feature/IO-2769-Job-Totals-Testing - non-related
This commit is contained in:
@@ -2841,6 +2841,15 @@ query GET_JOBID_BY_MERCHANTID_RONUMBER($merchantID: String!, $roNumber: String!)
|
|||||||
bodyshop {
|
bodyshop {
|
||||||
id
|
id
|
||||||
intellipay_config
|
intellipay_config
|
||||||
|
email
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
|
exports.GET_BODYSHOP_BY_MERCHANT_ID = `
|
||||||
|
query GET_BODYSHOP_BY_MERCHANTID($merchantID: String!) {
|
||||||
|
bodyshops(where: {intellipay_merchant_id: {_eq: $merchantID}}) {
|
||||||
|
id
|
||||||
|
email
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
|||||||
@@ -2,8 +2,11 @@ const handlePaymentValidationError = require("./handlePaymentValidationError");
|
|||||||
const {
|
const {
|
||||||
GET_JOBID_BY_MERCHANTID_RONUMBER,
|
GET_JOBID_BY_MERCHANTID_RONUMBER,
|
||||||
INSERT_PAYMENT_RESPONSE,
|
INSERT_PAYMENT_RESPONSE,
|
||||||
INSERT_NEW_PAYMENT
|
INSERT_NEW_PAYMENT,
|
||||||
|
GET_BODYSHOP_BY_MERCHANT_ID
|
||||||
} = require("../../graphql-client/queries");
|
} = require("../../graphql-client/queries");
|
||||||
|
|
||||||
|
const { sendServerEmail } = require("../../email/sendemail");
|
||||||
const getPaymentType = require("./getPaymentType");
|
const getPaymentType = require("./getPaymentType");
|
||||||
const moment = require("moment");
|
const moment = require("moment");
|
||||||
|
|
||||||
@@ -36,7 +39,32 @@ const handleInvoiceBasedPayment = async (values, logger, logMeta, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!result?.jobs?.length) {
|
if (!result?.jobs?.length) {
|
||||||
return handlePaymentValidationError(res, logger, "intellipay-postback-job-not-found", "Job not found", logMeta);
|
// Fetch bodyshop data
|
||||||
|
const bodyshop = await gqlClient.request(GET_BODYSHOP_BY_MERCHANT_ID, {
|
||||||
|
merchantID: values.merchantid
|
||||||
|
});
|
||||||
|
|
||||||
|
if (bodyshop?.bodyshops?.[0]) {
|
||||||
|
// Note: changed bodyshops to bodyshop to match query name
|
||||||
|
const email = bodyshop.bodyshops[0].email;
|
||||||
|
await sendServerEmail({
|
||||||
|
subject: `Failed to Insert Payment`,
|
||||||
|
text: `The system has attempted to insert a payment that was generated by your merchant terminal but could not find an associated invoice. Transaction details are below. Please input this payment to your system manually.\n\n${Object.keys(
|
||||||
|
values
|
||||||
|
)
|
||||||
|
.map((key) => `${key}: ${values[key]}`)
|
||||||
|
.join("\n")}`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return handlePaymentValidationError(
|
||||||
|
res,
|
||||||
|
logger,
|
||||||
|
"intellipay-postback-job-not-found",
|
||||||
|
"Job not found",
|
||||||
|
logMeta,
|
||||||
|
200
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const job = result.jobs[0];
|
const job = result.jobs[0];
|
||||||
|
|||||||
@@ -5,14 +5,15 @@
|
|||||||
* @param logCode
|
* @param logCode
|
||||||
* @param message
|
* @param message
|
||||||
* @param logMeta
|
* @param logMeta
|
||||||
|
* @param returnCode
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
const handlePaymentValidationError = (res, logger, logCode, message, logMeta) => {
|
const handlePaymentValidationError = (res, logger, logCode, message, logMeta, returnCode) => {
|
||||||
logger.log(logCode, "ERROR", "api", null, {
|
logger.log(logCode, "ERROR", "api", null, {
|
||||||
message,
|
message,
|
||||||
...logMeta
|
...logMeta
|
||||||
});
|
});
|
||||||
return res.status(400).send(`Bad Request: ${message}`);
|
return res.status(returnCode || 400).send(`Bad Request: ${message}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = handlePaymentValidationError;
|
module.exports = handlePaymentValidationError;
|
||||||
|
|||||||
Reference in New Issue
Block a user