From f80e1ce6a58ad6a36d5d0ec4e9123f36fd71cb62 Mon Sep 17 00:00:00 2001 From: imeepos Date: Sun, 28 Sep 2025 17:33:46 +0800 Subject: [PATCH] refactor: update payment flow to use checkout session with multiple image URLs --- src/pages/friends-photo/index.tsx | 16 ++++++++++------ src/sdk/sdk-server.ts | 11 ++++++----- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/pages/friends-photo/index.tsx b/src/pages/friends-photo/index.tsx index 2510eb3..3f03b8d 100644 --- a/src/pages/friends-photo/index.tsx +++ b/src/pages/friends-photo/index.tsx @@ -55,15 +55,19 @@ export default function FriendsPhoto() { try { // 将两个图片URL用逗号分隔 - const combinedImageUrl = `${image1},${image2}`; - - const taskId = await serverSdk.executeTemplate({ - imageUrl: combinedImageUrl, + const checkout = await serverSdk.createCheckoutSession({ templateCode: templateCode, + metadata: { + imageUrls: [ + image1, image2 + ] + } }); - + if (checkout && checkout.url) { + window.location.href = checkout.url; + } // 跳转到结果页面 - navigate(`/result?taskId=${taskId}&templateCode=${templateCode}`); + // navigate(`/result?taskId=${taskId}&templateCode=${templateCode}`); } catch (error) { console.error('提交失败:', error); alert(t('friendsPhoto.waitForTaskCompletion')); diff --git a/src/sdk/sdk-server.ts b/src/sdk/sdk-server.ts index 4d61a6c..f18b743 100644 --- a/src/sdk/sdk-server.ts +++ b/src/sdk/sdk-server.ts @@ -81,9 +81,8 @@ export interface TaskProgress { */ export interface CreateCheckoutParams { templateCode: string; // 模板代码 - userId: string; // 用户ID metadata: { - imageUrl: string; // 图片URL + imageUrls: string[]; // 图片URL [key: string]: any; // 其他元数据 }; } @@ -129,6 +128,8 @@ export interface GoogleUserInfo { email: string; // 邮箱 name: string; // 姓名 picture?: string; // 头像URL + customerId?: string; + created?: boolean; } /** @@ -589,7 +590,7 @@ export class SdkServer { */ async profile(): Promise { try { - const response = await this.request('/auth/google/userinfo'); + const response = await this.request('/auth/google/customer'); return response.data; } catch (error) { throw error; @@ -638,7 +639,7 @@ export class SdkServer { if (!uid) { throw new Error('用户ID不存在'); } - const response = await this.request<{ executions: UserExecution[]; total: number }>(`/templates/executions/user/${uid}`); + const response = await this.request<{ executions: UserExecution[]; total: number }>(`/templates/executions/user`); return response.data.executions || []; } catch (error) { throw error; @@ -661,7 +662,7 @@ export class SdkServer { async createCheckoutSession(params: CreateCheckoutParams): Promise { try { const response = await this.request(`/payment/checkout/${params.templateCode}`, 'POST', { - userId: params.userId, + customer: params.customer, metadata: params.metadata }); return response.data;