Flutter in_app_purchase handle subscription lifecycle

Viewed 532

I am using in_app_purchase: ^2.0.1 and thinking how to handle the whole lifecycle of subscription product. This is what I've found out:

  • purchaseStream is triggered when user buy non-consumable product
  • purchaseStream is not triggered after app restart
  • purchaseStream is not triggered when user pause or cancel subscription
  • purchaseStream is not triggered when subscription expire

this is the default behavior, but there is also restorePurchases() method, when I call it then:

  • purchaseStream is triggered ONLY when the subscription is valid
  • purchaseStream is not triggered when the subscription is canceled, expired, or paused

I am thinking about these approaches

1) client app only

  • when user buy -> store somewhere the purchaseID, hash, whatever.
  • when user opens the app again, call restorePurchases() and wait for let's say 5 seconds
  • if there is no value in the purchaseStream I guess that the subscription is invalid
  • if there is value, just compare ID and hash against the database

2) + server side (probably preferable)

  • the purchaseStream is used just for the current purchase, not for the future updates
  • recoverPurchases is not called
  • when user buy -> store somewhere the purchaseID + calculate and store date until
  • create some kind of cron job which checks users who have older date until
  • this job should get the details based on purchaseID but where/how*?
  • when the purchase is still valid, skip, when not, remove the subscription from the db

3) some kind of combination of these above

Thanks for your ideas ;)

0 Answers
Related