Files
bw-mini-app/src/platforms/h5/payment.ts
2025-09-28 12:32:45 +08:00

19 lines
723 B
TypeScript

import { useServerSdk } from "../../hooks";
import { Payment } from "../types/payment";
export class H5Payment extends Payment {
async pay(templateCode: string, imageUrl: string) {
const sdk = useServerSdk()
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}`)
}
}