fix: 微信 H5 支付未开通时 fallback 到 Native 扫码
移动端尝试 H5 下单失败时自动降级为 Native 二维码模式, 避免因 H5 权限未开通导致支付不可用。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -35,18 +35,19 @@ export class WxpayProvider implements PaymentProvider {
|
||||
throw new Error('WXPAY_NOTIFY_URL is required');
|
||||
}
|
||||
|
||||
if (request.isMobile) {
|
||||
if (!request.clientIp) {
|
||||
throw new Error('clientIp is required for H5 payment');
|
||||
if (request.isMobile && request.clientIp) {
|
||||
try {
|
||||
const h5Url = await createH5Order({
|
||||
out_trade_no: request.orderId,
|
||||
description: request.subject,
|
||||
notify_url: notifyUrl,
|
||||
amount: request.amount,
|
||||
payer_client_ip: request.clientIp,
|
||||
});
|
||||
return { tradeNo: request.orderId, payUrl: h5Url };
|
||||
} catch {
|
||||
// H5 未开通,fallback 到 Native 扫码
|
||||
}
|
||||
const h5Url = await createH5Order({
|
||||
out_trade_no: request.orderId,
|
||||
description: request.subject,
|
||||
notify_url: notifyUrl,
|
||||
amount: request.amount,
|
||||
payer_client_ip: request.clientIp,
|
||||
});
|
||||
return { tradeNo: request.orderId, payUrl: h5Url };
|
||||
}
|
||||
|
||||
const codeUrl = await createPcOrder({
|
||||
|
||||
Reference in New Issue
Block a user