102 lines
3.2 KiB
TypeScript
102 lines
3.2 KiB
TypeScript
// features/onlinePaymentHistory/api/onlinePaymentsHistoryApi.ts
|
|
|
|
import apiClient from "@/lib/api/client";
|
|
|
|
// ─── Shared ───────────────────────────────────────────────────────────────────
|
|
|
|
export interface LocalizedText {
|
|
en: string;
|
|
ru: string;
|
|
tm: string;
|
|
}
|
|
|
|
// ─── List Types ───────────────────────────────────────────────────────────────
|
|
|
|
/** Gateway status values returned by the backend. */
|
|
export type GatewayStatus = "success" | "failed" | "pending" | "processing";
|
|
|
|
export interface OnlinePayment {
|
|
id: number;
|
|
orderId: number;
|
|
orderUniqueId: string;
|
|
type: string; // "visa" | "sber" | "kart" | ...
|
|
branchId: number;
|
|
branchName: LocalizedText;
|
|
passportName: string;
|
|
passportSurname: string;
|
|
userId: number;
|
|
paid: boolean;
|
|
amountTmt: number;
|
|
bankFeeTmt: number;
|
|
gbusFeeTmt: number;
|
|
totalAmountTmt: number;
|
|
exchangeRateUsd: number;
|
|
paymentPeriod: string;
|
|
gatewayStatus: string;
|
|
gatewayReference: string;
|
|
createdById: number;
|
|
createdByName: string;
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
}
|
|
|
|
export interface OnlinePaymentListParams {
|
|
orderId?: number;
|
|
branchId?: number;
|
|
userId?: number;
|
|
status?: string;
|
|
search?: string;
|
|
page?: number;
|
|
limit?: number;
|
|
}
|
|
|
|
/** Shape returned by the backend after the axios envelope is unwrapped. */
|
|
export interface OnlinePaymentListResponse {
|
|
count: number;
|
|
items: OnlinePayment[];
|
|
}
|
|
|
|
// ─── Detail / History Step Types ─────────────────────────────────────────────
|
|
|
|
export interface PaymentHistoryStep {
|
|
id: number;
|
|
orderId: number;
|
|
step: string;
|
|
detail: Record<string, string>;
|
|
createdById: number;
|
|
createdByName: string;
|
|
createdAt: string;
|
|
}
|
|
|
|
// ─── API Functions ────────────────────────────────────────────────────────────
|
|
|
|
/**
|
|
* GET /payment-history
|
|
* Returns paginated list of online payment records.
|
|
* Query params: order_id, branch_id, user_id, status, search, page, limit
|
|
*/
|
|
export async function fetchOnlinePayments(params: OnlinePaymentListParams = {}): Promise<OnlinePaymentListResponse> {
|
|
const { orderId, branchId, userId, status, search, page, limit } = params;
|
|
const { data } = await apiClient.get<OnlinePaymentListResponse>("/payment-history", {
|
|
params: {
|
|
order_id: orderId || undefined,
|
|
branch_id: branchId || undefined,
|
|
user_id: userId || undefined,
|
|
status: status || undefined,
|
|
search: search || undefined,
|
|
page: page ?? 1,
|
|
limit: limit ?? 25,
|
|
},
|
|
});
|
|
return data;
|
|
}
|
|
|
|
/**
|
|
* GET /payment-history/:id
|
|
* Returns the step-by-step history log for a single payment order.
|
|
*/
|
|
export async function fetchOnlinePaymentById(id: number): Promise<PaymentHistoryStep[]> {
|
|
const { data } = await apiClient.get<PaymentHistoryStep[]>(`/payment-history/${id}`);
|
|
return data;
|
|
}
|