diff --git a/src/modules/payments/controllers/payments.controller.ts b/src/modules/payments/controllers/payments.controller.ts index 5899fb8..e0b55ae 100644 --- a/src/modules/payments/controllers/payments.controller.ts +++ b/src/modules/payments/controllers/payments.controller.ts @@ -26,18 +26,6 @@ export class PaymentsController { return this.paymentMethodService.findByRestaurant(restId); } - @Post('public/payments/verify') - @ApiOperation({ summary: 'Verify a payment' }) - @ApiBody({ type: VerifyPaymentDto }) - @ApiNotFoundResponse({ description: 'Payment not found' }) - verifyPayment(@Body() verifyPaymentDto: VerifyPaymentDto) { - return this.paymentsService.verifyPayment( - verifyPaymentDto.authority, - verifyPaymentDto.amount, - verifyPaymentDto.orderId, - ); - } - // @UseGuards(AdminAuthGuard) // @ApiBearerAuth() // @Get('admin/payments') @@ -127,4 +115,12 @@ export class PaymentsController { removeRestaurantPaymentMethod(@Param('paymentMethodId') paymentMethodId: string) { return this.paymentMethodService.remove(paymentMethodId); } + + @Post('public/payments/verify') + @ApiOperation({ summary: 'Verify a payment' }) + @ApiBody({ type: VerifyPaymentDto }) + @ApiNotFoundResponse({ description: 'Payment not found' }) + verifyPayment(@Body() verifyPaymentDto: VerifyPaymentDto) { + return this.paymentsService.verifyPayment(verifyPaymentDto.authority, verifyPaymentDto.orderId); + } } diff --git a/src/modules/payments/dto/verify-payment.dto.ts b/src/modules/payments/dto/verify-payment.dto.ts index d350b4a..06d5ecb 100644 --- a/src/modules/payments/dto/verify-payment.dto.ts +++ b/src/modules/payments/dto/verify-payment.dto.ts @@ -1,16 +1,11 @@ -import { IsNumber, IsOptional, IsString } from 'class-validator'; -import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; +import { IsString } from 'class-validator'; +import { ApiProperty } from '@nestjs/swagger'; export class VerifyPaymentDto { @ApiProperty({ description: 'Payment authority token' }) @IsString() authority: string; - @ApiPropertyOptional({ description: 'Payment amount (optional, will use payment amount if not provided)' }) - @IsOptional() - @IsNumber() - amount?: number; - @ApiProperty({ description: 'Payment order id' }) @IsString() orderId: string; diff --git a/src/modules/payments/services/payments.service.ts b/src/modules/payments/services/payments.service.ts index 7e9f399..f978a91 100644 --- a/src/modules/payments/services/payments.service.ts +++ b/src/modules/payments/services/payments.service.ts @@ -150,7 +150,7 @@ export class PaymentsService { return null; } - async verifyPayment(authority: string, amount: number | undefined, orderId: string): Promise { + async verifyPayment(authority: string, orderId: string): Promise { // Find payment by authority and orderId const payment = await this.em.findOne( Payment, @@ -177,12 +177,12 @@ export class PaymentsService { } // For non-online payments, mark as paid directly - if (paymentMethod.method !== PaymentMethodEnum.Online) { - payment.status = PaymentStatusEnum.Paid; - payment.paidAt = new Date(); - await this.em.persistAndFlush(payment); - return payment; - } + // if (paymentMethod.method !== PaymentMethodEnum.Online) { + // payment.status = PaymentStatusEnum.Paid; + // payment.paidAt = new Date(); + // await this.em.persistAndFlush(payment); + // return payment; + // } // Online payments require gateway verification if (!paymentMethod.merchantId) { @@ -193,13 +193,12 @@ export class PaymentsService { throw new BadRequestException('Payment gateway is required for online payment verification'); } - // Use provided amount or payment amount - const verifyAmount = amount || payment.amount; + // Use payment amount + const verifyAmount = payment.amount; // Handle ZarinPal gateway verification if (payment.gateway === PaymentGatewayEnum.ZarinPal) { try { - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const verifyResponse = await this.verifyZarinPalPayment({ merchantId: paymentMethod.merchantId, amount: verifyAmount, @@ -211,18 +210,13 @@ export class PaymentsService { throw new BadRequestException('Invalid verification response from payment gateway'); } - // Type assertion after type guard - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - const response: IPaymentVerifyResponse = verifyResponse as IPaymentVerifyResponse; + const response = verifyResponse; - // Check verification response code (100 means success for ZarinPal) - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access if (response.code === 100) { // Payment successful payment.status = PaymentStatusEnum.Paid; - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access payment.refId = String(response.refId); - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment + payment.cardPan = response.cardPan; payment.verifyResponse = response as unknown as Record; payment.paidAt = new Date();