j3k0 / cordova-plugin-purchase

In-App Purchase for Cordova on iOS, Android and Windows
https://purchase.cordova.fovea.cc
1.29k stars 529 forks source link

Autorenewing subscriptions - no event triggered when subscription ends to check if it is renewed #1468

Closed oduverne closed 7 months ago

oduverne commented 8 months ago

Hello, I'm using 13.8.0 version of the plugin. My issue is on iOS and Android. I'm using autorenewing subscriptions (auto renew every month if user has not canceled it). At the end of the monthly subscription we need to check if the user has canceled the renewal of the subscription. The plugin doesn't trigger an event when the subscription renewaldate is reached. I tried to run CdvPurchase.store.update() but the receipt is not updated. If I restart my app the new receipt is correctly fetched and validated. What should I do to get the new receipt and validate it? Thank you

mebeingken commented 8 months ago

Personally, I don't rely on the plugin to do this, but rather the receipt validation service (either your own or iaptic).

With iaptic it is pretty easy, setup webhooks so the service will ping your backend on subscription changes/renewals/lapses, etc.

https://www.iaptic.com/documentation/webhook

And use the app stores to notify iaptic:

iOS (status url): https://www.iaptic.com/documentation/setup/ios-subscription-status-url

Android (realtime notifications): https://www.iaptic.com/documentation/setup/connect-with-google-publisher-api

With that in place, you can rely on a subscription status within your app to control access.

oduverne commented 8 months ago

@mebeingken thank you for your suggestion. As I didn't want to do too much modifications of my code, I decided to call the validator using this: CdvPurchase.store.findInLocalReceipts(CdvPurchase.store.get(productId)).verify(); With this I get the expected behavior on Android (not yet tested on iOS). I don't know if it is the best way to do it.

oduverne commented 7 months ago

@j3k0 Thank you for adding the validator call when subscriptions end in v13.8.4. It works great! I think you should extend a little more the grace period on Android. Sometimes I don't get the correct expiration date when validating the receipt. When I test a 1 month subscriptions (5 minutes for testers), sometimes the expiration date is only extended for 2 minutes when I call Google API. May be we do it to early.

j3k0 commented 7 months ago

When the expiration date is only extended by 2 minutes, it probably means Google Play simulates their actual grace period (billing retry, or something), when a payment method fails.

Too bad we have to figure out the correct grace period with trial and error. I'll add another 20 seconds to the plugin's internal grace period for Google.