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

Products owned status changes on IOS Ionic Capacitor Live reload #1562

Open studentrk opened 1 week ago

studentrk commented 1 week ago

Observed behavior

Using live reload:

  1. app starts
  2. buy a non-consumable product
  3. the owned status of non-consumable product changes to true
  4. make code changes, save them and the app gets reloaded
  5. all products from CdvPurchase.store.products have the owned status as false

When employing live reload with Ionic on iOS, purchasing a non-consumable product, making code changes, and triggering app restart, the CdvPurchase.store.products function returns all products as not owned. However, upon calling restorePurchases, the purchases are accurately restored. It appears that not all plugin code is reloaded during live reload, and the paymentQueue function is not executed again after the reload.

This issue doesn't require immediate fixing but might be beneficial to document.

Expected behavior

During live reload, purchasing a non-consumable product should retain its owned status even after recompilation.

Simple workaround

  1. app starts
  2. buy a non-consumable product
  3. the owned status of non-consumable product changes to true
  4. make code changes, save them and the app gets reloaded
  5. all products from CdvPurchase.store.products have the owned status as false
  6. close app and restart app --> this does set the correct status again
j3k0 commented 5 days ago

I believe thought that this would work if receipt validation is setup (is it your case?). Calling "initialize" should trigger a receipt validation call that'll make the plugin aware of non-consumable purchases (and subscriptions). Without receipt validation, on iOS, purchases won't be reported again.

That could potentially be fixed by keeping a cache of transactions on the native side, but could create other issues (like a reload after switching AppStore account would report incorrect transactions, other side effects maybe?).

Not sure how important that is, notice that in debug you could probably work with "TEST" products, that will work across reloads (because they're pure JS) -- cf https://github.com/j3k0/cordova-plugin-purchase/wiki/v13-reference:-Test-Adapter