feat: add callback URL handling and payTemplateCode method for payment flow
This commit is contained in:
parent
f80e1ce6a5
commit
399935d2ef
|
|
@ -55,9 +55,16 @@ export default function FriendsPhoto() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 将两个图片URL用逗号分隔
|
// 将两个图片URL用逗号分隔
|
||||||
|
const { hostname, protocol, port } = window.location;
|
||||||
|
let baseUrl = `${protocol}//${hostname}`
|
||||||
|
if (hostname === 'localhost') {
|
||||||
|
baseUrl = `${protocol}//${hostname}:${port}`
|
||||||
|
}
|
||||||
|
const cbUrl = `${baseUrl}/result`
|
||||||
const checkout = await serverSdk.createCheckoutSession({
|
const checkout = await serverSdk.createCheckoutSession({
|
||||||
templateCode: templateCode,
|
templateCode: templateCode,
|
||||||
metadata: {
|
metadata: {
|
||||||
|
cb_url: cbUrl,
|
||||||
imageUrls: [
|
imageUrls: [
|
||||||
image1, image2
|
image1, image2
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,7 @@ export interface CreateCheckoutParams {
|
||||||
templateCode: string; // 模板代码
|
templateCode: string; // 模板代码
|
||||||
metadata: {
|
metadata: {
|
||||||
imageUrls: string[]; // 图片URL
|
imageUrls: string[]; // 图片URL
|
||||||
|
cb_url: string;
|
||||||
[key: string]: any; // 其他元数据
|
[key: string]: any; // 其他元数据
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -371,13 +372,13 @@ export class SdkServer {
|
||||||
/**
|
/**
|
||||||
* 如果多图的话 images.join(',')
|
* 如果多图的话 images.join(',')
|
||||||
*/
|
*/
|
||||||
async payTemplateCode(templateCode: string, imageUrl: string, cbUrl: string) {
|
async payTemplateCode(templateCode: string, imageUrls: 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,
|
imageUrls: imageUrls, // 图片URL
|
||||||
cb_url: cbUrl
|
cb_url: cbUrl
|
||||||
})
|
})
|
||||||
return response.data as {url: string};
|
return response.data as { url: string };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
@ -661,10 +662,7 @@ export class SdkServer {
|
||||||
*/
|
*/
|
||||||
async createCheckoutSession(params: CreateCheckoutParams): Promise<CheckoutSessionResult> {
|
async createCheckoutSession(params: CreateCheckoutParams): Promise<CheckoutSessionResult> {
|
||||||
try {
|
try {
|
||||||
const response = await this.request<CheckoutSessionResult>(`/payment/checkout/${params.templateCode}`, 'POST', {
|
const response = await this.request<CheckoutSessionResult>(`/payment/checkout/${params.templateCode}`, 'POST', params.metadata);
|
||||||
customer: params.customer,
|
|
||||||
metadata: params.metadata
|
|
||||||
});
|
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue