jamesmontemagno / InAppBillingPlugin

Cross-platform In App Billing Plugin for .NET
MIT License
651 stars 152 forks source link

Proper way to check for active/valid subscription (Android and iOS)? #200

Closed cncb-gh closed 5 years ago

cncb-gh commented 5 years ago

My app has an annual subscription with a 7-day free trial. It is not clear to me that I am properly checking for an active/valid subscription. I would appreciate any help.

Android: With test purchases it seems GetPurchasesAsync() does not return any purchases for the given id if the subscription/trial has expired and was cancelled/not renewed. So, all that seems necessary is to check for the existence of a purchase. Has anyone been able to verify that this is the same in production? Will it also not return any purchases if the payment failed?

iOS: With sandbox purchases it seems GetPurchasesAsync() returns all renewals each with the state of Purchased. So, is seems necessary to check the latest purchase and manually check the purchase date to see if it has expired (if only one, it is the trial period).

Is my understanding correct? Thanks.

jamesmontemagno commented 5 years ago

That is correct from my undestanding. ON android there is a "PurchaseState" and if you ask for subscriptions it will tell you the correct state. https://github.com/jamesmontemagno/InAppBillingPlugin/blob/master/src/Plugin.InAppBilling.Android/InAppBillingImplementation.cs#L828 However you still need to calculate things correctly.