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