verify payment
This commit is contained in:
@@ -124,22 +124,13 @@ export class PaymentsController {
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@Permissions(Permission.MANAGE_PAYMENTS)
|
||||
@ApiBearerAuth()
|
||||
@Post('admin/payments/verify-cash-method/:paymentId')
|
||||
@ApiOperation({ summary: 'Verify cash payment ' })
|
||||
@Post('admin/payments/verify/:paymentId')
|
||||
@ApiOperation({ summary: 'Verify cash/creditcard payment ' })
|
||||
@ApiParam({ name: 'paymentId', type: 'string', description: 'Payment ID' })
|
||||
verifyCashPayment(@Param('paymentId') paymentId: string) {
|
||||
return this.paymentsService.verifyCashPayment(paymentId);
|
||||
return this.paymentsService.verifyCashAnCreditPayment(paymentId);
|
||||
}
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@Permissions(Permission.MANAGE_PAYMENTS)
|
||||
@ApiBearerAuth()
|
||||
@Post('admin/payments/verify-credit-card-method/:paymentId')
|
||||
@ApiOperation({ summary: 'Verify credit card payment' })
|
||||
@ApiParam({ name: 'paymentId', type: 'string', description: 'Payment ID' })
|
||||
verifyCreditCardPayment(@Param('paymentId') paymentId: string) {
|
||||
return this.paymentsService.verifyCreditCardPayment(paymentId);
|
||||
}
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@Permissions(Permission.VIEW_REPORTS)
|
||||
|
||||
@@ -257,17 +257,14 @@ export class PaymentsService {
|
||||
);
|
||||
}
|
||||
|
||||
async verifyCashPayment(id: string): Promise<Payment> {
|
||||
return this.verifyManualPayment(id, PaymentMethodEnum.Cash, PaymentMessage.PAYMENT_METHOD_NOT_CASH);
|
||||
async verifyCashAnCreditPayment(id: string): Promise<Payment> {
|
||||
return this.verifyManualPayment(id, [PaymentMethodEnum.Cash, PaymentMethodEnum.CreditCard], PaymentMessage.PAYMENT_METHOD_NOT_CASH);
|
||||
}
|
||||
|
||||
async verifyCreditCardPayment(id: string): Promise<Payment> {
|
||||
return this.verifyManualPayment(id, PaymentMethodEnum.CreditCard, PaymentMessage.PAYMENT_METHOD_NOT_CREDIT_CARD);
|
||||
}
|
||||
|
||||
private async verifyManualPayment(
|
||||
id: string,
|
||||
expectedMethod: PaymentMethodEnum,
|
||||
expectedMethods: PaymentMethodEnum[],
|
||||
wrongMethodMessage: PaymentMessage,
|
||||
): Promise<Payment> {
|
||||
const payment = await this.em.transactional(async em => {
|
||||
@@ -275,7 +272,7 @@ export class PaymentsService {
|
||||
if (!payment) {
|
||||
throw new NotFoundException(PaymentMessage.PAYMENT_NOT_FOUND);
|
||||
}
|
||||
if (payment.method !== expectedMethod) {
|
||||
if (!expectedMethods.includes(payment.method)) {
|
||||
throw new BadRequestException(wrongMethodMessage);
|
||||
}
|
||||
if (payment.status === PaymentStatusEnum.Paid) {
|
||||
|
||||
Reference in New Issue
Block a user