feat: add cb url for payment

This commit is contained in:
imeepos
2025-09-28 12:32:45 +08:00
parent 3322bdda7f
commit 95f58aa70e
3 changed files with 14 additions and 6 deletions

View File

@@ -3,9 +3,16 @@ import { Payment } from "../types/payment";
export class H5Payment extends Payment {
async pay(templateCode: string, imageUrl: string) {
const sdk = useServerSdk()
const response = await sdk.payTemplateCode(templateCode, imageUrl)
const { hostname, protocol, port } = window.location;
let baseUrl = `${protocol}//${hostname}`
if (hostname === 'localhost') {
baseUrl = `${protocol}//${hostname}:${port}`
}
const cbUrl = `${baseUrl}`
const response = await sdk.payTemplateCode(templateCode, imageUrl, cbUrl)
if (response.url) {
window.location.href = response.url;
return;
}
throw new Error(`payment error: ${response}`)
}