fix: restore wechat payment oauth and jsapi flow

This commit is contained in:
IanShaw027
2026-04-20 23:34:57 +08:00
parent 6f00efa350
commit 7ef7fd19e7
16 changed files with 1563 additions and 87 deletions

View File

@@ -105,6 +105,50 @@ describe('decidePaymentLaunch', () => {
expect(decision.recovery.paymentMode).toBe('popup')
expect(decision.recovery.resumeToken).toBe('resume-2')
})
it('returns wechat oauth launch when backend requires in-app authorization', () => {
const decision = decidePaymentLaunch(createOrderResult({
result_type: 'oauth_required',
payment_type: 'wxpay',
oauth: {
authorize_url: '/api/v1/auth/oauth/wechat/payment/start?payment_type=wxpay',
appid: 'wx123',
scope: 'snsapi_base',
redirect_url: '/auth/wechat/payment/callback',
},
}), {
visibleMethod: 'wxpay',
orderType: 'balance',
isMobile: true,
})
expect(decision.kind).toBe('wechat_oauth')
expect(decision.oauth?.authorize_url).toContain('/api/v1/auth/oauth/wechat/payment/start')
expect(decision.paymentState.paymentType).toBe('wxpay')
})
it('returns wechat jsapi launch when backend has a jsapi payload ready', () => {
const decision = decidePaymentLaunch(createOrderResult({
result_type: 'jsapi_ready',
payment_type: 'wxpay',
jsapi: {
appId: 'wx123',
timeStamp: '1712345678',
nonceStr: 'nonce-123',
package: 'prepay_id=wx123',
signType: 'RSA',
paySign: 'signed-payload',
},
}), {
visibleMethod: 'wxpay',
orderType: 'subscription',
isMobile: true,
})
expect(decision.kind).toBe('wechat_jsapi')
expect(decision.jsapi?.appId).toBe('wx123')
expect(decision.paymentState.orderType).toBe('subscription')
})
})
describe('buildCreateOrderPayload', () => {