refactor: update payment flow to use checkout session with multiple image URLs

This commit is contained in:
imeepos 2025-09-28 17:33:46 +08:00
parent 8a1c5e982f
commit f80e1ce6a5
2 changed files with 16 additions and 11 deletions

View File

@ -55,15 +55,19 @@ export default function FriendsPhoto() {
try { try {
// 将两个图片URL用逗号分隔 // 将两个图片URL用逗号分隔
const combinedImageUrl = `${image1},${image2}`; const checkout = await serverSdk.createCheckoutSession({
const taskId = await serverSdk.executeTemplate({
imageUrl: combinedImageUrl,
templateCode: templateCode, 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) { } catch (error) {
console.error('提交失败:', error); console.error('提交失败:', error);
alert(t('friendsPhoto.waitForTaskCompletion')); alert(t('friendsPhoto.waitForTaskCompletion'));

View File

@ -81,9 +81,8 @@ export interface TaskProgress {
*/ */
export interface CreateCheckoutParams { export interface CreateCheckoutParams {
templateCode: string; // 模板代码 templateCode: string; // 模板代码
userId: string; // 用户ID
metadata: { metadata: {
imageUrl: string; // 图片URL imageUrls: string[]; // 图片URL
[key: string]: any; // 其他元数据 [key: string]: any; // 其他元数据
}; };
} }
@ -129,6 +128,8 @@ export interface GoogleUserInfo {
email: string; // 邮箱 email: string; // 邮箱
name: string; // 姓名 name: string; // 姓名
picture?: string; // 头像URL picture?: string; // 头像URL
customerId?: string;
created?: boolean;
} }
/** /**
@ -589,7 +590,7 @@ export class SdkServer {
*/ */
async profile(): Promise<GoogleUserInfo> { async profile(): Promise<GoogleUserInfo> {
try { try {
const response = await this.request<GoogleUserInfo>('/auth/google/userinfo'); const response = await this.request<GoogleUserInfo>('/auth/google/customer');
return response.data; return response.data;
} catch (error) { } catch (error) {
throw error; throw error;
@ -638,7 +639,7 @@ export class SdkServer {
if (!uid) { if (!uid) {
throw new Error('用户ID不存在'); 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 || []; return response.data.executions || [];
} catch (error) { } catch (error) {
throw error; throw error;
@ -661,7 +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', {
userId: params.userId, customer: params.customer,
metadata: params.metadata metadata: params.metadata
}); });
return response.data; return response.data;