flutter icon indicating copy to clipboard operation
flutter copied to clipboard

in_app_purchase plugin - detecting subscription lapse client-side

Open jamesncl opened this issue 6 years ago • 11 comments

I'm using the in_app_purchase plugin (v0.2.2) for Flutter to implement in-app auto-renewing subscription purchasing. I'm struggling to figure out how I check if a user's existing subscription has lapsed, which could be because of:

  • user has cancelled and the remaining time on the current billing period has elapsed
  • user has not auto-renewed and the remaining time on the current billing period has elapsed
  • payment error / in grace period

Is this supported by the plugin, and if not are there any plans to? I'm struggling to figure out which functions I could use to implement periodic checks on ios and android. Here's what I've figured out so far:

IOS:

Your app needs to determine which content the user has access to based on the period of time their auto-renewable subscription is active. To provide the customer access to the content to which they are entitled, keep a record of the date that each piece of content is published. Read the original_purchase_date, purchase_date, and expires_date field from each receipt entry to determine the start and end dates of each subscription period

How do you get the expires_date field from the ios receipt using in_app_purchase? The closest thing i could find is that PurchaseDetails has a PurchaseWrapper which contains a purchaseTime field - but the ios docs specifically say

Do not calculate the subscription period by adding a subscription duration to the purchase date. That approach fails to take into account the free trial period, the marketing opt-in period, and the content made available immediately after the user purchased the subscription.

Does in_app_purchase surface an expires_date or am I missing something?

ANDROID:

It looks like we need to use Google Play Developer API to query a particular subscription to determine if it's still valid. To do this you need:

app package name, purchase or subscription ID, and the purchase token

How do you get the purchaseToken for Android? It looks like PurchaseWrapper contains this field, but the docs say PurchaseWrapper is null on Android:

 /// Points back to the `BillingClient`'s [PurchaseWrapper] object that generated this [PurchaseDetails] object.
  ///
  /// This is null on Android.
  final PurchaseWrapper billingClientPurchase;

I'm totally stuck. I don't see how this plugin can be used for subscriptions if you can't detect lapsed subscriptions. Any advice highly appreciated :)

jamesncl avatar Oct 29 '19 13:10 jamesncl

@jamesncl Did you find a solution for this?

vladms avatar Nov 20 '19 09:11 vladms

@jamesncl or @vladms did either of you find a solution to this?

ramiechaarani avatar Dec 10 '19 17:12 ramiechaarani

I need this too. Anyone found a fix?

Toolenaar avatar Dec 29 '19 13:12 Toolenaar

@Toolenaar just throwing it out there - I worked on this for quite some time and was not feeling confident. I decided to go with RevenueCat as it is super reliable and their support team is very fast to respond with any queries you may have. Good luck to you! Fyi it took about a half day to implement it for me.

ramiechaarani avatar Dec 30 '19 17:12 ramiechaarani

I am facing the same problem, but i found one method i think can solve this, please correct me if i am wrong, look at the code when checking the past purchases i used (purchase.billingClientPurchase.isAutoRenewing) to see if is renewing or not, and in a test subscription is true when is active and false when i cancel it. So i guess it is enought to know if is charging user or not. What you think?

for (PurchaseDetails purchase in response.pastPurchases) { print(purchase.billingClientPurchase.isAutoRenewing); //_verifyPurchase(purchase); // Verify the purchase following the best practices for each storefront. //_deliverPurchase(purchase); // Deliver the purchase to the user in your app. if (Platform.isIOS) { // Mark that you've delivered the purchase. Only the App Store requires // this final confirmation. InAppPurchaseConnection.instance.completePurchase(purchase); } }

see my post on stack.

https://stackoverflow.com/questions/57474549/check-subscription-validity-using-flutters-in-app-purchase-plugin/59683165#59683165

jorgevvr avatar Jan 10 '20 14:01 jorgevvr

Similar #52522

rahulraj64 avatar Mar 13 '20 09:03 rahulraj64

Hello, how can i check the validity or say expiryInMillis of the non-consumable/subscription purchase a user made ?

Is not there any way to have a expiry validity property for the subscription expiry check?

JayM96 avatar May 25 '20 04:05 JayM96

Anyone found a way for this issue? It's been 2 years since the request was open.

adrianvintu avatar Sep 27 '21 15:09 adrianvintu

sad

xOldeVx avatar Dec 14 '21 17:12 xOldeVx

any way

awaitANTHONY avatar Jun 09 '22 05:06 awaitANTHONY

still stuck in this issue

fan123199 avatar Mar 01 '23 09:03 fan123199

Hi I need to get subscription's status either active or not from app store. Is there any way to get in this plugin

nikhil-guleria avatar Sep 06 '23 12:09 nikhil-guleria

In the end I got so frustrated with this plugin, and with iOS receipts and play billing library, that I switched to RevenueCat. Not free but it's so, so much easier, it's worth the small expense in exchange for weeks of my time back, and my sanity. Highly recommend. Leaving this issue open for others though.

jamesncl avatar Sep 22 '23 16:09 jamesncl

In the end I got so frustrated with this plugin, and with iOS receipts and play billing library, that I switched to RevenueCat. Not free but it's so, so much easier, it's worth the small expense in exchange for weeks of my time back, and my sanity. Highly recommend. Leaving this issue open for others though.

I am on the verge for the same. There is no way to either get the trial period, expiry date or duration of a user's purchase. Highly frustrating to find out other ways to get such basic information

PriyaSindkar avatar Jul 08 '24 08:07 PriyaSindkar