in_app_purchase plugin - detecting subscription lapse client-side
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:
- documentation is on https://developer.apple.com/documentation/storekit/in-app_purchase/handling_subscriptions_billing
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:
- documentation https://developer.android.com/google/play/developer-api.html#subscriptions_api_overview
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 Did you find a solution for this?
@jamesncl or @vladms did either of you find a solution to this?
I need this too. Anyone found a fix?
@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.
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.
Similar #52522
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?
Anyone found a way for this issue? It's been 2 years since the request was open.
sad
any way
still stuck in this issue
Hi I need to get subscription's status either active or not from app store. Is there any way to get in this plugin
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.
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