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 {
// 将两个图片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'));

View File

@ -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<GoogleUserInfo> {
try {
const response = await this.request<GoogleUserInfo>('/auth/google/userinfo');
const response = await this.request<GoogleUserInfo>('/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<CheckoutSessionResult> {
try {
const response = await this.request<CheckoutSessionResult>(`/payment/checkout/${params.templateCode}`, 'POST', {
userId: params.userId,
customer: params.customer,
metadata: params.metadata
});
return response.data;