23 lines
875 B
JavaScript
23 lines
875 B
JavaScript
function parseOrderInfo(payment) {
|
|
if (payment.paymentParams && typeof payment.paymentParams === 'object') return payment.paymentParams
|
|
if (typeof payment.payMessage !== 'string') return payment.payMessage
|
|
try { return JSON.parse(payment.payMessage) } catch { return payment.payMessage }
|
|
}
|
|
|
|
export function requestAppPayment(payment) {
|
|
if (!payment || payment.payWay !== 'APP') {
|
|
return Promise.reject(new Error('当前订单不是 App 支付订单'))
|
|
}
|
|
const provider = payment.paymentMethod === 'alipay' ? 'alipay' : 'wxpay'
|
|
const orderInfo = parseOrderInfo(payment)
|
|
if (!orderInfo) return Promise.reject(new Error('支付参数为空'))
|
|
return new Promise((resolve, reject) => {
|
|
uni.requestPayment({
|
|
provider,
|
|
orderInfo,
|
|
success: resolve,
|
|
fail: error => reject(new Error(error?.errMsg || '支付未完成'))
|
|
})
|
|
})
|
|
}
|