feat: add callback URL handling and payTemplateCode method for payment flow
This commit is contained in:
parent
f80e1ce6a5
commit
399935d2ef
|
|
@ -55,9 +55,16 @@ export default function FriendsPhoto() {
|
|||
|
||||
try {
|
||||
// 将两个图片URL用逗号分隔
|
||||
const { hostname, protocol, port } = window.location;
|
||||
let baseUrl = `${protocol}//${hostname}`
|
||||
if (hostname === 'localhost') {
|
||||
baseUrl = `${protocol}//${hostname}:${port}`
|
||||
}
|
||||
const cbUrl = `${baseUrl}/result`
|
||||
const checkout = await serverSdk.createCheckoutSession({
|
||||
templateCode: templateCode,
|
||||
metadata: {
|
||||
cb_url: cbUrl,
|
||||
imageUrls: [
|
||||
image1, image2
|
||||
]
|
||||
|
|
|
|||
|
|
@ -83,6 +83,7 @@ export interface CreateCheckoutParams {
|
|||
templateCode: string; // 模板代码
|
||||
metadata: {
|
||||
imageUrls: string[]; // 图片URL
|
||||
cb_url: string;
|
||||
[key: string]: any; // 其他元数据
|
||||
};
|
||||
}
|
||||
|
|
@ -371,13 +372,13 @@ export class SdkServer {
|
|||
/**
|
||||
* 如果多图的话 images.join(',')
|
||||
*/
|
||||
async payTemplateCode(templateCode: string, imageUrl: string, cbUrl: string) {
|
||||
async payTemplateCode(templateCode: string, imageUrls: string[], cbUrl: string) {
|
||||
try {
|
||||
const response = await this.request(`/payment/checkout/${templateCode}`, 'POST', {
|
||||
imageUrl: imageUrl,
|
||||
imageUrls: imageUrls, // 图片URL
|
||||
cb_url: cbUrl
|
||||
})
|
||||
return response.data as {url: string};
|
||||
return response.data as { url: string };
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
|
|
@ -661,10 +662,7 @@ export class SdkServer {
|
|||
*/
|
||||
async createCheckoutSession(params: CreateCheckoutParams): Promise<CheckoutSessionResult> {
|
||||
try {
|
||||
const response = await this.request<CheckoutSessionResult>(`/payment/checkout/${params.templateCode}`, 'POST', {
|
||||
customer: params.customer,
|
||||
metadata: params.metadata
|
||||
});
|
||||
const response = await this.request<CheckoutSessionResult>(`/payment/checkout/${params.templateCode}`, 'POST', params.metadata);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
|
|
|
|||
Loading…
Reference in New Issue