Compare commits
4 Commits
8a1c5e982f
...
f02e8d949a
| Author | SHA1 | Date |
|---|---|---|
|
|
f02e8d949a | |
|
|
5453c79197 | |
|
|
399935d2ef | |
|
|
f80e1ce6a5 |
|
|
@ -55,15 +55,26 @@ export default function FriendsPhoto() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 将两个图片URL用逗号分隔
|
// 将两个图片URL用逗号分隔
|
||||||
const combinedImageUrl = `${image1},${image2}`;
|
const { hostname, protocol, port } = window.location;
|
||||||
|
let baseUrl = `${protocol}//${hostname}`
|
||||||
const taskId = await serverSdk.executeTemplate({
|
if (hostname === 'localhost') {
|
||||||
imageUrl: combinedImageUrl,
|
baseUrl = `${protocol}//${hostname}:${port}`
|
||||||
|
}
|
||||||
|
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'));
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ const ResultPage: React.FC = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const paymentId = searchParams.get('payment_id') || searchParams.get('taskId');
|
const paymentId = searchParams.get('paymentId') || searchParams.get('taskId');
|
||||||
|
|
||||||
if (paymentId) {
|
if (paymentId) {
|
||||||
setTaskId(paymentId);
|
setTaskId(paymentId);
|
||||||
|
|
|
||||||
|
|
@ -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, imageUrl: string) {
|
async pay(templateCode: string, imageUrls: 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, imageUrl, cbUrl)
|
const response = await sdk.payTemplateCode(templateCode, imageUrls, cbUrl)
|
||||||
if (response.url) {
|
if (response.url) {
|
||||||
window.location.href = response.url;
|
window.location.href = response.url;
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -2,5 +2,5 @@
|
||||||
|
|
||||||
export abstract class Payment{
|
export abstract class Payment{
|
||||||
|
|
||||||
abstract pay(templateCode: string, imageUrl: string): Promise<any>;
|
abstract pay(templateCode: string, imageUrls: string[]): Promise<any>;
|
||||||
}
|
}
|
||||||
|
|
@ -81,9 +81,9 @@ export interface TaskProgress {
|
||||||
*/
|
*/
|
||||||
export interface CreateCheckoutParams {
|
export interface CreateCheckoutParams {
|
||||||
templateCode: string; // 模板代码
|
templateCode: string; // 模板代码
|
||||||
userId: string; // 用户ID
|
|
||||||
metadata: {
|
metadata: {
|
||||||
imageUrl: string; // 图片URL
|
imageUrls: string[]; // 图片URL
|
||||||
|
cb_url: string;
|
||||||
[key: string]: any; // 其他元数据
|
[key: string]: any; // 其他元数据
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -129,6 +129,8 @@ export interface GoogleUserInfo {
|
||||||
email: string; // 邮箱
|
email: string; // 邮箱
|
||||||
name: string; // 姓名
|
name: string; // 姓名
|
||||||
picture?: string; // 头像URL
|
picture?: string; // 头像URL
|
||||||
|
customerId?: string;
|
||||||
|
created?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -370,13 +372,13 @@ export class SdkServer {
|
||||||
/**
|
/**
|
||||||
* 如果多图的话 images.join(',')
|
* 如果多图的话 images.join(',')
|
||||||
*/
|
*/
|
||||||
async payTemplateCode(templateCode: string, imageUrl: string, cbUrl: string) {
|
async payTemplateCode(templateCode: string, imageUrls: string[], cbUrl: string) {
|
||||||
try {
|
try {
|
||||||
const response = await this.request(`/payment/checkout/${templateCode}`, 'POST', {
|
const response = await this.request(`/payment/checkout/${templateCode}`, 'POST', {
|
||||||
imageUrl: imageUrl,
|
imageUrls: imageUrls, // 图片URL
|
||||||
cb_url: cbUrl
|
cb_url: cbUrl
|
||||||
})
|
})
|
||||||
return response.data as {url: string};
|
return response.data as { url: string };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
@ -589,7 +591,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 +640,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;
|
||||||
|
|
@ -660,10 +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', params.metadata);
|
||||||
userId: params.userId,
|
|
||||||
metadata: params.metadata
|
|
||||||
});
|
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue