提交 f385e359 编写于 作者: zhaofengliang920817's avatar zhaofengliang920817

更新 virtualPayment 页面示例,支持通过virtualPaymentContext对象调用api。

上级 15742c6c
......@@ -7,7 +7,8 @@
<text>
requestVirtualPayment api 适用于消耗性类型、非消耗性类型、自动续期订阅类型、非自动续期订阅类型产品的购买。\n\n
1. 消耗性类型:该类型的产品可以设置购买数量,默认是1,最大值是10; \n
2. 非消耗性类型、自动续期订阅类型、非自动续期订阅类型: 这些类型的产品购买数量设置无效,数量只能是1。
2. 非消耗性类型、自动续期订阅类型、非自动续期订阅类型: 这些类型的产品购买数量设置无效,数量只能是1; \n
3. 非消耗性类型:该类型产品一个appleId只能购买一次,可以在任何登陆该appleId账号的设备上restore获取。
</text>
<button style="margin-top: 20px;" type="primary" v-for="(item,index) in productList" :key="index"
@click="requestVirtualPayment(item)">{{item.name}}</button>
......@@ -42,12 +43,18 @@
export default {
data() {
return {
productList: [] as PayItem[]
productList: [] as PayItem[],
virtualPaymentContext: Object
}
},
onLoad: function () {
this.virtualPaymentContext = uni.createVirtualPaymentContext()
this.initProductList()
},
methods: {
initProductList() {
this.productList.push({
name: '消耗性产品:个人赞助1元,购买数量=5',
name: '消耗性产品:个人赞助1元, 数量=5',
id: this.isDebug() ? "uniappx.consumable.sponsor_1" : "uniappx.consumable.sponsor1",
quantity: 5
} as PayItem);
......@@ -78,7 +85,6 @@
id: "uniappx.nonrenewable.none"
} as PayItem);
},
methods: {
getPackageName() : string {
const res = uni.getAppBaseInfo();
let packageName : string = ""
......@@ -116,11 +122,12 @@
title: "",
mask: true
});
uni.requestVirtualPayment({
apple: {
productId: e.id,
appAccountToken: "orderId+accountId",
quantity: e.quantity ?? 1
quantity: e.quantity ?? 1,
},
success: (res) => {
uni.hideLoading()
......@@ -128,7 +135,7 @@
//TODO: 开发者server验证逻辑
//经过开发者server验证成功后请结束该交易
uni.finishedTransaction({
this.virtualPaymentContext.finishTransaction({
transaction: res.apple,
success: (r) => {
console.log("关单成功, 该productId= " + res.apple?.payment.productId)
......@@ -157,7 +164,8 @@
title: "",
mask: true
});
uni.restoreCompletedTransactions({
this.virtualPaymentContext.restoreCompletedTransactions({
success: (res) => {
uni.hideLoading()
console.log("restore成功的交易个数:" + res.transactions.length)
......@@ -187,16 +195,18 @@
title: "",
mask: true
});
uni.getUnfinishedTransactions({
this.virtualPaymentContext.getUnfinishedTransactions({
success: (res) => {
uni.hideLoading()
console.log("获取未结束的订单列表个数:" + res.transactions.length)
res.transactions.forEach(transaction => {
console.log("getUnfinishedTransactions成功的交易productId= " + transaction.payment.productId)
//TODO: 开发者server验证逻辑
//经过开发者server验证成功后请结束该交易
uni.finishedTransaction({
this.virtualPaymentContext.finishTransaction({
transaction: transaction,
success: (r) => {
console.log("关单成功, 该productId= " + transaction.payment.productId)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册