cordova-plugin-purchase icon indicating copy to clipboard operation
cordova-plugin-purchase copied to clipboard

Recommended way to check expired status of auto-renewable subscription?

Open vanessag opened this issue 3 years ago • 6 comments

Hi,

I've been using this plugin in conjunction with the Fovea receipt validator to implement auto-renewable subscriptions in my app and so far it's been great. One thing I'm trying to understand is how do I determine whether the subscription is still active or expired? I would like to display a message in app when the user subscription expires and then remove the benefits.

I see that there is a .expired event but it's not clear and seems inconsistent when this event fires. It seems that if the Fovea validator returns a purchase expired code this event will be appropriately triggered. However, I've noticed that the Fovea validator only returns this code once some time after it expires and then returns a response with the receipt information with the cancelation information.

My question is how to I appropriately determine the status of the subscription? i.e. how do I know all the receipt validation is finished and I have no owned subscriptions?

Any help would be appreciated!

vanessag avatar Aug 18 '21 19:08 vanessag

@j3k0 @Dexus Would either of you be able to shed some light on this question?

vanessag avatar Aug 30 '21 23:08 vanessag

@vanessag Did you find a solution for this? I have a user who has an expired subscription and I don't seem to see the expired event being triggered when I initialize the plugin's information. The expire date was 10.3, I have logs before that date where I get the owned event but after the expiration date I do not see it (the user used the app at 10.5 - i.e two days after expiration but not expired event is there). My code can be seen here: https://github.com/IsraelHikingMap/Site/blob/d8c32a5c2ee41a41b6f34df700768abcf4f30d5b/IsraelHiking.Web/src/application/services/purchase.service.ts#L55 It uses the ionic wrapper. Let me know if I'm doing something wrong. The following is the log after expiration:

2021-10-05 07:35:08 | DEBUG | [Store] store.trigger -> triggering action refresh-finished
2021-10-05 07:35:08 | DEBUG | [Store] store.trigger -> triggering action refresh-completed
2021-10-05 07:35:08 | DEBUG | [Store] iabUpdatePurchases: []
2021-10-05 07:35:08 | DEBUG | [Store]                             -> []
2021-10-05 07:35:08 | DEBUG | [Store]                             -> object
2021-10-05 07:35:08 | DEBUG | [Store] inappbilling.getPurchases() -> Success
2021-10-05 07:35:08 | DEBUG | [Store] iabSetPurchases: []
2021-10-05 07:35:08 | DEBUG | [Store] iabGetPurchases()
2021-10-05 07:35:08 | DEBUG | [Store] state: offline_map -> valid
2021-10-05 07:35:08 | DEBUG | [Store] plugin -> loaded - [{"productId":"offline_map","type":"subs","title":"צפיה במפות ללא רשת - מנוי לשנה (מפת הטיולים הפתוחה)","name":"צפיה במפות ללא רשת - מנוי לשנה","price":"‏99.00 ₪","price_amount_micros":99000000,"price_currency_code":"ILS","description":"מנוי שנתי לעדכוני מפות הטיולים והאופניים לצפיה ללא רשת.\nאין שינוי ביכולות אחרות.","subscriptionPeriod":"P1Y","skuDetailsToken":"AEuhp4L0K6rie3pozXzP1ksaq5uy6B2S9gZVKXdojAJMTW3V8I6OXb4df8afzujlVV_6"}]
2021-10-05 07:35:07 | DEBUG | [Store] plugin -> ready
2021-10-05 07:35:05 | DEBUG | [Store] store.trigger -> triggering action refreshed
2021-10-05 07:35:05 |  INFO | [Store] logged in: 5236471
2021-10-05 07:35:05 | DEBUG | [Store] state: offline_map -> registered

These are the logs before expiration which are valid, there's no problem in the logs below, just adding them for comparison...

