feat: add callback URL handling and payTemplateCode method for payment flow

This commit is contained in:
imeepos 2025-09-28 17:50:06 +08:00
parent f80e1ce6a5
commit 399935d2ef
2 changed files with 12 additions and 7 deletions

View File

@ -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
] ]

View File

@ -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;