How to complete the buying cycle in ionic-native/in-app-purchase-2?

Documentation In App Purchase 2

The bottom line:
App on 4 Ionic / Cordova / Angular 8
Installed In App Purchase 2, set up a Sandbox account, and the account Apple.

Product registration normally takes place:
registerProduct() {
 this.iap.verbosity = this.iap.DEBUG;

this.iap.register({
 id: MONEYCOMBO_KEY,
 type: this.iap.CONSUMABLE
})

this.registerHandlersForPurchase(MONEYCOMBO_KEY)

 this.product = this.iap.get(MONEYCOMBO_KEY)

this.iap.refresh()

 this.iap.when(MONEYCOMBO_KEY).updated((p) => {
 this.product = p
 this.title = p.title
 this.price = p.price
})
 }


Method for tracking:
registerHandlersForPurchase(productId) {
 let self = this.iap;

 this.iap.when(productId).updated(function (product) {
 if (product.loaded && product.valid && product.state === self.APPROVED && product.transaction != null) {
product.finish();
}
});

 this.iap.when(productId).registered((product: IAPProduct) => {
 // alert(` owned ${product.owned}`);
});

 this.iap.when(productId).owned((product: IAPProduct) => {
console.error('finished')
product.finish();
});

 this.iap.when(productId).approved((product: IAPProduct) => {
 // alert('approved');
product.finish();
});

 this.iap.when(productId).refunded((product: IAPProduct) => {
 // alert('refunded');
});

 this.iap.when(productId).expired((product: IAPProduct) => {
 // alert('expired');
});
 }


Method to buy:
buyMoneyCombo(form: NgForm) {
this.registerHandlersForPurchase(MONEYCOMBO_KEY)
 this.date = form.value.date
this.iap.order(MONEYCOMBO_KEY)
this.iap.refresh()
 }


As much as I tried to change the sequence of actions in the console, all actions stop at the message:
"InAppPurchase[js]: product test has a transaction in progress: 1000000628239595"


What's the problem? Why the handlers may not work?
April 7th 20 at 15:37
1 answer
April 7th 20 at 15:39
Solution
The problem was resolved a deep analysis of the code.

It turned out that the message
"InAppPurchase[js]: product test has a transaction in progress: 1000000628239595"

appears already after the transaction completed.

And all action must be done after work handler:
this.iap.when(MONEYCOMBO_KEY).approved((product: IAPProduct) => {
product.finish()
this.getMoney()
 })

Find more questions by tags AngularJavaScript