feat(payments): add Order & Escrow entities with CQRS commands, Prisma schema

- Add Order entity with lifecycle (pending → paid → completed/cancelled/refunded)
- Add Escrow entity with hold/release/dispute flow for secure transactions
- Add PlatformFee value object with tiered commission calculation
- Implement CQRS: CreateOrder, CancelOrder, HoldEscrow, ReleaseEscrow commands
- Add GetOrderStatus query handler
- Add OrdersController with REST endpoints and DTOs
- Add Prisma models for Order, Escrow, EscrowStatusHistory
- Add domain event classes for order and escrow state changes
- Add unit tests for Order, Escrow entities and PlatformFee VO
- Update PROJECT_TRACKER to Wave 14 status

Co-Authored-By: Claude Opus 4 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ho Ngoc Hai
2026-04-12 23:40:00 +07:00
parent 836499c1cf
commit 2c97f99214
42 changed files with 1786 additions and 34 deletions

View File

@@ -1,32 +1,52 @@
import { Module } from '@nestjs/common';
import { CqrsModule } from '@nestjs/cqrs';
import { CancelOrderHandler } from './application/commands/cancel-order/cancel-order.handler';
import { CreateOrderHandler } from './application/commands/create-order/create-order.handler';
import { CreatePaymentHandler } from './application/commands/create-payment/create-payment.handler';
import { HandleCallbackHandler } from './application/commands/handle-callback/handle-callback.handler';
import { HoldEscrowHandler } from './application/commands/hold-escrow/hold-escrow.handler';
import { RefundPaymentHandler } from './application/commands/refund-payment/refund-payment.handler';
import { ReleaseEscrowHandler } from './application/commands/release-escrow/release-escrow.handler';
import { GetOrderStatusHandler } from './application/queries/get-order-status/get-order-status.handler';
import { GetPaymentStatusHandler } from './application/queries/get-payment-status/get-payment-status.handler';
import { ListTransactionsHandler } from './application/queries/list-transactions/list-transactions.handler';
import { ESCROW_REPOSITORY } from './domain/repositories/escrow.repository';
import { ORDER_REPOSITORY } from './domain/repositories/order.repository';
import { PAYMENT_REPOSITORY } from './domain/repositories/payment.repository';
import { PrismaEscrowRepository } from './infrastructure/repositories/prisma-escrow.repository';
import { PrismaOrderRepository } from './infrastructure/repositories/prisma-order.repository';
import { PrismaPaymentRepository } from './infrastructure/repositories/prisma-payment.repository';
import { MomoService } from './infrastructure/services/momo.service';
import { PaymentGatewayFactory } from './infrastructure/services/payment-gateway.factory';
import { PAYMENT_GATEWAY_FACTORY } from './infrastructure/services/payment-gateway.interface';
import { VnpayService } from './infrastructure/services/vnpay.service';
import { ZalopayService } from './infrastructure/services/zalopay.service';
import { OrdersController } from './presentation/controllers/orders.controller';
import { PaymentsController } from './presentation/controllers/payments.controller';
const CommandHandlers = [
CancelOrderHandler,
CreateOrderHandler,
CreatePaymentHandler,
HandleCallbackHandler,
HoldEscrowHandler,
RefundPaymentHandler,
ReleaseEscrowHandler,
];
const QueryHandlers = [GetPaymentStatusHandler, ListTransactionsHandler];
const QueryHandlers = [
GetOrderStatusHandler,
GetPaymentStatusHandler,
ListTransactionsHandler,
];
@Module({
imports: [CqrsModule],
controllers: [PaymentsController],
controllers: [OrdersController, PaymentsController],
providers: [
// Repositories
{ provide: ESCROW_REPOSITORY, useClass: PrismaEscrowRepository },
{ provide: ORDER_REPOSITORY, useClass: PrismaOrderRepository },
{ provide: PAYMENT_REPOSITORY, useClass: PrismaPaymentRepository },
// Gateway Services
@@ -39,6 +59,6 @@ const QueryHandlers = [GetPaymentStatusHandler, ListTransactionsHandler];
...CommandHandlers,
...QueryHandlers,
],
exports: [PAYMENT_REPOSITORY, PAYMENT_GATEWAY_FACTORY],
exports: [ESCROW_REPOSITORY, ORDER_REPOSITORY, PAYMENT_REPOSITORY, PAYMENT_GATEWAY_FACTORY],
})
export class PaymentsModule {}