2

I'm using the in_app_purchase (https://pub.dev/packages/in_app_purchase) Flutter plugin to implement subscription.

I fail to understand how to check if a certain user is still subscribed: The queryPastPurchases method returns a PurchaseDetails object per subscription but I can't find a "status" for the current subscription (active / non active etc.)...

I can check the transactionDate field but it isn't a good solution.

Appriciate any help with this issue

creativecreatorormaybenot
  • 114,516
  • 58
  • 291
  • 402
user6097845
  • 1,257
  • 1
  • 15
  • 33
  • You'll probably find this answer helpful: https://stackoverflow.com/questions/57474549/check-subscription-validity-using-flutters-in-app-purchase-plugin – Tomas Baran Jan 07 '22 at 11:34

1 Answers1

-2

Loop through each PurchaseDetails, and if a purchase.billingClientPurchase.sku == "your_subscriptionID" then an active subscription exists. If the user cancels the subscription and it has past the ending period(30 days), then response.pastPurchases list will not contain a subscription/purchase of "your_subscriptionID".

for (PurchaseDetails purchase in response.pastPurchases) {

    if(purchase.billingClientPurchase.sku == "your_subscriptionID"){
      hasSubscription = true;
    }

    if (Platform.isIOS) {
      InAppPurchaseConnection.instance.completePurchase(purchase);
    }
  }
Christer
  • 2,746
  • 3
  • 31
  • 50