Refine payment UX for wallet flows

This commit is contained in:
IanShaw027
2026-04-21 00:05:09 +08:00
parent 4ebdfcd13a
commit f83fd59dca
9 changed files with 373 additions and 18 deletions
@@ -155,4 +155,29 @@ describe('PaymentResultView', () => {
expect(wrapper.text()).toContain('payment.result.success')
expect(verifyOrderPublic).not.toHaveBeenCalled()
})
it('normalizes aliased payment methods before rendering the label', async () => {
routeState.query = {
resume_token: 'resume-88',
}
resolveOrderPublicByResumeToken.mockResolvedValueOnce({
data: {
...orderFactory('PAID'),
payment_type: 'alipay_direct',
},
})
const wrapper = mount(PaymentResultView, {
global: {
stubs: {
OrderStatusBadge: true,
},
},
})
await flushPromises()
expect(wrapper.text()).toContain('payment.methods.alipay')
expect(wrapper.text()).not.toContain('payment.methods.alipay_direct')
})
})
@@ -0,0 +1,49 @@
import { describe, expect, it } from 'vitest'
import {
describePaymentScenarioError,
normalizePaymentMethodForDisplay,
} from '../paymentUx'
describe('normalizePaymentMethodForDisplay', () => {
it('collapses visible payment aliases to canonical method ids', () => {
expect(normalizePaymentMethodForDisplay(' alipay_direct ')).toBe('alipay')
expect(normalizePaymentMethodForDisplay('wxpay_direct')).toBe('wxpay')
expect(normalizePaymentMethodForDisplay('wechat_pay')).toBe('wxpay')
})
it('leaves non-aliased methods untouched', () => {
expect(normalizePaymentMethodForDisplay('stripe')).toBe('stripe')
})
})
describe('describePaymentScenarioError', () => {
it('maps WeChat H5 authorization errors to explicit in-app guidance', () => {
expect(describePaymentScenarioError(
{ reason: 'WECHAT_H5_NOT_AUTHORIZED' },
{ paymentMethod: 'wxpay', isMobile: true, isWechatBrowser: false },
)).toEqual({
messageKey: 'payment.errors.wechatH5NotAuthorized',
hintKey: 'payment.errors.wechatOpenInWeChatHint',
})
})
it('maps missing WeixinJSBridge to a JSAPI-specific prompt', () => {
expect(describePaymentScenarioError(
new Error('WeixinJSBridge is unavailable'),
{ paymentMethod: 'wxpay', isMobile: true, isWechatBrowser: true },
)).toEqual({
messageKey: 'payment.errors.wechatJsapiUnavailable',
hintKey: 'payment.errors.wechatOpenInWeChatHint',
})
})
it('maps generic desktop Alipay failures to QR guidance', () => {
expect(describePaymentScenarioError(
{ reason: 'PAYMENT_GATEWAY_ERROR' },
{ paymentMethod: 'alipay', isMobile: false, isWechatBrowser: false },
)).toEqual({
messageKey: 'payment.errors.alipayDesktopUnavailable',
hintKey: 'payment.errors.alipayDesktopQrHint',
})
})
})