diff --git a/src/modules/IPG/gateways/sep.ts b/src/modules/IPG/gateways/sep.ts index 7199846..49585e8 100644 --- a/src/modules/IPG/gateways/sep.ts +++ b/src/modules/IPG/gateways/sep.ts @@ -51,8 +51,7 @@ class SepGateway implements IGateway { RedirectUrl: `${this.callBackURL}${callBackPath}`, ResNum: Date.now().toString(), CellNumber: _mobile, - // GetMethod:true - }; + }; const response = await axios.post(requesturl, purchaseData, { headers: this.requestHeader }); const data = response.data; @@ -85,7 +84,6 @@ class SepGateway implements IGateway { if (!this.gatewayApiUrl || !this.terminalNumber) { throw new InternalError(["SEP gateway is not configured"]); } - // https://sep.shaparak.ir/verifyTxnRandomSessionkey/ipg/VerifyTransaction try { const verifyData = { RefNum: data.refNum, TerminalNumber: this.terminalNumber }; diff --git a/src/modules/payment/payment.controller.ts b/src/modules/payment/payment.controller.ts index 2ce243a..b828277 100644 --- a/src/modules/payment/payment.controller.ts +++ b/src/modules/payment/payment.controller.ts @@ -117,10 +117,10 @@ class PaymentController extends BaseController { @response() res: Response, @requestBody() dto: VerifyOnlinePaymentDTO, ) { - console.log("post verify cart checkout", dto); - const verifyCallbackData = { + const verifyCallbackData = { status: dto.Status, refNum: dto.RefNum, + authority: dto.Token, }; const data = await this.paymentService.verifyCartPayment(gateway as GatewayProvider, verifyCallbackData); const html = verifyPaymentTemplate(data); diff --git a/src/modules/payment/providers/payment.service.ts b/src/modules/payment/providers/payment.service.ts index b2a1227..4b4c874 100644 --- a/src/modules/payment/providers/payment.service.ts +++ b/src/modules/payment/providers/payment.service.ts @@ -160,14 +160,11 @@ class PaymentService { //################################################################## //################################################################## //verify callback of cart payment - async verifyCartPayment(gateway: GatewayProvider, verifyCallbackData: { status: string; authority?: string; refNum?: string }) { + async verifyCartPayment(gateway: GatewayProvider, verifyCallbackData: { status: string; authority: string; refNum?: string }) { const { status, authority, refNum } = verifyCallbackData; const session = await startSession(); session.startTransaction(); try { - // For SEP gateway, refNum is used as authority in database - const authorityToFind = gateway === GatewayProvider.SEP ? refNum : authority; - if (!authorityToFind) throw new BadRequestError(PaymentMessage.PaymentNotFound); // For SEP gateway, check if refNum has already been used as transaction_id if (gateway === GatewayProvider.SEP && refNum) { @@ -175,7 +172,7 @@ class PaymentService { if (existingPayment) throw new BadRequestError(PaymentMessage.RefNumIsAlreadyUsed); } - const paymentData = await this.cartPaymentRepo.model.findOne({ authority: authorityToFind }).session(session); + const paymentData = await this.cartPaymentRepo.model.findOne({ authority }).session(session); if (!paymentData) throw new BadRequestError(PaymentMessage.PaymentNotFound); @@ -200,6 +197,8 @@ class PaymentService { : { authority, amount: paymentData.totalPrice }; const data = await this.paymentGateway.verifyPayment(gateway, verifyData); + console.log("verify payment data**", data); + if (data.code === 100 || data.code === 101) { await this.handleSellerNotify(order._id, user, session); // For SEP gateway, save refNum as transaction_id; for Zarinpal, save ref_id