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

Cancel purchase process trigger #1523

Open sergip76 opened 2 months ago

sergip76 commented 2 months ago

Is it possible to know when a purchase has been cancelled? I mean that the user clicks on buy and once the purchase screen appears go back to cancel the process before making the purchase.

It would be something like this:

CdvPurchase.store.when().cancelled(() => { });

reinos commented 2 months ago

Its not really in the documentation but your could use this

https://github.com/j3k0/cordova-plugin-purchase/wiki/HOWTO:-Migrate-to-v13#detecting-failed-purchases

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
    }
  }
});
sergip76 commented 2 months ago

Its not really in the documentation but your could use this

https://github.com/j3k0/cordova-plugin-purchase/wiki/HOWTO:-Migrate-to-v13#detecting-failed-purchases

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
    }
  }
});

I was referring to the moment when the user simply closes the payment window, not when the payment is cancelled. If the user closes the payment window no error is thrown.