IO-3176 IntelliPay Payment Mapping

Signed-off-by: Allan Carr <allan.carr@thinkimex.com>
This commit is contained in:
Allan Carr
2025-03-25 20:16:34 -07:00
parent 9d1f810af2
commit bbf291e8f3
2 changed files with 27 additions and 19 deletions

View File

@@ -2768,6 +2768,9 @@ exports.GET_BODYSHOP_BY_ID = `
id
md_order_statuses
shopname
imexshopid
intellipay_config
state
}
}
`;

View File

@@ -52,6 +52,7 @@ const getShopCredentials = async (bodyshop) => {
const decodeComment = (comment) => {
try {
return comment ? JSON.parse(Buffer.from(comment, "base64").toString()) : null;
// eslint-disable-next-line no-unused-vars
} catch (error) {
return null; // Handle malformed base64 string gracefully
}
@@ -361,24 +362,18 @@ exports.checkfee = async (req, res) => {
exports.postback = async (req, res) => {
const { body: values } = req;
const decodedComment = decodeComment(values?.comment);
const logResponseMeta = {
bodyshop: {
id: req.body?.bodyshop?.id,
imexshopid: req.body?.bodyshop?.imexshopid,
name: req.body?.bodyshop?.shopname,
state: req.body?.bodyshop?.state
},
iprequest: values,
decodedComment
};
const ipMapping = req.body?.bodyshop?.intellipay_config?.payment_map;
logger.log("intellipay-postback-received", "DEBUG", req.user?.email, null, logResponseMeta);
logger.log("intellipay-postback-received", "DEBUG", "api", null, logResponseMeta);
try {
if ((!values.invoice || values.invoice === "") && !decodedComment) {
//invoice is specified through the pay link. Comment by IO.
logger.log("intellipay-postback-ignored", "DEBUG", req.user?.email, null, {
logger.log("intellipay-postback-ignored", "DEBUG", "api", null, {
message: "No invoice or comment provided",
...logResponseMeta
});
@@ -391,7 +386,7 @@ exports.postback = async (req, res) => {
//This has been triggered by IO and may have multiple jobs.
const parsedComment = decodedComment;
logger.log("intellipay-postback-parsed-comment", "DEBUG", req.user?.email, null, {
logger.log("intellipay-postback-parsed-comment", "DEBUG", "api", null, {
parsedComment,
...logResponseMeta
});
@@ -405,8 +400,12 @@ exports.postback = async (req, res) => {
const jobs = await gqlClient.request(queries.GET_JOBS_BY_PKS, {
ids: partialPayments.map((p) => p.jobid)
});
const bodyshop = await gqlClient.request(queries.GET_BODYSHOP_BY_ID, {
id: jobs.jobs[0].shopid
});
const ipMapping = bodyshop.bodyshops_by_pk.intellipay_config?.payment_map;
logger.log("intellipay-postback-jobs-fetched", "DEBUG", req.user?.email, null, {
logger.log("intellipay-postback-jobs-fetched", "DEBUG", "api", null, {
jobs,
parsedComment,
...logResponseMeta
@@ -424,7 +423,7 @@ exports.postback = async (req, res) => {
payment_responses: {
data: {
amount: values.total,
bodyshopid: jobs.jobs[0].shopid,
bodyshopid: bodyshop.bodyshops_by_pk.id,
jobid: p.jobid,
declinereason: "Approved",
ext_paymentid: values.paymentid,
@@ -435,7 +434,7 @@ exports.postback = async (req, res) => {
}))
});
logger.log("intellipay-postback-payment-success", "DEBUG", req.user?.email, null, {
logger.log("intellipay-postback-payment-success", "DEBUG", "api", null, {
paymentResult,
jobs,
parsedComment,
@@ -458,7 +457,7 @@ exports.postback = async (req, res) => {
.join("<br/>")
})
}).catch((error) => {
logger.log("intellipay-postback-email-error", "ERROR", req.user?.email, null, {
logger.log("intellipay-postback-email-error", "ERROR", "api", null, {
message: error.message,
jobs,
paymentResult,
@@ -472,8 +471,14 @@ exports.postback = async (req, res) => {
id: values.invoice
});
logger.log("intellipay-postback-invoice-job-fetched", "DEBUG", req.user?.email, null, {
const bodyshop = await gqlClient.request(queries.GET_BODYSHOP_BY_ID, {
id: job.jobs_by_pk.shopid
});
const ipMapping = bodyshop.bodyshops_by_pk.intellipay_config?.payment_map;
logger.log("intellipay-postback-invoice-job-fetched", "DEBUG", "api", null, {
job,
bodyshop,
...logResponseMeta
});
@@ -488,7 +493,7 @@ exports.postback = async (req, res) => {
}
});
logger.log("intellipay-postback-invoice-payment-success", "DEBUG", req.user?.email, null, {
logger.log("intellipay-postback-invoice-payment-success", "DEBUG", "api", null, {
paymentResult,
...logResponseMeta
});
@@ -496,7 +501,7 @@ exports.postback = async (req, res) => {
const responseResults = await gqlClient.request(queries.INSERT_PAYMENT_RESPONSE, {
paymentResponse: {
amount: values.total,
bodyshopid: job.jobs_by_pk.shopid,
bodyshopid: bodyshop.bodyshops_by_pk.id,
paymentid: paymentResult.id,
jobid: values.invoice,
declinereason: "Approved",
@@ -506,14 +511,14 @@ exports.postback = async (req, res) => {
}
});
logger.log("intellipay-postback-invoice-response-success", "DEBUG", req.user?.email, null, {
logger.log("intellipay-postback-invoice-response-success", "DEBUG", "api", null, {
responseResults,
...logResponseMeta
});
res.sendStatus(200);
}
} catch (error) {
logger.log("intellipay-postback-error", "ERROR", req.user?.email, null, {
logger.log("intellipay-postback-error", "ERROR", "api", null, {
message: error?.message,
...logResponseMeta
});