Compare commits

..

No commits in common. "f02e8d949a404d879d46bd20c07ff92ca4ec67f4" and "8a1c5e982f1713dd47a39d86cbf63c0df52f5ec6" have entirely different histories.

5 changed files with 21 additions and 31 deletions

View File

@ -55,26 +55,15 @@ export default function FriendsPhoto() {
try { try {
// 将两个图片URL用逗号分隔 // 将两个图片URL用逗号分隔
const { hostname, protocol, port } = window.location; const combinedImageUrl = `${image1},${image2}`;
let baseUrl = `${protocol}//${hostname}`
if (hostname === 'localhost') { const taskId = await serverSdk.executeTemplate({
baseUrl = `${protocol}//${hostname}:${port}` imageUrl: combinedImageUrl,
}
const cbUrl = `${baseUrl}/result`
const checkout = await serverSdk.createCheckoutSession({
templateCode: templateCode, templateCode: templateCode,
metadata: {
cb_url: cbUrl,
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

@ -55,7 +55,7 @@ const ResultPage: React.FC = () => {
}; };
useEffect(() => { useEffect(() => {
const paymentId = searchParams.get('paymentId') || searchParams.get('taskId'); const paymentId = searchParams.get('payment_id') || searchParams.get('taskId');
if (paymentId) { if (paymentId) {
setTaskId(paymentId); setTaskId(paymentId);

View File

@ -1,7 +1,7 @@
import { useServerSdk } from "../../hooks"; import { useServerSdk } from "../../hooks";
import { Payment } from "../types/payment"; import { Payment } from "../types/payment";
export class H5Payment extends Payment { export class H5Payment extends Payment {
async pay(templateCode: string, imageUrls: string[]) { async pay(templateCode: string, imageUrl: string) {
const sdk = useServerSdk() const sdk = useServerSdk()
const { hostname, protocol, port } = window.location; const { hostname, protocol, port } = window.location;
let baseUrl = `${protocol}//${hostname}` let baseUrl = `${protocol}//${hostname}`
@ -9,7 +9,7 @@ export class H5Payment extends Payment {
baseUrl = `${protocol}//${hostname}:${port}` baseUrl = `${protocol}//${hostname}:${port}`
} }
const cbUrl = `${baseUrl}` const cbUrl = `${baseUrl}`
const response = await sdk.payTemplateCode(templateCode, imageUrls, cbUrl) const response = await sdk.payTemplateCode(templateCode, imageUrl, cbUrl)
if (response.url) { if (response.url) {
window.location.href = response.url; window.location.href = response.url;
return; return;

View File

@ -2,5 +2,5 @@
export abstract class Payment{ export abstract class Payment{
abstract pay(templateCode: string, imageUrls: string[]): Promise<any>; abstract pay(templateCode: string, imageUrl: string): Promise<any>;
} }

View File

@ -81,9 +81,9 @@ export interface TaskProgress {
*/ */
export interface CreateCheckoutParams { export interface CreateCheckoutParams {
templateCode: string; // 模板代码 templateCode: string; // 模板代码
userId: string; // 用户ID
metadata: { metadata: {
imageUrls: string[]; // 图片URL imageUrl: string; // 图片URL
cb_url: string;
[key: string]: any; // 其他元数据 [key: string]: any; // 其他元数据
}; };
} }
@ -129,8 +129,6 @@ export interface GoogleUserInfo {
email: string; // 邮箱 email: string; // 邮箱
name: string; // 姓名 name: string; // 姓名
picture?: string; // 头像URL picture?: string; // 头像URL
customerId?: string;
created?: boolean;
} }
/** /**
@ -372,10 +370,10 @@ export class SdkServer {
/** /**
* images.join(',') * images.join(',')
*/ */
async payTemplateCode(templateCode: string, imageUrls: string[], cbUrl: string) { async payTemplateCode(templateCode: string, imageUrl: string, cbUrl: string) {
try { try {
const response = await this.request(`/payment/checkout/${templateCode}`, 'POST', { const response = await this.request(`/payment/checkout/${templateCode}`, 'POST', {
imageUrls: imageUrls, // 图片URL imageUrl: imageUrl,
cb_url: cbUrl cb_url: cbUrl
}) })
return response.data as {url: string}; return response.data as {url: string};
@ -591,7 +589,7 @@ export class SdkServer {
*/ */
async profile(): Promise<GoogleUserInfo> { async profile(): Promise<GoogleUserInfo> {
try { try {
const response = await this.request<GoogleUserInfo>('/auth/google/customer'); const response = await this.request<GoogleUserInfo>('/auth/google/userinfo');
return response.data; return response.data;
} catch (error) { } catch (error) {
throw error; throw error;
@ -640,7 +638,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`); const response = await this.request<{ executions: UserExecution[]; total: number }>(`/templates/executions/user/${uid}`);
return response.data.executions || []; return response.data.executions || [];
} catch (error) { } catch (error) {
throw error; throw error;
@ -662,7 +660,10 @@ 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', params.metadata); const response = await this.request<CheckoutSessionResult>(`/payment/checkout/${params.templateCode}`, 'POST', {
userId: params.userId,
metadata: params.metadata
});
return response.data; return response.data;
} catch (error) { } catch (error) {
throw error; throw error;