支付代码
requestPayment(orderInfo) {
return new Promise((resolve, reject) => {
plus.payment.request(this._channel, orderInfo, result => {
//console.log(result)
resolve(result)
}, (e) => {
console.log(e)
reject(e)
});
});
}
业务代码
const pay = await getOrder(data)
const order = pay.data
//支付参数
const payParam = {
productid: this.currentItem?.apple_id,
username: order.order_id //根据业务需求透传参数,关联用户和订单关系
}
uni.showLoading({
title: '支付中请勿退出',
mask: true
});
const res = await this.iap.requestPayment(payParam)
console.log(res)
uni.showLoading({
title: '处理中请勿退出',
mask: true
});
if(res.transactionState == 1) {
//在此处请求开发者服务器,在服务器端请求苹果服务器验证票据
await validateMemberServicePaymentResult({
order_id: order.order_id,
username: payParam.username,
transactionreceipt: res.transactionReceipt, // 不可作为订单唯一标识
transaction_id: res.transactionIdentifier
});
//关闭订单
this.iap.finishTransaction(res)
uni.hideToast()
uni.showModal({
content: "支付成功",
showCancel: false
})
}
还没支付就弹出支付成功了
a***@lvyac.com (作者)
上面代码完全可以看出,运行到 const res = await this.iap.requestPayment(payParam) 弹出支付框,我还没支付,代码就已经到了 uni.showModal({
content: "支付成功",
showCancel: false
})
就是说,还没支付 await this.iap.requestPayment(payParam) 就已经回调了
2022-11-10 08:11
x***@163.com
回复 a***@lvyac.com:同问,解决了吗
2023-10-09 20:52