Files
approagency-admin-panel/types/purchase.ts
T
2026-08-02 19:37:22 +03:30

96 lines
2.8 KiB
TypeScript

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;
// Display-only pricing (متن نمایشی — بدون محاسبه)
discounted_price: string | null; // قیمت کلی تخفیف‌خورده
discount: string | 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;
product_id?: number; // filter by a specific product
per_page?: number;
page?: number;
}