diff --git a/src/modules/payment/services/payments.service.ts b/src/modules/payment/services/payments.service.ts index a1bfe07..9504946 100644 --- a/src/modules/payment/services/payments.service.ts +++ b/src/modules/payment/services/payments.service.ts @@ -45,21 +45,23 @@ export class PaymentService { this.frontUrl = this.configService.get('FRONT_URL') || 'https://negareh-console.dev.danakcorp.com/' } - async payInvoice(invoiceId: string, dto: PayOrderDto, adminId?: string): Promise<{ paymentUrl: string | null }> { + async payInvoice(invoiceId: string, dto: PayOrderDto, adminId?: string) + : Promise<{ paymentUrl: string | null, method: PaymentMethodEnum }> { const ctx = await this.loadAndValidateOrder(invoiceId, dto, adminId) switch (dto.method) { case PaymentMethodEnum.Cash: await this.handleCashPayment(ctx); - return { paymentUrl: null }; + return { paymentUrl: null, method: dto.method }; case PaymentMethodEnum.Credit: await this.handleCreditPayment(ctx); - return { paymentUrl: null }; + return { paymentUrl: null, method: dto.method }; case PaymentMethodEnum.Online: - return this.handleOnlinePayment(ctx); + const { paymentUrl } = await this.handleOnlinePayment(ctx); + return { paymentUrl, method: dto.method }; default: throw new BadRequestException(PaymentMessage.UNSUPPORTED_PAYMENT_METHOD); @@ -88,7 +90,7 @@ export class PaymentService { throw new BadRequestException(PaymentMessage.AMOUNT_MUST_BE_GREATER_THAN_ZERO); } - if (new Decimal(amount).gte(invoice.balance)) { + if (new Decimal(amount).gt(invoice.balance)) { throw new BadRequestException(`You cant pay more than ${invoice.balance}`); }