feat(trade): connect WeChat refund API and callback flow
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -72,4 +72,40 @@ export class PayWechatProvider implements IPayProvider {
|
||||
});
|
||||
return { mode: 'jsapi', prepay };
|
||||
}
|
||||
|
||||
async refundOrder(
|
||||
orderId: bigint,
|
||||
outRefundNo: string,
|
||||
reason?: string,
|
||||
) {
|
||||
if (loadAppConfig().mockPay) {
|
||||
return { mode: 'mock' as const, outRefundNo };
|
||||
}
|
||||
if (!this.wechat.isPayEnabled()) {
|
||||
throw new Error('微信支付未配置:请关闭 MOCK_PAY 并配置 WX_MCH_ID 等商户参数');
|
||||
}
|
||||
|
||||
const order = await this.prisma.order.findUnique({ where: { id: orderId } });
|
||||
if (!order) throw new Error('订单不存在');
|
||||
|
||||
const amountFen = Math.round(Number(order.payAmount) * 100);
|
||||
const notifyUrl = process.env.WX_REFUND_NOTIFY_URL ?? '';
|
||||
|
||||
this.logger.log(`create refund order=${order.orderNo} outRefundNo=${outRefundNo}`);
|
||||
const result = await this.wechat.createDomesticRefund({
|
||||
orderNo: order.orderNo,
|
||||
transactionId: order.payExternalNo ?? undefined,
|
||||
outRefundNo,
|
||||
amountFen,
|
||||
totalFen: amountFen,
|
||||
reason,
|
||||
notifyUrl,
|
||||
});
|
||||
return {
|
||||
mode: 'wechat' as const,
|
||||
outRefundNo: result.outRefundNo,
|
||||
refundId: result.refundId,
|
||||
status: result.status === 'SUCCESS' ? 'SUCCESS' as const : 'PROCESSING' as const,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user