feat: add cb url for payment
This commit is contained in:
@@ -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}`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user