Merge branch 'master' into feature/america
This commit is contained in:
@@ -643,6 +643,7 @@ async function InsertAccountPostingData(socket) {
|
||||
|
||||
wips.push(item);
|
||||
});
|
||||
socket.transWips = wips;
|
||||
|
||||
const { data: AccountPostingChange } = await axios.post(
|
||||
PBS_ENDPOINTS.AccountingPostingChange,
|
||||
@@ -697,6 +698,7 @@ async function MarkJobExported(socket, jobid) {
|
||||
jobid: jobid,
|
||||
successful: true,
|
||||
useremail: socket.user.email,
|
||||
metadata: socket.transWips,
|
||||
},
|
||||
bill: {
|
||||
exported: true,
|
||||
|
||||
@@ -992,6 +992,7 @@ exports.GET_JOB_BY_PK = `query GET_JOB_BY_PK($id: uuid!) {
|
||||
ins_ph1
|
||||
est_co_nm
|
||||
est_ct_fn
|
||||
shopid
|
||||
est_ct_ln
|
||||
vehicle{
|
||||
id
|
||||
|
||||
@@ -4,6 +4,9 @@ const queries = require("../graphql-client/queries");
|
||||
const Dinero = require("dinero.js");
|
||||
const qs = require("query-string");
|
||||
const axios = require("axios");
|
||||
const moment = require("moment");
|
||||
const logger = require("../utils/logger");
|
||||
|
||||
require("dotenv").config({
|
||||
path: path.resolve(
|
||||
process.cwd(),
|
||||
@@ -12,7 +15,15 @@ require("dotenv").config({
|
||||
});
|
||||
|
||||
const domain = process.env.NODE_ENV ? "secure" : "test";
|
||||
const SecretsManager = require("./aws-secrets-manager");
|
||||
|
||||
const {
|
||||
SecretsManagerClient,
|
||||
GetSecretValueCommand,
|
||||
} = require("@aws-sdk/client-secrets-manager");
|
||||
|
||||
const client = new SecretsManagerClient({
|
||||
region: "ca-central-1",
|
||||
});
|
||||
|
||||
const gqlClient = require("../graphql-client/graphql-client").client;
|
||||
|
||||
@@ -20,38 +31,55 @@ const getShopCredentials = async (bodyshop) => {
|
||||
// Development only
|
||||
if (process.env.NODE_ENV === undefined) {
|
||||
return {
|
||||
merchantkey: process.env.DEV_INTELLIPAY_MERCHANTKEY,
|
||||
apikey: process.env.DEV_INTELLIPAY_APIKEY,
|
||||
merchantkey: process.env.INTELLIPAY_MERCHANTKEY,
|
||||
apikey: process.env.INTELLIPAY_APIKEY,
|
||||
};
|
||||
}
|
||||
|
||||
// Production code
|
||||
if (bodyshop?.imexshopid) {
|
||||
const secret = await SecretsManager.getSecret(
|
||||
`intellipay-credentials-${bodyshop.imexshopid}`,
|
||||
process.env.REGION
|
||||
);
|
||||
|
||||
return JSON.parse(secret);
|
||||
try {
|
||||
const secret = await client.send(
|
||||
new GetSecretValueCommand({
|
||||
SecretId: `intellipay-credentials-${bodyshop.imexshopid}`,
|
||||
VersionStage: "AWSCURRENT", // VersionStage defaults to AWSCURRENT if unspecified
|
||||
})
|
||||
);
|
||||
return JSON.parse(secret.SecretString);
|
||||
} catch (error) {
|
||||
return {
|
||||
error: error.message,
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.lightbox_credentials = async (req, res) => {
|
||||
logger.log(
|
||||
"intellipay-lightbox-credentials",
|
||||
"DEBUG",
|
||||
req.user?.email,
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
const shopCredentials = await getShopCredentials(req.body.bodyshop);
|
||||
|
||||
if (shopCredentials.error) {
|
||||
res.json(shopCredentials);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const options = {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/x-www-form-urlencoded" },
|
||||
//TODO: Move these to environment variables/database.
|
||||
data: qs.stringify({
|
||||
...shopCredentials,
|
||||
operatingenv:
|
||||
process.env.NODE_ENV === undefined
|
||||
? process.env.NODE_ENV
|
||||
: "businessattended",
|
||||
operatingenv: "businessattended",
|
||||
}),
|
||||
url: `https://${domain}.cpteller.com/api/custapi.cfc?method=autoterminal`,
|
||||
url: `https://${domain}.cpteller.com/api/custapi.cfc?method=autoterminal${
|
||||
req.body.refresh ? "_refresh" : ""
|
||||
}`, //autoterminal_refresh
|
||||
};
|
||||
|
||||
const response = await axios(options);
|
||||
@@ -59,11 +87,20 @@ exports.lightbox_credentials = async (req, res) => {
|
||||
res.send(response.data);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
logger.log(
|
||||
"intellipay-lightbox-credentials-error",
|
||||
"ERROR",
|
||||
req.user?.email,
|
||||
null,
|
||||
{ error: JSON.stringify(error) }
|
||||
);
|
||||
res.json({ error });
|
||||
}
|
||||
};
|
||||
|
||||
exports.payment_refund = async (req, res) => {
|
||||
logger.log("intellipay-refund", "DEBUG", req.user?.email, null, null);
|
||||
|
||||
const shopCredentials = await getShopCredentials(req.body.bodyshop);
|
||||
|
||||
try {
|
||||
@@ -85,11 +122,15 @@ exports.payment_refund = async (req, res) => {
|
||||
res.send(response.data);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
logger.log("intellipay-refund-error", "ERROR", req.user?.email, null, {
|
||||
error: JSON.stringify(error),
|
||||
});
|
||||
res.json({ error });
|
||||
}
|
||||
};
|
||||
|
||||
exports.generate_payment_url = async (req, res) => {
|
||||
logger.log("intellipay-payment-url", "DEBUG", req.user?.email, null, null);
|
||||
const shopCredentials = await getShopCredentials(req.body.bodyshop);
|
||||
try {
|
||||
const options = {
|
||||
@@ -100,6 +141,7 @@ exports.generate_payment_url = async (req, res) => {
|
||||
...shopCredentials,
|
||||
...req.body,
|
||||
createshorturl: true,
|
||||
//The postback URL is set at the CP teller global terminal settings page.
|
||||
}),
|
||||
url: `https://${domain}.cpteller.com/api/custapi.cfc?method=generate_lightbox_url`,
|
||||
};
|
||||
@@ -109,76 +151,58 @@ exports.generate_payment_url = async (req, res) => {
|
||||
res.send(response.data);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
logger.log("intellipay-payment-url-error", "ERROR", req.user?.email, null, {
|
||||
error: JSON.stringify(error),
|
||||
});
|
||||
res.json({ error });
|
||||
}
|
||||
};
|
||||
|
||||
exports.postback = async (req, res) => {
|
||||
console.log("postback as", req.body);
|
||||
|
||||
logger.log("intellipay-postback", "ERROR", req.user?.email, null, req.body);
|
||||
const { body: values } = req;
|
||||
|
||||
if (!values.invoice) {
|
||||
res.sendStatus(200);
|
||||
return;
|
||||
}
|
||||
// TODO query job by account name
|
||||
const job = await gqlClient.request(queries.GET_JOB_BY_RO_NUMBER, {
|
||||
ro_number: values.account,
|
||||
const job = await gqlClient.request(queries.GET_JOB_BY_PK, {
|
||||
id: values.invoice,
|
||||
});
|
||||
// TODO add mutation to database
|
||||
|
||||
const paymentResult = await gqlClient.request(queries.INSERT_NEW_PAYMENT, {
|
||||
paymentInput: {
|
||||
amount: values.total,
|
||||
transactionid: `C00 ${values.authcode}`,
|
||||
payer: "Customer",
|
||||
type: values.cardtype,
|
||||
jobid: job.jobs[0].id,
|
||||
date: moment(Date.now()),
|
||||
},
|
||||
});
|
||||
try {
|
||||
const paymentResult = await gqlClient.request(queries.INSERT_NEW_PAYMENT, {
|
||||
paymentInput: {
|
||||
amount: values.total,
|
||||
transactionid: `C00 ${values.authcode}`,
|
||||
payer: "Customer",
|
||||
type: values.cardtype,
|
||||
jobid: values.invoice,
|
||||
date: moment(Date.now()),
|
||||
},
|
||||
});
|
||||
|
||||
await gqlClient.request(queries.INSERT_PAYMENT_RESPONSE, {
|
||||
paymentResponse: {
|
||||
amount: values.total,
|
||||
bodyshopid: job.jobs[0].bodyshop.id,
|
||||
paymentid: paymentResult.id,
|
||||
jobid: job.jobs[0].id,
|
||||
declinereason: "Approved",
|
||||
ext_paymentid: values.paymentid,
|
||||
successful: true,
|
||||
response: values,
|
||||
},
|
||||
});
|
||||
await gqlClient.request(queries.INSERT_PAYMENT_RESPONSE, {
|
||||
paymentResponse: {
|
||||
amount: values.total,
|
||||
bodyshopid: job.jobs_by_pk.shopid,
|
||||
paymentid: paymentResult.id,
|
||||
jobid: values.invoice,
|
||||
declinereason: "Approved",
|
||||
ext_paymentid: values.paymentid,
|
||||
successful: true,
|
||||
response: values,
|
||||
},
|
||||
});
|
||||
|
||||
res.send({ message: "Postback Successful" });
|
||||
res.send({ message: "Postback Successful" });
|
||||
} catch (error) {
|
||||
logger.log("intellipay-postback-error", "ERROR", req.user?.email, null, {
|
||||
error: JSON.stringify(error),
|
||||
body: req.body,
|
||||
});
|
||||
res.status(400).json({ succesful: false, error: error.message });
|
||||
}
|
||||
};
|
||||
|
||||
`{
|
||||
ipaddress: '136.158.34.242',
|
||||
firstname: 'JC',
|
||||
notes: '',
|
||||
city: '',
|
||||
fee: ' 0.00',
|
||||
origin: 'OneLink',
|
||||
total: '5061.36',
|
||||
avsdata: 'N',
|
||||
arglist: '""',
|
||||
state: ' ',
|
||||
cardtype: 'Visa',
|
||||
department: '',
|
||||
email: '',
|
||||
timestamp: "{ts '2023-03-23 09:52:23'}",
|
||||
op: 'Kh6Pa6AT9keg',
|
||||
amount: '5061.36',
|
||||
method: 'CARD',
|
||||
address2: '',
|
||||
address1: '',
|
||||
lastname: 'Tolentino',
|
||||
zipcode: '1742 ',
|
||||
authcode: '367885',
|
||||
phone: '',
|
||||
merchantid: '7114',
|
||||
paymentid: '24205435',
|
||||
customerid: '19610104',
|
||||
comment: '',
|
||||
invoice: '',
|
||||
account: 'QBD241'
|
||||
}`;
|
||||
|
||||
Reference in New Issue
Block a user