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 {
// 将两个图片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({
templateCode: templateCode,
metadata: {
cb_url: cbUrl,
imageUrls: [
image1, image2
]

View File

@ -83,6 +83,7 @@ export interface CreateCheckoutParams {
templateCode: string; // 模板代码
metadata: {
imageUrls: string[]; // 图片URL
cb_url: string;
[key: string]: any; // 其他元数据
};
}
@ -371,13 +372,13 @@ export class SdkServer {
/**
* images.join(',')
*/
async payTemplateCode(templateCode: string, imageUrl: string, cbUrl: string) {
async payTemplateCode(templateCode: string, imageUrls: string[], cbUrl: string) {
try {
const response = await this.request(`/payment/checkout/${templateCode}`, 'POST', {
imageUrl: imageUrl,
imageUrls: imageUrls, // 图片URL
cb_url: cbUrl
})
return response.data as {url: string};
return response.data as { url: string };
} catch (error) {
throw error;
}
@ -661,10 +662,7 @@ export class SdkServer {
*/
async createCheckoutSession(params: CreateCheckoutParams): Promise<CheckoutSessionResult> {
try {
const response = await this.request<CheckoutSessionResult>(`/payment/checkout/${params.templateCode}`, 'POST', {
customer: params.customer,
metadata: params.metadata
});
const response = await this.request<CheckoutSessionResult>(`/payment/checkout/${params.templateCode}`, 'POST', params.metadata);
return response.data;
} catch (error) {
throw error;