PeterStaev / nativescript-purchase

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

Multiple purchase events when app comes out of sleep mode #114

Open mreall opened 3 years ago

mreall commented 3 years ago

In development, I'm testing the purchase of an auto-renew subscription. The purchase goes through the App Store, gets verified on the server, and enables the subscription in the app, all as expected. However, if the phone goes to sleep and starts up again, the transactionUpdateEvent gets called several times with old transactions. The more I test new subscription purchases, the more the transactionUpdateEvent gets called when the phone wakes up. I'm now up to over 150 transactions posting to my server.

Does anyone know what's going on? It's almost like the finishTransaction call isn't working in the plugin.

PeterStaev commented 3 years ago

@mreall , this might be because in sandbox subscriptions renew in an accellarted schedule: https://help.apple.com/app-store-connect/#/dev7e89e149d That might explain why you see so much events. If the transactions are different, then it should be fine.

mreall commented 3 years ago

@PeterStaev, thanks for the quick response. I'm seeing the server-to-server notifications on the accelerated schedule as described in the App Store docs. But it seems strange that the transactionUpdatedEvent in the app itself would be called so many times. I'll keep digging to see if I can provide any more details.

PeterStaev commented 3 years ago

I dont think it is strange. For every renew I think StoreKit will call your app's transaction event in addition to the server to server notifications.

mreall commented 3 years ago

But it looks like the app's transaction event is getting called with transactions that have already been processed. I'm seeing transactions with a transactionDate from several days ago when I started testing. It's like every transaction is being reprocessed. When I verify the receipts server-side, all but the latest have a status of 21006, indicating the subscriptions have expired.

Do you know why the App Store would continue sending these transactions in SKPaymentQueue and if there's a way identify valid (i.e. non-expired) transactions?

PeterStaev commented 3 years ago

Sadly I don't 😞 Don't have a production app that uses app purchases or subscriptions so don't have any past experience.

mreall commented 3 years ago

The more I look online it appears that others have had the same issue and can't really explain it. The number of repeat transactions is amplified in the Sandbox because I'm doing so much testing. But I'll have to wait until I'm in production to see if I experience the same issues.

jgmedialtd commented 2 years ago

@mreall - realise this was a while ago - but did you ever manage to solve this? I'm encountering the same issue now and wondering if it will happen in production?

mreall commented 2 years ago

@jgmediadesign I'm not getting orders on iOS in production yet, so I can't verify.