feat: add cb url for payment
This commit is contained in:
parent
3322bdda7f
commit
95f58aa70e
|
|
@ -56,10 +56,10 @@ const ResultPage: React.FC = () => {
|
||||||
const instance = getCurrentInstance();
|
const instance = getCurrentInstance();
|
||||||
const params = instance?.router?.params;
|
const params = instance?.router?.params;
|
||||||
|
|
||||||
if (params?.taskId) {
|
if (params?.payment_id) {
|
||||||
setTaskId(params.taskId);
|
setTaskId(params.payment_id);
|
||||||
// 开始轮询
|
// 开始轮询
|
||||||
pollTaskResult(params.taskId);
|
pollTaskResult(params.payment_id);
|
||||||
} else {
|
} else {
|
||||||
showToast({
|
showToast({
|
||||||
title: '缺少taskId参数',
|
title: '缺少taskId参数',
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,16 @@ import { Payment } from "../types/payment";
|
||||||
export class H5Payment extends Payment {
|
export class H5Payment extends Payment {
|
||||||
async pay(templateCode: string, imageUrl: string) {
|
async pay(templateCode: string, imageUrl: string) {
|
||||||
const sdk = useServerSdk()
|
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) {
|
if (response.url) {
|
||||||
window.location.href = response.url;
|
window.location.href = response.url;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
throw new Error(`payment error: ${response}`)
|
throw new Error(`payment error: ${response}`)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -368,10 +368,11 @@ export class SdkServer {
|
||||||
/**
|
/**
|
||||||
* 如果多图的话 images.join(',')
|
* 如果多图的话 images.join(',')
|
||||||
*/
|
*/
|
||||||
async payTemplateCode(templateCode: string, imageUrl: string) {
|
async payTemplateCode(templateCode: string, imageUrl: string, cbUrl: string) {
|
||||||
try {
|
try {
|
||||||
const response = await this.request(`/payment/checkout/${templateCode}`, 'POST', {
|
const response = await this.request(`/payment/checkout/${templateCode}`, 'POST', {
|
||||||
imageUrl: imageUrl
|
imageUrl: imageUrl,
|
||||||
|
cb_url: cbUrl
|
||||||
})
|
})
|
||||||
return response.data as {url: string};
|
return response.data as {url: string};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue