我正在使用 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"
交易无法完成。为什么?
最佳答案
因此,经过一周的研究,我找到了解决方案。
而且没有问题:
交易完成后显示来自 Apple 的消息:
"InAppPurchase[js]: product test has a transaction in progress: 1000000628239595"
并且必须在内部声明所有购买逻辑:
this.iap.when(MONEYCOMBO_KEY).approved((product: IAPProduct) => {
product.finish()
this.getMoney()
})
关于javascript - 无法在 ionic-native/in-app-purchase-2 中完成交易,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60276469/