【问题标题】:Can't finish transaction in ionic-native/in-app-purchase-2无法在 ionic-native/in-app-purchase-2 中完成交易
【发布时间】:2020-06-02 05:06:40
【问题描述】:

我正在使用 Ionic 4 / Angular 8 / Cordova 开发应用程序

我已经安装了In App Purchase 2 并进行了设置。 Apple Developer 和 Sandbox 帐户都可以。

产品注册成功:

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

事件处理程序:

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

购买方式:

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

问题:

控制台说:

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

交易无法完成。为什么?

【问题讨论】:

    标签: javascript angular cordova ionic-framework


    【解决方案1】:

    所以,经过一周的研究,我找到了解决方案。

    而且没有问题: 交易完成后显示来自 Apple 的消息:

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

    并且所有的购买逻辑都必须在里面声明:

    this.iap.when(MONEYCOMBO_KEY).approved((product: IAPProduct) => {
            product.finish()
            this.getMoney()
        })
    

    【讨论】:

    • 你的回答救了我的命!非常感谢
    猜你喜欢
    • 2019-07-22
    • 2017-05-29
    • 2015-01-08
    • 2020-10-01
    • 2022-12-27
    • 1970-01-01
    • 2016-03-12
    • 2012-10-16
    • 1970-01-01
    相关资源
    最近更新 更多