diff --git a/src/app.integration.ts b/src/app.integration.ts index 16ebeaf..9165030 100644 --- a/src/app.integration.ts +++ b/src/app.integration.ts @@ -52,7 +52,6 @@ import { MobileSession, OfflineSyncQueue, PushToken, - PaymentTransaction, } from './modules/mobile/entities'; import { @@ -146,7 +145,6 @@ export function getAllEntities() { MobileSession, OfflineSyncQueue, PushToken, - PaymentTransaction, // Billing SubscriptionPlan, TenantSubscription, diff --git a/src/modules/invoices/index.ts b/src/modules/invoices/index.ts index 27cce0a..c2fb0ad 100644 --- a/src/modules/invoices/index.ts +++ b/src/modules/invoices/index.ts @@ -1,3 +1,10 @@ +/** + * @deprecated This module is deprecated. Use 'financial' module instead. + * The invoices functionality has been consolidated into the financial module + * for better integration with accounting and GL posting. + * See: docs/90-adr/ADR-019-CONSOLIDATE-INVOICES-FINANCIAL.md + * Migration: Import from './modules/financial' instead of './modules/invoices' + */ export { InvoicesModule, invoicesModule } from './invoices.module.js'; export * from './entities/index.js'; export { InvoicesService, invoicesService } from './services/index.js'; diff --git a/src/modules/mobile/entities/index.ts b/src/modules/mobile/entities/index.ts index a109c57..88a2c9a 100644 --- a/src/modules/mobile/entities/index.ts +++ b/src/modules/mobile/entities/index.ts @@ -3,4 +3,4 @@ export { OfflineSyncQueue, SyncOperation, SyncStatus, ConflictResolution } from export { SyncConflict, ConflictType, ConflictResolutionType } from './sync-conflict.entity'; export { PushToken, PushProvider } from './push-token.entity'; export { PushNotificationLog, NotificationStatus, NotificationCategory } from './push-notification-log.entity'; -export { PaymentTransaction, PaymentSourceType, PaymentMethod, PaymentStatus, CardType } from './payment-transaction.entity'; +// PaymentTransaction removed - use payment-terminals module instead diff --git a/src/modules/payment-terminals/dto/transaction.dto.ts b/src/modules/payment-terminals/dto/transaction.dto.ts index 0a1bfe5..d93f4b4 100644 --- a/src/modules/payment-terminals/dto/transaction.dto.ts +++ b/src/modules/payment-terminals/dto/transaction.dto.ts @@ -2,7 +2,7 @@ * Transaction DTOs */ -import { PaymentSourceType, PaymentMethod, PaymentStatus } from '../../mobile/entities/payment-transaction.entity'; +import { PaymentSourceType, PaymentMethod, PaymentStatus } from '../entities/payment-transaction.entity'; export class ProcessPaymentDto { terminalId: string; diff --git a/src/modules/payment-terminals/entities/index.ts b/src/modules/payment-terminals/entities/index.ts index 766af69..a913c03 100644 --- a/src/modules/payment-terminals/entities/index.ts +++ b/src/modules/payment-terminals/entities/index.ts @@ -1,3 +1,4 @@ export * from './tenant-terminal-config.entity'; export * from './terminal-payment.entity'; export * from './terminal-webhook-event.entity'; +export * from './payment-transaction.entity'; diff --git a/src/modules/payment-terminals/entities/payment-transaction.entity.ts b/src/modules/payment-terminals/entities/payment-transaction.entity.ts new file mode 100644 index 0000000..b9da1a4 --- /dev/null +++ b/src/modules/payment-terminals/entities/payment-transaction.entity.ts @@ -0,0 +1,115 @@ +import { + Entity, + PrimaryGeneratedColumn, + Column, + CreateDateColumn, + UpdateDateColumn, + Index, +} from 'typeorm'; + +export type PaymentSourceType = 'sale' | 'invoice' | 'subscription'; +export type PaymentMethod = 'card' | 'contactless' | 'qr' | 'link'; +export type PaymentStatus = 'pending' | 'processing' | 'completed' | 'failed' | 'refunded' | 'cancelled'; +export type CardType = 'credit' | 'debit'; + +@Entity({ name: 'payment_transactions', schema: 'mobile' }) +export class PaymentTransaction { + @PrimaryGeneratedColumn('uuid') + id: string; + + @Index() + @Column({ name: 'tenant_id', type: 'uuid' }) + tenantId: string; + + @Index() + @Column({ name: 'branch_id', type: 'uuid', nullable: true }) + branchId: string; + + @Index() + @Column({ name: 'user_id', type: 'uuid' }) + userId: string; + + @Column({ name: 'device_id', type: 'uuid', nullable: true }) + deviceId: string; + + // Referencia al documento origen + @Index() + @Column({ name: 'source_type', type: 'varchar', length: 30 }) + sourceType: PaymentSourceType; + + @Column({ name: 'source_id', type: 'uuid' }) + sourceId: string; + + // Terminal de pago + @Column({ name: 'terminal_provider', type: 'varchar', length: 30 }) + terminalProvider: string; // clip, mercadopago, stripe + + @Column({ name: 'terminal_id', type: 'varchar', length: 100, nullable: true }) + terminalId: string; + + // Transaccion + @Index() + @Column({ name: 'external_transaction_id', type: 'varchar', length: 255, nullable: true }) + externalTransactionId: string; + + @Column({ type: 'decimal', precision: 12, scale: 2 }) + amount: number; + + @Column({ type: 'varchar', length: 3, default: 'MXN' }) + currency: string; + + @Column({ name: 'tip_amount', type: 'decimal', precision: 12, scale: 2, default: 0 }) + tipAmount: number; + + @Column({ name: 'total_amount', type: 'decimal', precision: 12, scale: 2 }) + totalAmount: number; + + // Metodo de pago + @Column({ name: 'payment_method', type: 'varchar', length: 30 }) + paymentMethod: PaymentMethod; + + @Column({ name: 'card_brand', type: 'varchar', length: 20, nullable: true }) + cardBrand: string; // visa, mastercard, amex + + @Column({ name: 'card_last_four', type: 'varchar', length: 4, nullable: true }) + cardLastFour: string; + + @Column({ name: 'card_type', type: 'varchar', length: 20, nullable: true }) + cardType: CardType; + + // Estado + @Index() + @Column({ type: 'varchar', length: 20, default: 'pending' }) + status: PaymentStatus; + + @Column({ name: 'failure_reason', type: 'text', nullable: true }) + failureReason: string; + + // Tiempos + @Column({ name: 'initiated_at', type: 'timestamptz', default: () => 'CURRENT_TIMESTAMP' }) + initiatedAt: Date; + + @Column({ name: 'completed_at', type: 'timestamptz', nullable: true }) + completedAt: Date; + + // Metadata del proveedor + @Column({ name: 'provider_response', type: 'jsonb', default: {} }) + providerResponse: Record; + + // Recibo + @Column({ name: 'receipt_url', type: 'text', nullable: true }) + receiptUrl: string; + + @Column({ name: 'receipt_sent', type: 'boolean', default: false }) + receiptSent: boolean; + + @Column({ name: 'receipt_sent_to', type: 'varchar', length: 255, nullable: true }) + receiptSentTo: string; + + @Index() + @CreateDateColumn({ name: 'created_at', type: 'timestamptz' }) + createdAt: Date; + + @UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' }) + updatedAt: Date; +} diff --git a/src/modules/payment-terminals/services/transactions.service.ts b/src/modules/payment-terminals/services/transactions.service.ts index 146fde5..d51e5ea 100644 --- a/src/modules/payment-terminals/services/transactions.service.ts +++ b/src/modules/payment-terminals/services/transactions.service.ts @@ -9,7 +9,7 @@ import { PaymentTransaction, PaymentStatus, PaymentMethod, -} from '../../mobile/entities/payment-transaction.entity'; +} from '../entities/payment-transaction.entity'; import { BranchPaymentTerminal } from '../../branches/entities/branch-payment-terminal.entity'; import { ProcessPaymentDto,