You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
3.6 KiB

import apiService from './apiClient';
// 支付方式类型定义
export interface PaymentMethod {
key: string;
value: string | string[];
}
export interface CountryPaymentMethods {
country?: number;
country_name?: string;
payment_methods: PaymentMethod[];
}
export interface PaymentMethodsResponse {
current_country_code: number;
current_country_methods: PaymentMethod[];
other_country_methods: CountryPaymentMethods[];
}
1 month ago
export interface PaymentInfoResponse {
success: boolean;
payment_url: string;
msg: string;
}
export interface PayInfoBody {
3 weeks ago
order_id: number | string;
1 month ago
method: string;
4 weeks ago
amount: number;
1 month ago
currency: string;
}
3 weeks ago
// 新增充值接口请求体类型
export interface RechargeInitiateBody {
amount: number;
currency: string;
payment_method: string;
phone?: string;
}
// 新增充值接口返回类型
export interface RechargeInitiateResponse {
success: boolean;
recharge_id: number;
payment: {
success: boolean;
msg: string;
payment_url: string;
order_id: number;
method: string;
status: string | null;
transaction_id: string;
};
msg: string | null;
}
export interface ConvertCurrencyBody {
from_currency: string;
to_currency: string;
amounts: {
total_amount?: number;
domestic_shipping_fee?: number;
shipping_fee?: number;
};
}
3 weeks ago
export interface PaySuccessCallbackBody {
success: boolean;
msg: string;
order_id: number;
transaction_id: string;
status: number;
}
export interface rechargeHistory {
recharge_id: number;
user_id: number;
amount: number;
currency: string;
payment_method: string;
status: number;
transaction_id: string;
create_time: string;
update_time: string;
}
3 weeks ago
export interface RechargeRecommendAmountResponse {
amounts: number[];
currency: string;
}
2 weeks ago
export interface Transaction {
transaction_id: string;
type: "order_payment"; // Assuming 'order_payment' is the only possible type for this dataset
amount: number;
currency: string;
description: string;
timestamp: string; // Could also be `Date` if you plan to parse it immediately
related_order_no: string;
}
export interface TransactionsResponse {
items: Transaction[];
total: number;
page: number;
page_size: number;
}
export const payApi = {
// 获取当前国家支付方式
getCountryPaymentMethods: () => {
4 weeks ago
return apiService.get<PaymentMethodsResponse>('/api/payment/country_payment_methods/');
},
1 month ago
// 获取支付信息
getPayInfo: (data: PayInfoBody) => {
4 weeks ago
return apiService.post<PaymentInfoResponse>(`/api/payment/initiate/`, data);
1 month ago
},
// 货币转换
convertCurrency: (data: ConvertCurrencyBody) => {
return apiService.post<any>(`/api/currency/convert/`, data);
},
3 weeks ago
// 支付成功的回调
paySuccessCallback: (paymentId:string,PayerID:string) => {
return apiService.post<PaySuccessCallbackBody>(`/api/payment/paypal/execute/`,{paymentId,PayerID});
3 weeks ago
},
3 weeks ago
// 新增充值接口
initiateRecharge: (data: RechargeInitiateBody) => {
return apiService.post<RechargeInitiateResponse>('/api/recharge/initiate/', data);
},
// 获取充值历史
getRechargeHistory: () => {
return apiService.get<rechargeHistory[]>('/api/recharge/records/');
},
3 weeks ago
//获取充值推荐金额
getRechargeRecommendAmount: () => {
return apiService.get<RechargeRecommendAmountResponse>('/api/recharge/recommended-amounts/');
},
2 weeks ago
// 获取流水
getTransactionHistory: (page:number,page_size:number) => {
return apiService.get<TransactionsResponse>(`/api/users/me/transactions/?page=${page}&page_size=${page_size}`);
},
};