PHPerSumer
PHPerSumer
  • 发布:2022-10-14 15:47
  • 更新:2024-05-10 18:51
  • 阅读:464

UniApp 检查是否存在未关闭的订单 不进入成功 也不进入失败?

分类:uni-app
              async init() {  
                uni.showLoading({  
                    title: '检测支付环境...',  
                    mask: true  
                });  
                try {  
                    await this.getAppleProductList()  
                    const transactions = await this.restoreCompletedTransactions('');  

                                        //从这里往下不执行  

                    if (transactions.length) {  
                        while (transactions.length) {  
                            const transaction = transactions[0];  
                            transactions.shift();  
                            switch (transaction.transactionState) {  
                                case "1":  
                                    try {  
                                        // 用户已付款,在此处请求开发者服务器,在服务器端请求苹果服务器验证票据  
                                        await this.finishTransaction(transactions);  
                                        // await this.paySuccess(transactions)  

                                    } catch (err) {  
                                        console.error('err:', err)  
                                    }  
                                    // // 验证通过,交易结束,关闭订单  
                                    break;  
                                case IapTransactionState.failed:  
                                    // 关闭未支付的订单  
                                    await this.finishTransaction(transaction);  
                                    break;  
                                default:  
                                    break;  
                            }  

                        }  

                    } else {  
                        console.log('没有未关闭的订单')  
                    }  
                    uni.hideLoading();  
                } catch (e) {  
                    console.log('e:', e)  
                    uni.hideLoading();  
                }  
            },  
                       getAppleProductList() {  
                return new Promise((resolve, reject) => {  
                    uni.getProvider({  
                        service: 'payment',  
                        success: res => {  
                            const appleiapChannel = res.providers.find(channel => {  
                                return channel.id === 'appleiap'  
                            })  
                            this.channel = appleiapChannel;  
                            appleiapChannel.requestProduct(this.productIds, productList => {  
                                this.productList = productList  
                                resolve(productList)  
                            }, err => {  
                                uni.showToast({  
                                    icon: "none",  
                                    title: '获取商品列表失败',  
                                    mask: true  
                                })  
                                console.error(err);  
                                reject(err)  
                            })  
                        }  
                    })  
                })  
            },  
            restoreCompletedTransactions(username = '') {  
                return new Promise((resolve, reject) => {  
                                        // console.log(xxx);  这句打印可以执行  
                    this.channel.restoreCompletedTransactions({  
                        username  
                    }, (res) => {  
                                                  // console.log('成功');  这句打印无法执行  
                        resolve(res);  
                    }, (err) => {  
                                                    // console.log('失败');  这句打印无法执行  
                        reject(err);  
                    })  
                                       // console.log(xxx);  这句打印可以执行  
                });  
            },

restoreCompletedTransactions 这个方法 执行没有完毕 检测支付环境... 的弹窗一直存在着

2022-10-14 15:47 负责人:DCloud_uni-ad_HDX 分享
已邀请:
wjb3435

wjb3435

你好 这个问题后面解决了吗

zhaoyu2020

zhaoyu2020 - 一只小小鸟

我也遇到这个问题了...

要回复问题请先登录注册