added the logic for aws secrets manager

This commit is contained in:
swtmply
2023-03-27 23:21:39 +08:00
parent 88ee4f13e1
commit a5e3985745
8 changed files with 224 additions and 12099 deletions

View File

@@ -12,23 +12,32 @@ require("dotenv").config({
});
const domain = process.env.NODE_ENV ? "secure" : "test";
const SecretsManager = require("./aws-secrets-manager");
const getShopCredentials = () => {
// add parametes for the request
// TODO: Implement retrieval logic later.
const gqlClient = require("../graphql-client/graphql-client").client;
return {
merchantkey: "3B8068", //This should be dynamic
apikey: "Oepn2B.XqRgzAqHqvOOmYUxD2VW.vGSipi", //This should be dynamic
};
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,
};
}
// Production code
if (bodyshop?.imexshopid) {
const secret = await SecretsManager.getSecret(
`intellipay-credentials-${bodyshop.imexshopid}`,
process.env.REGION
);
return JSON.parse(secret);
}
};
exports.lightbox_credentials = async (req, res) => {
//req.user contains firebase decoded credentials
// can add bodyshopid to req.body
//Server side query to get API credentials for that shop and generatae link
const shopCredentials = getShopCredentials();
const shopCredentials = await getShopCredentials(req.body.bodyshop);
try {
const options = {
@@ -55,7 +64,7 @@ exports.lightbox_credentials = async (req, res) => {
};
exports.payment_refund = async (req, res) => {
const shopCredentials = getShopCredentials();
const shopCredentials = await getShopCredentials(req.body.bodyshop);
try {
const options = {
@@ -81,8 +90,7 @@ exports.payment_refund = async (req, res) => {
};
exports.generate_payment_url = async (req, res) => {
const shopCredentials = getShopCredentials();
const shopCredentials = await getShopCredentials(req.body.bodyshop);
try {
const options = {
method: "POST",
@@ -108,5 +116,69 @@ exports.generate_payment_url = async (req, res) => {
exports.postback = async (req, res) => {
console.log("postback as", req.body);
res.send({ message: "postback" });
const { body: values } = req;
// TODO query job by account name
const job = await gqlClient.request(queries.GET_JOB_BY_RO_NUMBER, {
ro_number: values.account,
});
// 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()),
},
});
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,
},
});
res.send({ message: "Postback Successful" });
};
`{
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'
}`;