import { Column, CreateDateColumn, Entity, Index, PrimaryGeneratedColumn, UpdateDateColumn, } from 'typeorm'; export type PaymentStatus = 'pending' | 'success' | 'failed' | 'refunded'; /** * `topup` = شحن محفظة الراكب (**أمانة** — تبقى ملكه). * `credit_topup` = شحن السائق رصيده التشغيلي (**إيراد** المستأجر — docs/24 §3.1). * `trip` = دفع أجرة رحلة. * التمييز بين الأولين جوهري: خلطهما يجعل تقرير الأرباح كاذباً. */ export type PaymentPurpose = 'topup' | 'credit_topup' | 'trip'; /** * معاملة دفع. الجدول: tripz_pay_payments («schema الدفع» منطقياً — قابل للفصل). */ @Entity('pay_payments') @Index(['tenant_id', 'user_id']) @Index(['tenant_id', 'status']) export class Payment { @PrimaryGeneratedColumn('uuid') id: string; @Column({ type: 'uuid' }) tenant_id: string; @Column({ type: 'uuid' }) user_id: string; @Column({ type: 'uuid', nullable: true }) trip_id: string | null; @Column({ default: 'topup' }) purpose: PaymentPurpose; @Column() provider: string; // cash | cliq | zaincash | syriatel | mtn | shamcash | paymob | fawry @Column({ type: 'varchar', nullable: true }) method: string | null; @Column({ type: 'numeric', precision: 12, scale: 3 }) amount: number; @Column({ default: 'JOD' }) currency: string; @Column({ type: 'varchar', default: 'pending' }) status: PaymentStatus; @Column({ type: 'varchar', nullable: true }) tx_ref: string | null; @Column({ type: 'varchar', nullable: true }) redirect_url: string | null; @Column({ type: 'jsonb', default: {} }) meta: Record; @CreateDateColumn() created_at: Date; @UpdateDateColumn() updated_at: Date; }