更换苹果支付模式
This commit is contained in:
@@ -11,29 +11,37 @@ const ComplateRequestArr = []
|
||||
|
||||
|
||||
var iap = {
|
||||
getProvider() {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.getProvider({
|
||||
service: 'payment',
|
||||
success: (res) => {
|
||||
const iapChannel = res.providers.find((channel) => {
|
||||
return (channel.id === 'appleiap')
|
||||
})
|
||||
resolve(iapChannel);
|
||||
// 如果 iapChannel 为 null,说明当前包没有包含iap支付模块。注意:HBuilder基座不包含 iap 通道
|
||||
}
|
||||
});
|
||||
})
|
||||
},
|
||||
// 检测支付通道
|
||||
getChannels(){
|
||||
async getChannels(){
|
||||
const that = this;
|
||||
console.log('检测支付通道')
|
||||
plus.payment.getChannels(async (channels) => {
|
||||
for (var i in channels) {
|
||||
// 判断是否苹果支付1
|
||||
if (channels[i].id === "appleiap") {
|
||||
console.log("存在苹果内购channels",channels, );
|
||||
that.iapChannel = channels[i];
|
||||
// 先检测有没有未完成的订单
|
||||
that.restoreComplateRequest()
|
||||
}else{
|
||||
console.log('安卓客户端');
|
||||
}
|
||||
}
|
||||
});
|
||||
this.iapChannel = await this.getProvider()
|
||||
if(this.iapChannel){
|
||||
// this.requestOrder();
|
||||
this.restoreComplateRequest()
|
||||
}else{
|
||||
console.log("不支持iap支付");
|
||||
}
|
||||
},
|
||||
// 检测是否有未关闭订单
|
||||
restoreComplateRequest() {
|
||||
let that = this
|
||||
console.log('检测未完成订单')
|
||||
this.iapChannel.restoreComplateRequest({
|
||||
this.iapChannel.restoreCompletedTransactions({
|
||||
manualFinishTransaction: true
|
||||
}, function(results) {
|
||||
if (!that.checking) {
|
||||
@@ -50,7 +58,7 @@ var iap = {
|
||||
// return false
|
||||
// 已经支付,但是没有走逻辑的内购订单 就发给后台做验证
|
||||
that.iapCheck(item, index)
|
||||
// that.finishTransaction(item)
|
||||
// that.finishTransaction(item)
|
||||
} else {
|
||||
// 其他状态的内购订单
|
||||
that.finishTransaction(item)
|
||||
|
||||
Reference in New Issue
Block a user