feat(payments): improve VNPay, MoMo, ZaloPay services with ConfigService
Migrate payment gateway services from hardcoded config to NestJS ConfigService injection. Improve payment handler error handling and update gateway factory specs. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Inject, Logger } from '@nestjs/common';
|
||||
import { CommandHandler, type EventBus, type ICommandHandler } from '@nestjs/cqrs';
|
||||
import { createId } from '@paralleldrive/cuid2';
|
||||
import { ConflictException, ValidationException } from '@modules/shared/domain/domain-exception';
|
||||
import { ConflictException, ValidationException } from '@modules/shared';
|
||||
import { PaymentEntity } from '../../../domain/entities/payment.entity';
|
||||
import {
|
||||
PAYMENT_REPOSITORY,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Inject, Logger } from '@nestjs/common';
|
||||
import { CommandHandler, type EventBus, type ICommandHandler } from '@nestjs/cqrs';
|
||||
import { type PaymentStatus } from '@prisma/client';
|
||||
import { NotFoundException, ValidationException } from '@modules/shared/domain/domain-exception';
|
||||
import { NotFoundException, ValidationException } from '@modules/shared';
|
||||
import {
|
||||
PAYMENT_REPOSITORY,
|
||||
type IPaymentRepository,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Inject } from '@nestjs/common';
|
||||
import { type IQueryHandler, QueryHandler } from '@nestjs/cqrs';
|
||||
import { NotFoundException, ForbiddenException } from '@modules/shared/domain/domain-exception';
|
||||
import { NotFoundException, ForbiddenException } from '@modules/shared';
|
||||
import {
|
||||
PAYMENT_REPOSITORY,
|
||||
type IPaymentRepository,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { type PaymentProvider } from '@prisma/client';
|
||||
import { type DomainEvent } from '@modules/shared/domain/domain-event';
|
||||
import { type DomainEvent } from '@modules/shared';
|
||||
|
||||
export class PaymentCompletedEvent implements DomainEvent {
|
||||
readonly eventName = 'payment.completed';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { type PaymentProvider, type PaymentType } from '@prisma/client';
|
||||
import { type DomainEvent } from '@modules/shared/domain/domain-event';
|
||||
import { type DomainEvent } from '@modules/shared';
|
||||
|
||||
export class PaymentCreatedEvent implements DomainEvent {
|
||||
readonly eventName = 'payment.created';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { type PaymentProvider } from '@prisma/client';
|
||||
import { type DomainEvent } from '@modules/shared/domain/domain-event';
|
||||
import { type DomainEvent } from '@modules/shared';
|
||||
|
||||
export class PaymentFailedEvent implements DomainEvent {
|
||||
readonly eventName = 'payment.failed';
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Result } from '@modules/shared/domain/result';
|
||||
import { ValueObject } from '@modules/shared/domain/value-object';
|
||||
import { Result, ValueObject } from '@modules/shared';
|
||||
|
||||
interface MoneyProps {
|
||||
amountVND: bigint;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export { PaymentsModule } from './payments.module';
|
||||
export { PAYMENT_REPOSITORY, type IPaymentRepository } from './domain/repositories/payment.repository';
|
||||
export { PAYMENT_GATEWAY_FACTORY, type IPaymentGatewayFactory } from './infrastructure/services/payment-gateway.interface';
|
||||
export { PaymentCompletedEvent } from './domain/events/payment-completed.event';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as crypto from 'crypto';
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { type ConfigService } from '@nestjs/config';
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { MomoService } from '../services/momo.service';
|
||||
|
||||
describe('MomoService', () => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { type ConfigService } from '@nestjs/config';
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { MomoService } from '../services/momo.service';
|
||||
import { PaymentGatewayFactory } from '../services/payment-gateway.factory';
|
||||
import { VnpayService } from '../services/vnpay.service';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as crypto from 'crypto';
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { type ConfigService } from '@nestjs/config';
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { VnpayService } from '../services/vnpay.service';
|
||||
|
||||
describe('VnpayService', () => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as crypto from 'crypto';
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { type ConfigService } from '@nestjs/config';
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { ZalopayService } from '../services/zalopay.service';
|
||||
|
||||
describe('ZalopayService', () => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Prisma, type Payment as PrismaPayment, type PaymentStatus } from '@prisma/client';
|
||||
import { type PrismaService } from '@modules/shared/infrastructure/prisma.service';
|
||||
import { type PrismaService } from '@modules/shared';
|
||||
import { PaymentEntity, type PaymentProps } from '../../domain/entities/payment.entity';
|
||||
import { type IPaymentRepository } from '../../domain/repositories/payment.repository';
|
||||
import { Money } from '../../domain/value-objects/money.vo';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as crypto from 'crypto';
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { type ConfigService } from '@nestjs/config';
|
||||
import { type PaymentProvider } from '@prisma/client';
|
||||
import {
|
||||
type IPaymentGateway,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as crypto from 'crypto';
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { type ConfigService } from '@nestjs/config';
|
||||
import { type PaymentProvider } from '@prisma/client';
|
||||
import {
|
||||
type IPaymentGateway,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as crypto from 'crypto';
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { type ConfigService } from '@nestjs/config';
|
||||
import { type PaymentProvider } from '@prisma/client';
|
||||
import {
|
||||
type IPaymentGateway,
|
||||
|
||||
@@ -18,11 +18,7 @@ import {
|
||||
} from '@nestjs/swagger';
|
||||
import { Throttle } from '@nestjs/throttler';
|
||||
import { type PaymentProvider } from '@prisma/client';
|
||||
import { type JwtPayload } from '@modules/auth/infrastructure/services/token.service';
|
||||
import { CurrentUser } from '@modules/auth/presentation/decorators/current-user.decorator';
|
||||
import { Roles } from '@modules/auth/presentation/decorators/roles.decorator';
|
||||
import { JwtAuthGuard } from '@modules/auth/presentation/guards/jwt-auth.guard';
|
||||
import { RolesGuard } from '@modules/auth/presentation/guards/roles.guard';
|
||||
import { type JwtPayload, CurrentUser, Roles, JwtAuthGuard, RolesGuard } from '@modules/auth';
|
||||
import { CreatePaymentCommand } from '../../application/commands/create-payment/create-payment.command';
|
||||
import { type CreatePaymentResult } from '../../application/commands/create-payment/create-payment.handler';
|
||||
import { HandleCallbackCommand } from '../../application/commands/handle-callback/handle-callback.command';
|
||||
|
||||
Reference in New Issue
Block a user