fix(payment): trim callback base URL trailing slashes

This commit is contained in:
chihao.ou
2026-09-20 18:05:09 +08:00
parent d2e319b2a1
commit 1582347204
2 changed files with 28 additions and 2 deletions
@@ -705,8 +705,8 @@ function handleSave() {
// If base URL is empty, auto-fill with current domain
const paths = PROVIDER_CALLBACK_PATHS[form.provider_key]
if (paths) {
const notifyBase = notifyBaseUrl.value.trim() || defaultBaseUrl
const returnBase = returnBaseUrl.value.trim() || defaultBaseUrl
const notifyBase = (notifyBaseUrl.value.trim() || defaultBaseUrl).replace(/\/+$/, '')
const returnBase = (returnBaseUrl.value.trim() || defaultBaseUrl).replace(/\/+$/, '')
notifyBaseUrl.value = notifyBase
returnBaseUrl.value = returnBase
if (paths.notifyUrl) filteredConfig['notifyUrl'] = notifyBase + paths.notifyUrl
@@ -95,6 +95,32 @@ function mountDialog(options: { editing?: ProviderInstance | null } = {}) {
})
}
describe('PaymentProviderDialog callback URLs', () => {
it.each([
['https://notify.example.com/', 'https://return.example.com///', 'https://notify.example.com', 'https://return.example.com'],
[' https://notify.example.com/sub/ ', ' https://return.example.com/site/ ', 'https://notify.example.com/sub', 'https://return.example.com/site'],
['https://notify.example.com', 'https://return.example.com', 'https://notify.example.com', 'https://return.example.com'],
['', '', window.location.origin, window.location.origin],
])('joins callback paths to %s and %s', async (notify, returnUrl, expectedNotify, expectedReturn) => {
const provider = providerFactory({
provider_key: 'easypay', name: 'EasyPay',
config: { pid: 'pid-1', apiBase: 'https://pay.example.com' },
supported_types: ['alipay'], payment_mode: 'qrcode',
})
const wrapper = mountDialog({ editing: provider })
;(wrapper.vm as unknown as { loadProvider: (provider: ProviderInstance) => void }).loadProvider(provider)
await nextTick()
const bases = wrapper.findAll('input').filter(input => input.classes().includes('!rounded-r-none'))
await bases[0].setValue(notify)
await bases[1].setValue(returnUrl)
await wrapper.find('form').trigger('submit')
const payload = wrapper.emitted('save')?.[0]?.[0] as { config: Record<string, string> }
expect(payload.config.notifyUrl).toBe(expectedNotify + '/api/v1/payment/webhook/easypay')
expect(payload.config.returnUrl).toBe(expectedReturn + '/payment/result')
wrapper.unmount()
})
})
describe('PaymentProviderDialog payment guide', () => {
it('shows no payment guide for providers without a flow guide', () => {
const wrapper = mountDialog()