109 lines
2.6 KiB
JavaScript
109 lines
2.6 KiB
JavaScript
import {
|
|
defineStore
|
|
} from 'pinia';
|
|
|
|
import {
|
|
ref
|
|
} from 'vue';
|
|
|
|
import {
|
|
APIpayltPayOrder,
|
|
APIpayltPayVip
|
|
} from '@/common/api/pay.js'
|
|
|
|
export const Memberpay = defineStore('memberpay', {
|
|
actions: {
|
|
actionspayltPayVip(data) {
|
|
return new Promise(async (resolve, reject) => {
|
|
try {
|
|
let res = await APIpayltPayVip({
|
|
shopId: data.shopId,
|
|
shopUserId: data.shopUserId,
|
|
amount: data.amount,
|
|
// #ifdef MP-WEIXIN
|
|
payType: 'wechatPay',
|
|
openId: uni.cache.get('userInfo').wechatOpenId,
|
|
// #endif
|
|
// #ifdef MP-ALIPAY
|
|
payType: 'aliPay',
|
|
openId: uni.cache.get('userInfo').wechatOpenId,
|
|
// #endif
|
|
returnUrl: data.returnUrl ? data.returnUrl : '',
|
|
buyerRemark: data.buyerRemark ? data.buyerRemark : ''
|
|
})
|
|
if (res) {
|
|
uni.showLoading({
|
|
title: '加载中',
|
|
mask: true
|
|
})
|
|
uni.requestPayment({
|
|
// #ifdef MP-WEIXIN
|
|
provider: 'wxpay', //支付类型-固定值
|
|
partnerid: res.appId, // 微信支付商户号
|
|
timeStamp: res.timeStamp, // 时间戳(单位:秒)
|
|
nonceStr: res.nonceStr, // 随机字符串
|
|
package: res.package, // 固定值
|
|
signType: res.signType, //固定值
|
|
paySign: res.paySign, //签名
|
|
// #endif
|
|
// #ifdef MP-ALIPAY
|
|
provider: 'alipay', //支付类型-固定值
|
|
orderInfo: res.tradeNo, // 微信支付商户号
|
|
// #endif
|
|
success: (res) => {
|
|
console.log(res)
|
|
uni.hideLoading()
|
|
let pages = getCurrentPages()
|
|
// #ifdef MP-WEIXIN
|
|
uni.showToast({
|
|
title: "支付成功"
|
|
})
|
|
resolve(res)
|
|
// #endif
|
|
|
|
// #ifdef MP-ALIPAY
|
|
if (res.resultCode == '9000') {
|
|
uni.showToast({
|
|
title: "支付成功"
|
|
})
|
|
resolve(res)
|
|
} else {
|
|
uni.showToast({
|
|
title: "支付失败"
|
|
})
|
|
}
|
|
// #endif
|
|
},
|
|
fail: (res) => {
|
|
uni.hideLoading()
|
|
reject(false)
|
|
}
|
|
});
|
|
}
|
|
} catch (e) {
|
|
uni.hideLoading()
|
|
reject(false)
|
|
}
|
|
})
|
|
},
|
|
|
|
actionsltPayOrder() {
|
|
return new Promise(async (resolve, reject) => {
|
|
let res = await APIpayltPayOrder({
|
|
shopId: uni.cache.get('shopId'),
|
|
checkOrderPay: {},
|
|
// #ifdef MP-WEIXIN
|
|
payType: 'wechatPay',
|
|
openId: uni.cache.get('userInfo').wechatOpenId,
|
|
// #endif
|
|
// #ifdef MP-ALIPAY
|
|
payType: 'aliPay',
|
|
openId: uni.cache.get('alipayOpenId').wechatOpenId,
|
|
// #endif
|
|
returnUrl: '',
|
|
buyerRemark: '',
|
|
})
|
|
})
|
|
}
|
|
}
|
|
}); |