1***@qq.com
1***@qq.com
  • 发布:2023-10-23 14:19
  • 更新:2024-03-18 15:34
  • 阅读:511

苹果内购 报Payment_appleiap:Failed toreturn orderinformation testFilight上面测试支付是正常使用的

分类:uni-app

Payment_appleiap:Failed toreturn orderinformation,https://ask.dcloud.net.cn/article/282

问题描述 :本地测试了在iPhone上面与ipad上(testFlight上)没有出现这个问题,但是提交到苹果审核那里,苹果审核给出的截图,

弹窗说Payment_appleiap:Failed toreturn orderinformation,https://ask.dcloud.net.cn/article/282

2023-10-23 14:19 负责人:无 分享
已邀请:
1***@qq.com

1***@qq.com (作者)

代码
onLoad(data) {
this.productInfo = JSON.parse(data.buyInfo);
console.log("this.productInfo: " + JSON.stringify(this.productInfo));
this._iap = new Iap({
products: [this.productInfo.mealsId] // 苹果开发者中心创建
})
this.init();
},
onShow() {
if (this._iap.ready) {
this.restore();
}
},
async init() {
uni.showLoading({
title: '检测支付环境...'
});

            try {  
                // 初始化,获取iap支付通道  
                await this._iap.init();  
                // 从苹果服务器获取产品列表  
                this.productList = await this._iap.getProduct();  
                this.productList[0].checked = true;  
                this.productId = this.productList[0].productid;  

                // 填充产品列表,启用界面  
                this.disabled = false;  
            } catch (e) {  
                uni.showModal({  
                    title: "init",  
                    content: e.message,  
                    showCancel: false  
                });  
            } finally {  
                uni.hideLoading();  
            }  

            if (this._iap.ready) {  
                this.restore();  
            }  
        },  
        async restore() {  
            // 检查上次用户已支付且未关闭的订单,可能出现原因:首次绑卡,网络中断等异常  

            // 在此处检查用户是否登陆  

            uni.showLoading({  
                title: '正在检测已支付且未关闭的订单...'  
            });  

            try {  
                // 从苹果服务器检查未关闭的订单,可选根据 username 过滤,和调用支付时透传的值一致  
                const transactions = await this._iap.restoreCompletedTransactions({  
                    username: ""  
                });  

                if (!transactions.length) {  
                    return;  
                }  

                // 开发者业务逻辑,从服务器获取当前用户未完成的订单列表,和本地的比较  
                // 此处省略  

                switch (transaction.transactionState) {  
                    case IapTransactionState.purchased:  
                        // 用户已付款,在此处请求开发者服务器,在服务器端请求苹果服务器验证票据  
                        // let result = await this.validatePaymentResult();  

                        // 验证通过,交易结束,关闭订单  
                        // if (result) {  
                        //   await this._iap.finishTransaction(transaction);  
                        // }  
                        break;  
                    case IapTransactionState.failed:  
                        // 关闭未支付的订单  
                        await this._iap.finishTransaction(transaction);  
                        break;  
                    default:  
                        break;  
                }  
            } catch (e) {  
                uni.showModal({  
                    content: e.message,  
                    showCancel: false  
                });  
            } finally {  
                uni.hideLoading();  
            }  
        },  
        async payment() {  
            if (this.loading == true) {  
                return;  
            }  
            this.loading = true;  

            uni.showLoading({  
                title: '支付处理中...'  
            });  

            try {  
                //从开发者服务器创建订单  
                const order = await this.createOrder();  
                // 请求苹果支付  
                const transaction = await this._iap.requestPayment({  
                    productid: this.productId,  
                    manualFinishTransaction: true,  
                    // username: username + orderId //根据业务需求透传参数,关联用户和订单关系  
                    username:order.data.orderId  
                });  

                // 在此处请求开发者服务器,在服务器端请求苹果服务器验证票据  
                await this.validatePaymentResult({  
                  orderId: order.data.orderId,  
                  transactionReceipt: transaction.transactionReceipt, // 不可作为订单唯一标识  
                  transactionIdentifier: transaction.transactionIdentifier,  
                  type:1  
                });  

                // 验证成功后关闭订单  
                await this._iap.finishTransaction(transaction);  
                uni.navigateTo({  
                    url:'/pages/pee/goods/buyDetails/buyDetails?state=2'  
                })  
                // 支付成功  
            } catch (e) {  
                uni.showModal({  
                    content: e.message||'支付失败或取消支付',  
                    showCancel: false  
                });  
            } finally {  
                this.loading = false;  
                uni.hideLoading();  
            }  
        },  
        //创建订单  
    async createOrder() {  
              try {  
                const res = await this.$api.order.createOrder({  
                  goodsId: this.productInfo.shopId,  
                  mealId: this.productInfo.mealsId,  
                  payPlatform: 'APPLE_PAY',  
                  quantity: this.productInfo.buyNum,  
                  remark: this.userInfo.remarks  
                });  
                console.log("res: " + JSON.stringify(res));  
                return res; // 返回API响应  
              } catch (err) {  
                // 处理任何错误  
                console.error(err);  
                throw err; // 重新抛出错误以供调用者捕获  
              }  

        },  
    async validatePaymentResult(data) {  
            try {  
              const res = await this.$api.order.verify(data);  
              console.log("res: " + JSON.stringify(res));  
              return res; // 返回API响应  
            } catch (err) {  
              // 处理任何错误  
              console.error(err);  
              throw err; // 重新抛出错误以供调用者捕获  
            }  
        },  

}

  • zhaoyu2020

    楼主 能请教下 Apple pay 能用基座在本地测试吗?我的报"code":-100,"message":"Payment_appleiap:返回訂單信息失敗,https://ask.dcloud.net.cn/article/282"

    2024-03-18 14:30

  • 1***@qq.com (作者)

    回复 zhaoyu2020: 看后端是否支持沙盒环境校验

    2024-04-25 18:02

DCloud_iOS_XHY

DCloud_iOS_XHY

获取订单信息失败,后台看一下商品审核通过了吗?

  • 1***@qq.com (作者)

    商品审核通过了,苹果审核给的原因是验证凭证的问题,提供了沙盒测试账号,现在已经上线了

    2023-11-01 16:24

  • zhaoyu2020

    回复 1***@qq.com: 楼主的沙盒测试账号 是通过什么获取的 ?邮箱?

    2024-03-18 15:35

  • zhaoyu2020

    请问大佬,商品审核是否是要和app 一起送审的?

    2024-03-18 15:36

  • 1***@qq.com (作者)

    回复 zhaoyu2020: 在appstore connect中的用户创建沙盒测试账号,商品审核是和app一起送审的

    2024-04-25 18:03

  • zhaoyu2020

    回复 1***@qq.com: 大佬 我现在能获取商品信息了,但是拉起支付的时候提示我 账户不支援此商店 你的账户无法在香港商店使用 你必须转到中国大陆商店才能购物 .我被整懵圈了...

    2024-05-02 12:08

H***@beone1.cn

H***@beone1.cn

在uniapp中使用微信原生代码

zhaoyu2020

zhaoyu2020 - 一只小小鸟

楼主, 我的app内置项目 显示的是 草稿 (3) 这种状态可否在本地用基座进行测试了?

要回复问题请先登录注册