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[]; } export interface PaymentInfoResponse { success: boolean; payment_url: string; msg: string; } export interface PayInfoBody { order_id: number | string; method: string; amount: number; currency: string; } // 新增充值接口请求体类型 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; }; } 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; } export const payApi = { // 获取当前国家支付方式 getCountryPaymentMethods: () => { return apiService.get('/api/payment/country_payment_methods/'); }, // 获取支付信息 getPayInfo: (data: PayInfoBody) => { return apiService.post(`/api/payment/initiate/`, data); }, // 货币转换 convertCurrency: (data: ConvertCurrencyBody) => { return apiService.post(`/api/currency/convert/`, data); }, // 支付成功的回调 paySuccessCallback: (paymentId:string,PayerID:string) => { return apiService.post(`/api/payment/paypal/execute/`,{paymentId,PayerID}); }, // 新增充值接口 initiateRecharge: (data: RechargeInitiateBody) => { return apiService.post('/api/recharge/initiate/', data); }, // 获取充值历史 getRechargeHistory: () => { return apiService.get('/api/recharge/records/'); }, };