82 lines
3.0 KiB
TypeScript
82 lines
3.0 KiB
TypeScript
import { BaseApiClient } from '../base/BaseApiClient';
|
|
|
|
// TODO: Import these types from apps/website/lib/types/generated when available
|
|
type GetPaymentsOutputDto = { payments: import('../types/generated').PaymentDto[] };
|
|
type CreatePaymentInputDto = {
|
|
type: 'sponsorship' | 'membership_fee';
|
|
amount: number;
|
|
payerId: string;
|
|
payerType: 'sponsor' | 'driver';
|
|
leagueId: string;
|
|
seasonId?: string;
|
|
};
|
|
type CreatePaymentOutputDto = { payment: import('../types/generated').PaymentDto };
|
|
type GetMembershipFeesOutputDto = {
|
|
fee: import('../types/generated').MembershipFeeDto | null;
|
|
payments: import('../types/generated').MemberPaymentDto[]
|
|
};
|
|
type GetPrizesOutputDto = { prizes: import('../types/generated').PrizeDto[] };
|
|
type GetWalletOutputDto = {
|
|
wallet: import('../types/generated').WalletDto;
|
|
transactions: import('../types/generated').TransactionDto[]
|
|
};
|
|
type ProcessWalletTransactionInputDto = {
|
|
leagueId: string;
|
|
type: 'deposit' | 'withdrawal' | 'platform_fee';
|
|
amount: number;
|
|
description: string;
|
|
referenceId?: string;
|
|
referenceType?: 'sponsorship' | 'membership_fee' | 'prize';
|
|
};
|
|
type ProcessWalletTransactionOutputDto = {
|
|
wallet: import('../types/generated').WalletDto;
|
|
transaction: import('../types/generated').TransactionDto
|
|
};
|
|
type UpdateMemberPaymentInputDto = {
|
|
feeId: string;
|
|
driverId: string;
|
|
status?: 'pending' | 'paid' | 'overdue';
|
|
paidAt?: Date | string;
|
|
};
|
|
type UpdateMemberPaymentOutputDto = { payment: import('../types/generated').MemberPaymentDto };
|
|
type GetWalletTransactionsOutputDto = { transactions: import('../types/generated').TransactionDto[] };
|
|
|
|
/**
|
|
* Payments API Client
|
|
*
|
|
* Handles all payment-related API operations.
|
|
*/
|
|
export class PaymentsApiClient extends BaseApiClient {
|
|
/** Get payments */
|
|
getPayments(leagueId?: string, driverId?: string): Promise<GetPaymentsOutputDto> {
|
|
const params = new URLSearchParams();
|
|
if (leagueId) params.append('leagueId', leagueId);
|
|
if (driverId) params.append('driverId', driverId);
|
|
const query = params.toString();
|
|
return this.get<GetPaymentsOutputDto>(`/payments${query ? `?${query}` : ''}`);
|
|
}
|
|
|
|
/** Create a payment */
|
|
createPayment(input: CreatePaymentInputDto): Promise<CreatePaymentOutputDto> {
|
|
return this.post<CreatePaymentOutputDto>('/payments', input);
|
|
}
|
|
|
|
/** Get membership fees */
|
|
getMembershipFees(leagueId: string): Promise<GetMembershipFeesOutputDto> {
|
|
return this.get<GetMembershipFeesOutputDto>(`/payments/membership-fees?leagueId=${leagueId}`);
|
|
}
|
|
|
|
/** Get prizes */
|
|
getPrizes(leagueId?: string, seasonId?: string): Promise<GetPrizesOutputDto> {
|
|
const params = new URLSearchParams();
|
|
if (leagueId) params.append('leagueId', leagueId);
|
|
if (seasonId) params.append('seasonId', seasonId);
|
|
const query = params.toString();
|
|
return this.get<GetPrizesOutputDto>(`/payments/prizes${query ? `?${query}` : ''}`);
|
|
}
|
|
|
|
/** Get wallet */
|
|
getWallet(driverId: string): Promise<GetWalletOutputDto> {
|
|
return this.get<GetWalletOutputDto>(`/payments/wallets?driverId=${driverId}`);
|
|
}
|
|
} |