PeterStaev / nativescript-purchase

:moneybag: A NativeScript plugin for making in-app purchases!
Apache License 2.0
83 stars 28 forks source link

How to check if subscription has ended or has been cancelled? #103

Closed StefanNedelchev closed 3 years ago

StefanNedelchev commented 4 years ago

I've read a lot of closed issues here but yet I can't find a solid answer to what I'm looking for. I have the following issue - my app has only subscriptions (renewable subscriptions - one monthly and one 3-month subscription). I userestorePurchases() to restore currently purchased subscriptions. The thing is that restorePurchases() behaves differently on both platforms. On Android it returns only the currently active subscriptions - if I cancel a subscription and as soon as it's period ends it's no longer returned by restorePurchases(). As for iOS - it returns even subscriptions that should have been inactive. Keep in mind that I work with sandbox but the documentation says that all sandbox subscriptions (even renewables) expire after 6 renewals and therefore they are not active. The local storage method doesn't seem to make sense for subscriptions because I can't know when to remove them. The user should be able to cancel the subscription at any time and then it should be available to purchase once again. Another specific case for my app is that the user should have only one active subscription at a time. If there is an active subscription, the user shouldn't see it and therefore should have access to the content that the subscription unlocks. Also I'm not sure howgetStoreReceipt() could be helpful on iOS if it just returns the receipt of the last transaction

PeterStaev commented 4 years ago

@hardmaster92 , you send the store receipt to your backend, validate it against google/apple servers and check if the user subscription is active or not. You cannot do this on the device only, like for normal purchases.

StefanNedelchev commented 4 years ago

So you mean that if restorePurchases() returns 10 purchases, I have to check every one of them in the backend?

PeterStaev commented 4 years ago

No I mean you have to send the receipt, which when validated should return the info you need for all subscriptions.

StefanNedelchev commented 4 years ago

So let me check of I got it right - I get the receipt using getStoreReceipt() and then I can use it in my backend to validate and get info for all subscriptions?

PeterStaev commented 4 years ago

Yes, at least this is how I understand the Google/Apple store documentations. I haven't implemented neither subscriptions nor purchases in any production app, so can't be 100% sure.

StefanNedelchev commented 4 years ago

Yes, at least this is how I understand the Google/Apple store documentations. I haven't implemented neither subscriptions nor purchases in any production app, so can't be 100% sure.

Judging by the things that I see there it seems to be exactly the case for Apple. As for Android - this method returns always undefined (as mentioned in the docs). If I call restorePurchases() on Android it returns only the transaction for the currently active subscription (probably the transaction from the last renewal?) but when I call it on iOS it returns every single transaction, even old ones from my tests that I did yesterday.