提交 8aa250af 编写于 作者: VK1688's avatar VK1688

优化uni-pay示例

上级 cbd859f7
......@@ -47,42 +47,48 @@
"description": "为DCloud提供的免费软件进行赞助",
"goods_price": 1, // 单价(元)
"buy_quantity": 1, // 数量(消耗性类型: 数量默认是1,最大值是10)
"product_id": this.isDebug() ? "uniappx.consumable.sponsor_1" : "uniappx.consumable.sponsor1",
"product_id": this.isDebug() ? "uniappx.consumable.sponsor_1" : "uniappx.consumable.sponsor1",
"product_type": "consumable", // 消耗性类型
"title": "消耗性产品:赞助"
},
{
"description": "为DCloud提供的免费软件进行赞助",
"goods_price": 5, // 单价(元)
"buy_quantity": 1, // 数量(消耗性类型: 数量默认是1,最大值是10)
"product_id": this.isDebug() ? "uniappx.consumable.sponsor_50" : "uniappx.consumable.sponsor50",
"product_id": this.isDebug() ? "uniappx.consumable.sponsor_50" : "uniappx.consumable.sponsor50",
"product_type": "consumable", // 消耗性类型
"title": "消耗性产品:赞助"
},
{
"description": "为DCloud提供的免费软件进行赞助",
"goods_price": 1, // 单价(元)
"buy_quantity": 1, // 数量(非消耗性: 数量只能是1,且一个该类型产品一个appleId只能购买一次)
"product_id": this.isDebug() ? "uniappx.nonconsumable.sponsorskin_1" : "uniappx.nonconsumable.sponsorskin1",
"product_id": this.isDebug() ? "uniappx.nonconsumable.sponsorskin_1" : "uniappx.nonconsumable.sponsorskin1",
"product_type": "nonconsumable", // 非消耗性类型
"title": "非消耗性产品: 赞助"
},
// {
// "description": "为DCloud提供的免费软件进行赞助",
// "goods_price": 1, // 单价(元)
// "buy_quantity": 1, // 数量(自动续期订阅产品: 数量只能是1)
// "product_id": this.isDebug() ? "uniappx.autorenewable.monthly_1" : "uniappx.autorenewable.monthly1",
// "product_id": this.isDebug() ? "uniappx.autorenewable.monthly_1" : "uniappx.autorenewable.monthly1",
// "product_type": "autorenewable", // 自动续期订阅产品
// "title": "自动续期订阅产品:每月定期赞助", // 注意自动续期订阅产品在沙盒模式下,实际周期会缩短到几分钟续期一次(即现实世界几分钟 = 沙盒世界1个月)
// },
{
"description": "为DCloud提供的免费软件进行赞助",
"goods_price": 1, // 单价(元)
"buy_quantity": 1, // 数量(非自动续期订阅产品: 数量只能是1)
"product_id": this.isDebug() ? "uniappx.nonrenewable.monthly_1" : "uniappx.nonrenewable.monthly1",
"product_id": this.isDebug() ? "uniappx.nonrenewable.monthly_1" : "uniappx.nonrenewable.monthly1",
"product_type": "nonrenewable", // 非自动续期订阅产品
"title": "非自动续期订阅产品:月赞助",
},
// {
// "description": "为DCloud提供的免费软件进行赞助",
// "goods_price": 1, // 单价(元)
// "buy_quantity": 1, // 数量
// "product_id": "uniappx.nonrenewable.none",
// "product_id": "uniappx.nonrenewable.none",
// "product_type": "consumable", // 消耗性类型
// "title": "测试不存在的产品"
// }
] as Array<UTSJSONObject>
......@@ -112,7 +118,8 @@
return item['product_id'] == this.product_id;
});
let buy_quantity = productInfo.getNumber('buy_quantity') || 1;
let goods_price = productInfo.getNumber('goods_price');
let goods_price = productInfo.getNumber('goods_price');
let product_type = productInfo['product_type'];
// 发起支付
this.$refs.payRef.createOrder({
provider: "appleiap", // 支付供应商(这里固定为appleiap,代表苹果虚拟支付)
......@@ -125,7 +132,8 @@
apple_virtual: {
product_id: this.product_id, // 产品id
goods_price: goods_price, // 单价
buy_quantity: buy_quantity, // 购买数量
buy_quantity: buy_quantity, // 购买数量
product_type: product_type // 产品类型
},
// 自定义数据
custom: {}
......
......@@ -585,6 +585,33 @@
// #endif
// #ifdef APP-IOS
const virtualPaymentManager = uni.getVirtualPaymentManager();
if (options.apple_virtual['product_type'] == 'nonconsumable') {
uni.showLoading({
title: "请求中...",
mask: true
})
let purchased = await new Promise((resolve, reject) => {
// 如果是非消耗性产品只能购买一次,需要先判断下
virtualPaymentManager.restoreTransactions({
success: (res) => {
let transactions = res.transactions;
let index = res.transactions.findIndex(transaction => {
return transaction.productId == options.apple_virtual['product_id']
})
resolve(index > -1 ? true : false);
}
});
});
uni.hideLoading()
if (purchased) {
uni.showModal({
title: "提示",
content: "您已购买过此商品,请勿重复购买",
showCancel: false
});
return;
}
}
let createOrderData = {
provider: options.provider,
total_fee: options.total_fee,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册