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

store.initilize and store.update does not update if product is owned #1470

Closed maxfloden closed 6 months ago

maxfloden commented 8 months ago

This is just a minor thing but it is a little confusing and took me a while to figure out, not sure if it is working as expected or not?

Observed behavior

I just upgraded from v11 to 13.8.0 and noticed this:

Expected behavior

From migration guide:

store.refresh() is now store.initialize()

The store.refresh() method had 3 different purposes:
initialize the plugin
refresh product prices and status of purchases
restore purchases (on iOS)

The plugin now has one method for each of those purposes:
use store.initialize() at initialization
use store.update() to refresh product prices and status of purchases
use store.restorePurchases() to restore purchases

System Info

lincolnthree commented 7 months ago

I am also seeing this issue. However according to Apple we are apparently not supposed to call "store.restorePurchases()" automatically because it will prompt the user for their App Store / iCloud credentials.

What is the correct sequence of calls to get updated receipt info on App Startup?

j3k0 commented 7 months ago

Yes, store.restorePurchases() should only be called in response to the user clicking a "Restore Purchases" button in your app. In general, it will ask the user for their AppStore password, then replay the entire history in transactions. It's only meant to recover from certain situation, not meant for normal use.

The owned status of your products should be correct, it's been well tested on non-consumables. Can you share logs and source code? Is the issue resolved?

lincolnthree commented 7 months ago

It turns out that situation for us involved the user attempting to make a purchase, but the bank declining the purchase via the Apple App Store. Apparently once the user called their bank, they were able to complete the purchase (and we received the populated in_app: [ ... ] array as expected.

I'm not 100% sure how we're supposed to know how to handle that scenario.

lincolnthree commented 6 months ago

Actually not sure this is exactly what's happening. It seems the value of in_app:[] is being omitted somewhat randomly. I can't pin it down.

j3k0 commented 6 months ago

Just use the content of "latest_receipt" (in_app might be outdated). I will close as the issue description now looks misleading, open a more specific issue if you learn more about it.