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:
purchaseStreamis triggered when user buy non-consumable productpurchaseStreamis not triggered after app restartpurchaseStreamis not triggered when user pause or cancel subscriptionpurchaseStreamis not triggered when subscription expire
this is the default behavior, but there is also restorePurchases() method, when I call it then:
purchaseStreamis triggered ONLY when the subscription is validpurchaseStreamis 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
purchaseStreamI guess that the subscription is invalid - if there is value, just compare ID and hash against the database
2) + server side (probably preferable)
- the
purchaseStreamis used just for the current purchase, not for the future updates recoverPurchasesis 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 ;)