feat:add purchesa

This commit is contained in:
2026-07-03 17:22:57 +03:30
parent 62398fbf3d
commit 3c0098ceab
4 changed files with 415 additions and 1 deletions
+91
View File
@@ -0,0 +1,91 @@
import { PackageName } from './user';
// Nested user on a purchase (subset of the full User model)
export interface PurchaseUser {
id: number;
uuid: string;
first_name: string | null;
last_name: string | null;
full_name: string | null;
email: string | null;
mobile: string | null;
}
// Nested product on a purchase, with its package
export interface PurchaseProduct {
id: number;
title: string | null;
price: number | null;
type: number | null;
package_name_id: number;
package_name: PackageName | null;
}
// A purchase = a subscription transaction
export interface Purchase {
id: number;
user_id: number;
product_id: number | null;
amount: number;
uuid: string;
status: number;
authority: string | null;
ref_id: string | null;
gateway: number;
created_at: string;
updated_at: string;
user: PurchaseUser | null;
product: PurchaseProduct | null;
}
// Laravel length-aware paginator envelope
export interface Paginated<T> {
current_page: number;
data: T[];
last_page: number;
per_page: number;
total: number;
from: number | null;
to: number | null;
next_page_url: string | null;
prev_page_url: string | null;
}
// Payment source (gateway) — matches backend Transaction::GATEWAYS
export const PAYMENT_GATEWAYS = {
asanpardakht: { code: 1, label: 'آسان‌پرداخت' },
zarinpal: { code: 2, label: 'زرین‌پال' },
digipay: { code: 3, label: 'دیجی‌پی' },
cafe: { code: 4, label: 'کافه بازار' },
myket: { code: 5, label: 'مایکت' },
} as const;
export type PaymentGatewayKey = keyof typeof PAYMENT_GATEWAYS;
export const getGatewayLabel = (gateway: number | null): string => {
const found = Object.values(PAYMENT_GATEWAYS).find((g) => g.code === gateway);
return found ? found.label : 'نامشخص';
};
// Purchase status — matches backend Transaction::STATUSES
export const PURCHASE_STATUSES: Record<number, string> = {
1: 'در انتظار پرداخت',
2: 'موفق',
3: 'مصرف‌شده',
};
export const getPurchaseStatusLabel = (status: number | null): string => {
if (status === null || status === undefined) return 'نامشخص';
return PURCHASE_STATUSES[status] || 'نامشخص';
};
// Filters sent to the purchases endpoint
export interface PurchaseFilters {
email?: string;
mobile?: string;
package_name?: string;
gateway?: string; // gateway name key (e.g. "zarinpal")
status?: number;
per_page?: number;
page?: number;
}