fix: handle cancel payment
This commit is contained in:
@@ -6,6 +6,7 @@ CONNECTION_STRING=
|
||||
MERCHANT_ID=250ae134-635f-4728-8415-ee9a984616e8
|
||||
IPG_TYPE=sandbox
|
||||
SITE_URL=https://dlearn-api.run.danakcorp.com/payment
|
||||
ACADEMY_URL=http://academy.shinan.ir
|
||||
EMAIL_HOST=
|
||||
EMAIL_PORT=
|
||||
EMAIL_USER=
|
||||
|
||||
@@ -6,6 +6,7 @@ CONNECTION_STRING=
|
||||
MERCHANT_ID=250ae134-635f-4728-8415-ee9a984616e8
|
||||
IPG_TYPE=sandbox
|
||||
SITE_URL=https://dlearn-api.run.danakcorp.com/payment
|
||||
ACADEMY_URL=http://academy.shinan.ir
|
||||
EMAIL_HOST=
|
||||
EMAIL_PORT=
|
||||
EMAIL_USER=
|
||||
|
||||
@@ -20,7 +20,7 @@ export class ZarinPalGateway {
|
||||
amount,
|
||||
callback_url: `${this.callbackURL}/${callbackPath}`,
|
||||
description: "خرید دوره",
|
||||
currency: "IRR" as const,
|
||||
currency: "IRT" as const,
|
||||
metadata: { userId },
|
||||
}
|
||||
|
||||
@@ -40,7 +40,6 @@ export class ZarinPalGateway {
|
||||
}
|
||||
|
||||
async verifyPayment(authority: string, amount: number) {
|
||||
try {
|
||||
const verifyData = {
|
||||
merchant_id: this.merchantID,
|
||||
amount,
|
||||
@@ -51,9 +50,5 @@ export class ZarinPalGateway {
|
||||
const { data } = response.data;
|
||||
|
||||
return data;
|
||||
} catch (error) {
|
||||
this.logger.error("error in payment verification", error);
|
||||
throw new InternalServerErrorException("error in payment verification");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
HttpStatus,
|
||||
Post,
|
||||
Query,
|
||||
Res,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import {
|
||||
@@ -15,6 +16,7 @@ import {
|
||||
ApiQuery,
|
||||
} from '@nestjs/swagger';
|
||||
import { CurrentUser } from '../../decorators/currentUser.decorator';
|
||||
import { Response } from 'express';
|
||||
import { AuthGuard } from '../../auth/auth.guard';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { Roles } from '../../decorators/role.decorators';
|
||||
@@ -58,9 +60,14 @@ export class PaymentController {
|
||||
description: 'get status',
|
||||
})
|
||||
@Get('/verify/Zarinpal/cart')
|
||||
async verifyPayment(@Query('Authority') authority: string, @Query('Status') status: string) {
|
||||
console.log({ authorityInController: authority, status })
|
||||
return this.paymentService.verifyPayment(authority, status);
|
||||
async verifyPayment(@Query('Authority') authority: string, @Query('Status') status: string,@Res() res: Response) {
|
||||
if (status === 'NOK') {
|
||||
return res.redirect(`${process.env.ACADEMY_URL}/payment/verify/Zarinpal/cart?Authority=${authority}&Status=${status}`)
|
||||
}
|
||||
const result = await this.paymentService.verifyPayment(authority, status);
|
||||
console.log({resultincontroller:result})
|
||||
return res.redirect(`${process.env.ACADEMY_URL}/payment/verify/Zarinpal/cart?Authority=${authority}&Status=${status}`)
|
||||
|
||||
}
|
||||
|
||||
@ApiOperation({
|
||||
|
||||
@@ -115,13 +115,12 @@ export class PaymentService {
|
||||
|
||||
|
||||
async verifyPayment(authority: string, status: string) {
|
||||
console.log({ authorityInService: authority })
|
||||
const paymentData = await this.paymentDataAccess.getPaymentByAuthority(authority);
|
||||
console.log({ paymentData })
|
||||
if (!paymentData) {
|
||||
throw new Error("payment not found");
|
||||
}
|
||||
const verifyData = await this.paymentGateway.verifyPayment({ authority, amount: paymentData.amount });
|
||||
console.log({verifyData})
|
||||
if (verifyData.code === 100 || verifyData.code === 101) {
|
||||
await this.purchaseDataAccess.createPurchase(paymentData.userId.toString(), paymentData.courseId.toString(), paymentData._id.toString());
|
||||
paymentData.paymentStatus = PaymentStatus.Completed;
|
||||
|
||||
Reference in New Issue
Block a user