fix: 微信 H5 支付未开通时 fallback 到 Native 扫码

移动端尝试 H5 下单失败时自动降级为 Native 二维码模式,
避免因 H5 权限未开通导致支付不可用。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
erio
2026-03-06 22:34:57 +08:00
parent 918750047a
commit 0c6c6e0ea6

View File

@@ -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({