fix wechat mini program virtual payment flow
This commit is contained in:
@@ -329,6 +329,7 @@ type WechatPayResult = {
|
||||
requestId: string;
|
||||
orderId: string | null;
|
||||
status: WechatMiniProgramPaymentStatus;
|
||||
errorMessage: string | null;
|
||||
};
|
||||
type RechargePaymentResultKind = 'success' | 'pending' | 'cancel' | 'failed';
|
||||
type RechargePaymentResult = {
|
||||
@@ -2681,22 +2682,34 @@ function readWechatPayResultFromHash(): WechatPayResult | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
const [requestId = '', rawStatus = ''] = result.split(':');
|
||||
const orderId = requestId
|
||||
const [requestId = '', rawStatus = '', explicitOrderId = '', ...rawErrors] =
|
||||
result.split(':');
|
||||
const inferredOrderId = requestId
|
||||
.replace(/^wechat_pay_/, '')
|
||||
.replace(/_\d+$/, '')
|
||||
.trim();
|
||||
const orderId = explicitOrderId.trim() || inferredOrderId;
|
||||
const status =
|
||||
rawStatus === 'success'
|
||||
? 'success'
|
||||
: rawStatus === 'cancel'
|
||||
? 'cancel'
|
||||
: 'fail';
|
||||
let errorMessage: string | null = null;
|
||||
const rawError = rawErrors.join(':');
|
||||
if (rawError) {
|
||||
try {
|
||||
errorMessage = decodeURIComponent(rawError);
|
||||
} catch (_error) {
|
||||
errorMessage = rawError;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
requestId,
|
||||
orderId: orderId || null,
|
||||
status,
|
||||
errorMessage,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4586,6 +4599,7 @@ export function RpgEntryHomeView({
|
||||
return;
|
||||
}
|
||||
|
||||
setSubmittingRechargeProductId(null);
|
||||
if (payResult.status === 'success') {
|
||||
setRechargePaymentResult({
|
||||
kind: 'pending',
|
||||
@@ -4635,10 +4649,13 @@ export function RpgEntryHomeView({
|
||||
});
|
||||
refreshRechargeState();
|
||||
} else {
|
||||
const detail = payResult.errorMessage
|
||||
? `微信返回:${payResult.errorMessage}`
|
||||
: '微信支付没有完成,本次不会入账。';
|
||||
setRechargePaymentResult({
|
||||
kind: 'failed',
|
||||
title: '支付未完成',
|
||||
message: '微信支付没有完成,本次不会入账。',
|
||||
message: detail,
|
||||
});
|
||||
refreshRechargeState();
|
||||
}
|
||||
@@ -4679,11 +4696,16 @@ export function RpgEntryHomeView({
|
||||
.then(async (response) => {
|
||||
if (paymentChannel === WECHAT_MINI_PROGRAM_VIRTUAL_PAYMENT_CHANNEL) {
|
||||
pendingWechatRechargeOrderIdRef.current = response.order.orderId;
|
||||
setRechargeCenter(response.center);
|
||||
setRechargePaymentResult({
|
||||
kind: 'pending',
|
||||
title: '正在支付',
|
||||
message: '请在微信小程序支付页完成支付,返回后会自动刷新状态。',
|
||||
});
|
||||
await requestWechatMiniProgramPayment(
|
||||
response.wechatMiniProgramPayParams,
|
||||
response.order.orderId,
|
||||
);
|
||||
setRechargeCenter(response.center);
|
||||
return;
|
||||
}
|
||||
if (paymentChannel === WECHAT_H5_PAYMENT_CHANNEL) {
|
||||
|
||||
Reference in New Issue
Block a user