IO-3176 IntelliPay Payment Mapping
Signed-off-by: Allan Carr <allan.carr@thinkimex.com>
This commit is contained in:
@@ -2768,6 +2768,9 @@ exports.GET_BODYSHOP_BY_ID = `
|
|||||||
id
|
id
|
||||||
md_order_statuses
|
md_order_statuses
|
||||||
shopname
|
shopname
|
||||||
|
imexshopid
|
||||||
|
intellipay_config
|
||||||
|
state
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ const getShopCredentials = async (bodyshop) => {
|
|||||||
const decodeComment = (comment) => {
|
const decodeComment = (comment) => {
|
||||||
try {
|
try {
|
||||||
return comment ? JSON.parse(Buffer.from(comment, "base64").toString()) : null;
|
return comment ? JSON.parse(Buffer.from(comment, "base64").toString()) : null;
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return null; // Handle malformed base64 string gracefully
|
return null; // Handle malformed base64 string gracefully
|
||||||
}
|
}
|
||||||
@@ -361,24 +362,18 @@ exports.checkfee = async (req, res) => {
|
|||||||
exports.postback = async (req, res) => {
|
exports.postback = async (req, res) => {
|
||||||
const { body: values } = req;
|
const { body: values } = req;
|
||||||
const decodedComment = decodeComment(values?.comment);
|
const decodedComment = decodeComment(values?.comment);
|
||||||
|
|
||||||
const logResponseMeta = {
|
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,
|
iprequest: values,
|
||||||
decodedComment
|
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 {
|
try {
|
||||||
if ((!values.invoice || values.invoice === "") && !decodedComment) {
|
if ((!values.invoice || values.invoice === "") && !decodedComment) {
|
||||||
//invoice is specified through the pay link. Comment by IO.
|
//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",
|
message: "No invoice or comment provided",
|
||||||
...logResponseMeta
|
...logResponseMeta
|
||||||
});
|
});
|
||||||
@@ -391,7 +386,7 @@ exports.postback = async (req, res) => {
|
|||||||
//This has been triggered by IO and may have multiple jobs.
|
//This has been triggered by IO and may have multiple jobs.
|
||||||
const parsedComment = decodedComment;
|
const parsedComment = decodedComment;
|
||||||
|
|
||||||
logger.log("intellipay-postback-parsed-comment", "DEBUG", req.user?.email, null, {
|
logger.log("intellipay-postback-parsed-comment", "DEBUG", "api", null, {
|
||||||
parsedComment,
|
parsedComment,
|
||||||
...logResponseMeta
|
...logResponseMeta
|
||||||
});
|
});
|
||||||
@@ -405,8 +400,12 @@ exports.postback = async (req, res) => {
|
|||||||
const jobs = await gqlClient.request(queries.GET_JOBS_BY_PKS, {
|
const jobs = await gqlClient.request(queries.GET_JOBS_BY_PKS, {
|
||||||
ids: partialPayments.map((p) => p.jobid)
|
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,
|
jobs,
|
||||||
parsedComment,
|
parsedComment,
|
||||||
...logResponseMeta
|
...logResponseMeta
|
||||||
@@ -424,7 +423,7 @@ exports.postback = async (req, res) => {
|
|||||||
payment_responses: {
|
payment_responses: {
|
||||||
data: {
|
data: {
|
||||||
amount: values.total,
|
amount: values.total,
|
||||||
bodyshopid: jobs.jobs[0].shopid,
|
bodyshopid: bodyshop.bodyshops_by_pk.id,
|
||||||
jobid: p.jobid,
|
jobid: p.jobid,
|
||||||
declinereason: "Approved",
|
declinereason: "Approved",
|
||||||
ext_paymentid: values.paymentid,
|
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,
|
paymentResult,
|
||||||
jobs,
|
jobs,
|
||||||
parsedComment,
|
parsedComment,
|
||||||
@@ -458,7 +457,7 @@ exports.postback = async (req, res) => {
|
|||||||
.join("<br/>")
|
.join("<br/>")
|
||||||
})
|
})
|
||||||
}).catch((error) => {
|
}).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,
|
message: error.message,
|
||||||
jobs,
|
jobs,
|
||||||
paymentResult,
|
paymentResult,
|
||||||
@@ -472,8 +471,14 @@ exports.postback = async (req, res) => {
|
|||||||
id: values.invoice
|
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,
|
job,
|
||||||
|
bodyshop,
|
||||||
...logResponseMeta
|
...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,
|
paymentResult,
|
||||||
...logResponseMeta
|
...logResponseMeta
|
||||||
});
|
});
|
||||||
@@ -496,7 +501,7 @@ exports.postback = async (req, res) => {
|
|||||||
const responseResults = await gqlClient.request(queries.INSERT_PAYMENT_RESPONSE, {
|
const responseResults = await gqlClient.request(queries.INSERT_PAYMENT_RESPONSE, {
|
||||||
paymentResponse: {
|
paymentResponse: {
|
||||||
amount: values.total,
|
amount: values.total,
|
||||||
bodyshopid: job.jobs_by_pk.shopid,
|
bodyshopid: bodyshop.bodyshops_by_pk.id,
|
||||||
paymentid: paymentResult.id,
|
paymentid: paymentResult.id,
|
||||||
jobid: values.invoice,
|
jobid: values.invoice,
|
||||||
declinereason: "Approved",
|
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,
|
responseResults,
|
||||||
...logResponseMeta
|
...logResponseMeta
|
||||||
});
|
});
|
||||||
res.sendStatus(200);
|
res.sendStatus(200);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.log("intellipay-postback-error", "ERROR", req.user?.email, null, {
|
logger.log("intellipay-postback-error", "ERROR", "api", null, {
|
||||||
message: error?.message,
|
message: error?.message,
|
||||||
...logResponseMeta
|
...logResponseMeta
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user