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

Detecting failed purchases does not work in v13 #1496

Open alexp25 opened 6 months ago

alexp25 commented 6 months ago

Current behavior:

The new version of this plugin does not detect failed purchases (e.g., cancelled purchase, declined, etc.)

The documentation states that the .error event was removed and can be detected by using the following code instead:

"To check for failed purchases, store.when("product").error() does not have a replacement in v13: you should now check for an error returned by the store.order()"

store.order(...)
.then(error => {
  if (error) {
    if (error.code === CdvPurchase.ErrorCode.PAYMENT_CANCELLED) {
      // Purchase flow has been cancelled by user
    }
    else {
      // Other type of error, check error.code and error.message
    }
  }
});

However, the error is never triggered and the purchase flow is left hanging.

Expected behavior:

Detecting failed purchases To check for failed purchases, store.when("product").error() does not have a replacement in v13: you should now check for an error returned by the store.order() promise (API Doc).

The purchase error should be detected.

undergroundcreative commented 6 months ago

It works for me if I use the numeric error code:

store.order(...).then(error => { if (error) { console.log("Store error " + error.code + ": " + error.message); if (error.code === 6777006) { // Purchase flow has been cancelled by user console.log("User cancelled"); } else { // Other type of error, check error.code and error.message } } });

alexp25 commented 6 months ago

Tried this but it doesn't resolve the promise at all - there is no output when a purchase is cancelled. Is there some other way to detect product-related errors? The store.when(product).error method is no longer available..

undergroundcreative commented 6 months ago

That's the only way it gives in the migration guide: https://github.com/j3k0/cordova-plugin-purchase/wiki/HOWTO:-Migrate-to-v13#detecting-failed-purchases

Maybe try setting the debug level to verbose and see if that gives any more clues:

store.verbosity = store.DEBUG;