fix : sep gateway
This commit is contained in:
@@ -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<SepRequestPaymentResponse>(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 };
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user