pay bug
This commit is contained in:
@@ -45,21 +45,23 @@ export class PaymentService {
|
|||||||
this.frontUrl = this.configService.get<string>('FRONT_URL') || 'https://negareh-console.dev.danakcorp.com/'
|
this.frontUrl = this.configService.get<string>('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)
|
const ctx = await this.loadAndValidateOrder(invoiceId, dto, adminId)
|
||||||
|
|
||||||
switch (dto.method) {
|
switch (dto.method) {
|
||||||
case PaymentMethodEnum.Cash:
|
case PaymentMethodEnum.Cash:
|
||||||
await this.handleCashPayment(ctx);
|
await this.handleCashPayment(ctx);
|
||||||
return { paymentUrl: null };
|
return { paymentUrl: null, method: dto.method };
|
||||||
|
|
||||||
case PaymentMethodEnum.Credit:
|
case PaymentMethodEnum.Credit:
|
||||||
await this.handleCreditPayment(ctx);
|
await this.handleCreditPayment(ctx);
|
||||||
return { paymentUrl: null };
|
return { paymentUrl: null, method: dto.method };
|
||||||
|
|
||||||
case PaymentMethodEnum.Online:
|
case PaymentMethodEnum.Online:
|
||||||
return this.handleOnlinePayment(ctx);
|
const { paymentUrl } = await this.handleOnlinePayment(ctx);
|
||||||
|
return { paymentUrl, method: dto.method };
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new BadRequestException(PaymentMessage.UNSUPPORTED_PAYMENT_METHOD);
|
throw new BadRequestException(PaymentMessage.UNSUPPORTED_PAYMENT_METHOD);
|
||||||
@@ -88,7 +90,7 @@ export class PaymentService {
|
|||||||
throw new BadRequestException(PaymentMessage.AMOUNT_MUST_BE_GREATER_THAN_ZERO);
|
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}`);
|
throw new BadRequestException(`You cant pay more than ${invoice.balance}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user