R
R
Roman Khegay2020-02-18 11:04:30
JavaScript
Roman Khegay, 2020-02-18 11:04:30

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

Documentation In App Purchase 2

Essence:
Application on Ionic 4 / Cordova / Angular 8
Installed In App Purchase 2 , Sandbox accounts are configured, and the Apple account itself.

Product registration goes well:

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


Tracking method:
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');
        });
    }


Purchase method:
buyMoneyCombo(form: NgForm) {
        this.registerHandlersForPurchase(MONEYCOMBO_KEY)
        this.date = form.value.date
        this.iap.order(MONEYCOMBO_KEY)
        this.iap.refresh()
    }


No matter how I try 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 is the problem? Why handlers can not work?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Khegay, 2020-02-22
@khegay

The problem was solved by deep analysis of the code.
It turned out that the message

"InAppPurchase[js]: product test has a transaction in progress: 1000000628239595"

appears after the completion of the transaction.
And all actions must be performed after the handler works:
this.iap.when(MONEYCOMBO_KEY).approved((product: IAPProduct) => {
            product.finish()
            this.getMoney()
        })

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question