Skip to content

in_app_purchase plugin - detecting subscription lapse client-side #43720

Open

Description

@jamesncl

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 :)

Activity

  1. vladms commented on Nov 20, 2019

    @vladms

    @jamesncl Did you find a solution for this?

  2. ramiechaarani commented on Dec 10, 2019

    @ramiechaarani

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

  3. Toolenaar commented on Dec 29, 2019

    @Toolenaar

    I need this too. Anyone found a fix?

  4. ramiechaarani commented on Dec 30, 2019

    @ramiechaarani

    @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.

  5. jorgevvr commented on Jan 10, 2020

    @jorgevvr

    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

  6. rahulraj64 commented on Mar 13, 2020

    @rahulraj64

    Similar #52522

  7. JayM96 commented on May 25, 2020

    @JayM96

    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?

  8. added
    P3Issues that are less important to the Flutter project
    on Apr 29, 2021
  9. 3 remaining items

  10. fan123199 commented on Mar 1, 2023

    @fan123199

    still stuck in this issue

  11. added
    d: api docsIssues with https://api.flutter.dev/
    on Jul 5, 2023
  12. nikhil-guleria commented on Sep 6, 2023

    @nikhil-guleria

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

  13. jamesncl commented on Sep 22, 2023

    @jamesncl
    Author

    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.

  14. PriyaSindkar commented on Jul 8, 2024

    @PriyaSindkar

    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

  15. moved this from To triage to Moderate, High Priority in Storekit 2 Tracker/[in_app_purchase_storekit] trackeron Dec 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectd: api docsIssues with https://api.flutter.dev/p: in_app_purchasePlugin for in-app purchasepackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions