/** * Admin Payment API endpoints * Handles payment management operations for administrators */ import { apiClient } from '../client' import type { DashboardStats, PaymentOrder, PaymentChannel, SubscriptionPlan, ProviderInstance } from '@/types/payment' import type { BasePaginationResponse } from '@/types' /** Admin-facing payment config returned by GET /admin/payment/config */ export interface AdminPaymentConfig { enabled: boolean min_amount: number max_amount: number daily_limit: number order_timeout_minutes: number max_pending_orders: number enabled_payment_types: string[] balance_disabled: boolean load_balance_strategy: string product_name_prefix: string product_name_suffix: string help_image_url: string help_text: string } /** Fields accepted by PUT /admin/payment/config (all optional via pointer semantics) */ export interface UpdatePaymentConfigRequest { enabled?: boolean min_amount?: number max_amount?: number daily_limit?: number order_timeout_minutes?: number max_pending_orders?: number enabled_payment_types?: string[] balance_disabled?: boolean load_balance_strategy?: string product_name_prefix?: string product_name_suffix?: string help_image_url?: string help_text?: string } export const adminPaymentAPI = { // ==================== Config ==================== /** Get payment configuration (admin view) */ getConfig() { return apiClient.get('/admin/payment/config') }, /** Update payment configuration */ updateConfig(data: UpdatePaymentConfigRequest) { return apiClient.put('/admin/payment/config', data) }, // ==================== Dashboard ==================== /** Get payment dashboard statistics */ getDashboard(days?: number) { return apiClient.get('/admin/payment/dashboard', { params: days ? { days } : undefined }) }, // ==================== Orders ==================== /** Get all orders (paginated, with filters) */ getOrders(params?: { page?: number page_size?: number status?: string payment_type?: string user_id?: number keyword?: string start_date?: string end_date?: string order_type?: string }) { return apiClient.get>('/admin/payment/orders', { params }) }, /** Get a specific order by ID */ getOrder(id: number) { return apiClient.get(`/admin/payment/orders/${id}`) }, /** Cancel an order (admin) */ cancelOrder(id: number) { return apiClient.post(`/admin/payment/orders/${id}/cancel`) }, /** Retry recharge for a failed order */ retryRecharge(id: number) { return apiClient.post(`/admin/payment/orders/${id}/retry`) }, /** Process a refund */ refundOrder(id: number, data: { amount: number; reason: string; deduct_balance?: boolean; force?: boolean }) { return apiClient.post(`/admin/payment/orders/${id}/refund`, data) }, // ==================== Channels ==================== /** Get all payment channels */ getChannels() { return apiClient.get('/admin/payment/channels') }, /** Create a payment channel */ createChannel(data: Partial) { return apiClient.post('/admin/payment/channels', data) }, /** Update a payment channel */ updateChannel(id: number, data: Partial) { return apiClient.put(`/admin/payment/channels/${id}`, data) }, /** Delete a payment channel */ deleteChannel(id: number) { return apiClient.delete(`/admin/payment/channels/${id}`) }, // ==================== Subscription Plans ==================== /** Get all subscription plans */ getPlans() { return apiClient.get('/admin/payment/plans') }, /** Create a subscription plan */ createPlan(data: Record) { return apiClient.post('/admin/payment/plans', data) }, /** Update a subscription plan */ updatePlan(id: number, data: Record) { return apiClient.put(`/admin/payment/plans/${id}`, data) }, /** Delete a subscription plan */ deletePlan(id: number) { return apiClient.delete(`/admin/payment/plans/${id}`) }, // ==================== Provider Instances ==================== /** Get all provider instances */ getProviders() { return apiClient.get('/admin/payment/providers') }, /** Create a provider instance */ createProvider(data: Partial) { return apiClient.post('/admin/payment/providers', data) }, /** Update a provider instance */ updateProvider(id: number, data: Partial) { return apiClient.put(`/admin/payment/providers/${id}`, data) }, /** Delete a provider instance */ deleteProvider(id: number) { return apiClient.delete(`/admin/payment/providers/${id}`) } } export default adminPaymentAPI