2021-10-01 07:50:28 | DEBUG | [Store] store.trigger -> triggering action refresh-finished
2021-10-01 07:50:28 | DEBUG | [Store] Product owned! Last modified: Thu Sep 30 2021 05:46:15 GMT+0300 (שעון ישראל (קיץ))
2021-10-01 07:50:28 | DEBUG | [Store] state: offline_map -> owned
2021-10-01 07:50:28 | DEBUG | [Store] plugin -> consumable finished
2021-10-01 07:50:28 | DEBUG | [Store] state: offline_map -> finished
2021-10-01 07:50:28 | DEBUG | [Store] product -> finishing offline_map
2021-10-01 07:50:28 | DEBUG | [Store] product -> defer finishing offline_map
2021-10-01 07:50:28 | DEBUG | [Store] Verified, Finishing: offline_map
2021-10-01 07:50:28 | DEBUG | [Store] verify -> success: {"id":"offline_map","transaction":{"orderId":"GPA.3336-1001-8871-10569","packageName":"il.org.osm.israelhiking","productId":"offline_map","purchaseTime":1601716313398,... reducted...
2021-10-01 07:50:28 | DEBUG | [Store] expiryDate: 2021-10-03T11:09:08.001Z
2021-10-01 07:50:28 | DEBUG | [Store] transaction fields for offline_map
2021-10-01 07:50:28 | DEBUG | [Store] verify -> {"success":true,"data":{"id":"offline_map","transaction":{"orderId":"GPA.3336-1001-8871-10569","packageName":"il.org.osm.israelhiking","productId":"offline_map","purchaseTime":1601716313398, ... reducted...
2021-10-01 07:50:28 | DEBUG | [Store] validator success, response: {"ok":true,"data":{"id":"offline_map","transaction":{"orderId":"GPA.3336-1001-8871-10569","packageName":"il.org.osm.israelhiking","productId":"offline_map","purchaseTime":1601716313398, ... reducted...
2021-10-01 07:50:26 | DEBUG | [Store] ajax -> send request to https://validator.fovea.cc/v1/validate?appName=il.org.osm.israelhiking&apiKey=1245b587-4bbc-4fbd-a3f1-d51169a53063
2021-10-01 07:50:26 | DEBUG | [Store] runValidation()
2021-10-01 07:50:23 | DEBUG | [Store] scheduleValidation()
2021-10-01 07:50:22 | DEBUG | [Store] store.trigger -> triggering action refresh-completed
2021-10-01 07:50:22 | DEBUG | [Store] Approved, verifing: offline_map
2021-10-01 07:50:22 | DEBUG | [Store] state: offline_map -> approved
2021-10-01 07:50:22 | DEBUG | [Store]              -> {"orderId":"GPA.3336-1001-8871-10569","packageName":"il.org.osm.israelhiking","productId":"offline_map","purchaseTime":1601716313398 ... reducted...
2021-10-01 07:50:22 | DEBUG | [Store] product data -> for offline_map
2021-10-01 07:50:22 | DEBUG | [Store] iabUpdatePurchases: [{"orderId":"GPA.3336-1001-8871-10569","packageName":"il.org.osm.israelhiking","productId":"offline_map","purchaseTime":1601716313398,... reducted...
2021-10-01 07:50:22 | DEBUG | [Store]                             -> [{"orderId":"GPA.3336-1001-8871-10569","packageName":"il.org.osm.israelhiking","productId":"offline_map","purchaseTime":1601716313398,... reducted...
2021-10-01 07:50:22 | DEBUG | [Store]                             -> object
2021-10-01 07:50:22 | DEBUG | [Store] inappbilling.getPurchases() -> Success
2021-10-01 07:50:22 | DEBUG | [Store] iabSetPurchases: [{"orderId":"GPA.3336-1001-8871-10569","packageName":"il.org.osm.israelhiking","productId":"offline_map","purchaseTime":1601716313398,... reducted...
2021-10-01 07:50:22 | DEBUG | [Store] iabGetPurchases()
2021-10-01 07:50:22 | DEBUG | [Store] state: offline_map -> valid
2021-10-01 07:50:22 | DEBUG | [Store] plugin -> loaded - [{"productId":"offline_map","type":"subs","title":"צפיה במפות ללא רשת - מנוי לשנה (מפת הטיולים הפתוחה)","name":"צפיה במפות ללא רשת - מנוי לשנה","price":"‏99.00 ₪","price_amount_micros":99000000,"price_currency_code":"ILS","description":"מנוי שנתי לעדכוני מפות הטיולים והאופניים לצפיה ללא רשת.\nאין שינוי ביכולות אחרות.","subscriptionPeriod":"P1Y","skuDetailsToken": ... reducted...}]
2021-10-01 07:50:18 | DEBUG | [Store] store.trigger -> triggering action refreshed
2021-10-01 07:50:18 |  INFO | [Store] logged in: 5236471
2021-10-01 07:50:18 | DEBUG | [Store] state: offline_map -> registered

HarelM avatar Oct 28 '21 09:10 HarelM

@HarelM No, sorry. I never did find a good solution to this. The expired event is not very reliable in my experience.

It seems someone else has opened a similar issue and I have commented there

vanessag avatar Dec 15 '21 19:12 vanessag

@vanessag thanks for the info! @j3k0 any updates on this?

HarelM avatar Dec 15 '21 20:12 HarelM

Any update on this!

ahmad-alk avatar Feb 15 '22 17:02 ahmad-alk

I’m having a similar problem I think. Currently developing locally and while using the sandbox I can subscribe but after expiring or even removing the subscription fully from the App Store manage section the user is still having the subscription. The expired event is not triggered as well and strange enough it is sticking on “owned” as well while the purchase should not be valid anymore

Should the refresh/update be run more often perhaps or?

jaimyborgman avatar Sep 23 '22 16:09 jaimyborgman