import api, { authorizeApi } from './api'; import { PaymentTransaction, CreditCard, AuthorizeTransaction, TransactionListResponse, CardListResponse, CreateCardRequest, PaymentRequest, AxiosResponse, TokenizeCardRequest, UpdateTokenizedCardRequest, ChargeSavedCardRequest, ChargeDirectRequest, CaptureRequest, PreauthorizeSavedCardRequest, AuthorizeNetTransactionResponse, CardResponse, CardsResponse } from '../types/models'; export const paymentService = { // Card management (Main API) getCard: (id: number): Promise> => api.get(`/payment/card/${id}`), getCards: (customerId: number): Promise> => api.get(`/payment/cards/${customerId}`), getCardsOnFile: (customerId: number): Promise> => api.get(`/payment/cards/onfile/${customerId}`), getAllCards: (page: number = 1): Promise> => api.get(`/payment/cards/all/${page}`), createCard: (customerId: number, data: CreateCardRequest): Promise> => api.post(`/payment/card/create/${customerId}`, data), updateCard: (id: number, data: Partial): Promise> => api.put(`/payment/card/edit/${id}`, data), removeCard: (id: number): Promise> => api.delete(`/payment/card/remove/${id}`), removeCardAlt: (id: number): Promise> => api.delete(`/payment/cards/remove/${id}`), updatePaymentProfile: (id: number, data: { auth_net_payment_profile_id: string }): Promise> => api.put(`/payment/card/update_payment_profile/${id}`, data), // Authorization & capture (Main API) authorizeDelivery: (id: number, data: PaymentRequest): Promise> => api.put(`/payment/authorize/${id}`, data), authorizeService: (id: number, data: PaymentRequest): Promise> => api.put(`/payment/authorize/service/${id}`, data), cleanupAuthorization: (id: number): Promise> => api.put(`/payment/authorize/cleanup/${id}`), captureServicePayment: (id: number, data: { amount: number }): Promise> => api.put(`/payment/capture/service/${id}`, data), // Service payment getServicePayment: (id: number, type: string): Promise> => api.get(`/payment/service/payment/${id}/${type}`), // Transactions getDeliveryTransaction: (id: number): Promise> => api.get(`/payment/transaction/delivery/${id}`), getAuthorizeTransactions: (): Promise> => api.get('/payment/transactions/authorize/1'), getCustomerTransactions: (customerId: number, page: number = 1): Promise> => api.get(`/payment/transactions/customer/${customerId}/${page}`), getServiceTransactions: (serviceId: number): Promise> => api.get(`/payment/transactions/service/${serviceId}`), // Authorize.net endpoints authorize: { tokenizeCard: (customerId: number, data: TokenizeCardRequest): Promise> => authorizeApi.post(`/api/payments/customers/${customerId}/cards`, data), updateTokenizedCard: (customerId: number, cardId: number, data: UpdateTokenizedCardRequest): Promise> => authorizeApi.put(`/api/payments/customers/${customerId}/cards/${cardId}`, data), authorizeSavedCard: (customerId: number, data: PreauthorizeSavedCardRequest): Promise> => authorizeApi.post(`/api/payments/authorize/saved-card/${customerId}`, data), chargeSavedCard: (customerId: number, data: ChargeSavedCardRequest): Promise> => authorizeApi.post(`/api/payments/charge/saved-card/${customerId}`, data), charge: (customerId: number, data: ChargeDirectRequest): Promise> => authorizeApi.post(`/api/charge/${customerId}`, data), capture: (data: CaptureRequest): Promise> => authorizeApi.post('/api/payments/capture', data), // Auto transaction endpoints getAutoTransaction: (deliveryId: number): Promise> => authorizeApi.get(`/api/auto/transaction/delivery/${deliveryId}`), updateAutoTransactionId: (deliveryId: number, newId: number, data?: Record): Promise> => authorizeApi.put(`/api/auto/transaction/delivery/${deliveryId}/update/${newId}`, data ?? {}), linkTransactionToAuto: (transactionId: number, autoId: number, data?: Record): Promise> => authorizeApi.put(`/api/transaction/${transactionId}/update_auto_id/${autoId}`, data ?? {}), // Check authorize account status checkAccount: (customerId: number): Promise> => authorizeApi.get(`/user/check-authorize-account/${customerId}`), }, // Convenience wrappers for commonly used operations getCardById: (id: number): Promise> => api.get(`/payment/card/${id}`), checkAuthorizeAccount: (customerId: number): Promise> => authorizeApi.get(`/user/check-authorize-account/${customerId}`), createAuthorizeCard: (customerId: number, data: TokenizeCardRequest): Promise> => authorizeApi.post(`/api/payments/customers/${customerId}/cards`, data), updateAuthorizeCard: (customerId: number, cardId: number, data: UpdateTokenizedCardRequest): Promise> => authorizeApi.put(`/api/payments/customers/${customerId}/cards/${cardId}`, data), }; export default paymentService;