Merge branch 'feature/intellipay' into feature/america
This commit is contained in:
@@ -12,6 +12,39 @@ query FIND_BODYSHOP_BY_MESSAGING_SERVICE_SID(
|
||||
}
|
||||
`;
|
||||
|
||||
exports.GET_JOB_BY_RO_NUMBER = `
|
||||
query GET_JOB_BY_RO_NUMBER($ro_number: String!) {
|
||||
jobs(where:{ro_number:{_eq:$ro_number}}) {
|
||||
id
|
||||
bodyshop {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
exports.INSERT_NEW_PAYMENT = `
|
||||
mutation INSERT_NEW_PAYMENT($paymentInput: [payments_insert_input!]!) {
|
||||
insert_payments(objects: $paymentInput) {
|
||||
returning {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
exports.INSERT_PAYMENT_RESPONSE = `
|
||||
mutation INSERT_PAYMENT_RESPONSE(
|
||||
$paymentResponse: [payment_response_insert_input!]!
|
||||
) {
|
||||
insert_payment_response(objects: $paymentResponse) {
|
||||
returning {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
exports.UNARCHIVE_CONVERSATION = `
|
||||
mutation UNARCHIVE_CONVERSATION($id: uuid!) {
|
||||
update_conversations_by_pk(pk_columns: {id: $id}, _set: {archived: false}) {
|
||||
|
||||
46
server/intellipay/aws-secrets-manager.js
Normal file
46
server/intellipay/aws-secrets-manager.js
Normal file
@@ -0,0 +1,46 @@
|
||||
"use strict";
|
||||
|
||||
const AWS = require("aws-sdk");
|
||||
|
||||
class SecretsManager {
|
||||
/**
|
||||
* Uses AWS Secrets Manager to retrieve a secret
|
||||
*/
|
||||
static async getSecret(secretName, region) {
|
||||
const config = { region: region };
|
||||
let secretsManager = new AWS.SecretsManager(config);
|
||||
try {
|
||||
let secretValue = await secretsManager
|
||||
.getSecretValue({ SecretId: secretName })
|
||||
.promise();
|
||||
if ("SecretString" in secretValue) {
|
||||
return secretValue.SecretString;
|
||||
} else {
|
||||
let buff = new Buffer(secretValue.SecretBinary, "base64");
|
||||
return buff.toString("ascii");
|
||||
}
|
||||
} catch (err) {
|
||||
if (err.code === "DecryptionFailureException")
|
||||
// Secrets Manager can't decrypt the protected secret text using the provided KMS key.
|
||||
// Deal with the exception here, and/or rethrow at your discretion.
|
||||
throw err;
|
||||
else if (err.code === "InternalServiceErrorException")
|
||||
// An error occurred on the server side.
|
||||
// Deal with the exception here, and/or rethrow at your discretion.
|
||||
throw err;
|
||||
else if (err.code === "InvalidParameterException")
|
||||
// You provided an invalid value for a parameter.
|
||||
// Deal with the exception here, and/or rethrow at your discretion.
|
||||
throw err;
|
||||
else if (err.code === "InvalidRequestException")
|
||||
// You provided a parameter value that is not valid for the current state of the resource.
|
||||
// Deal with the exception here, and/or rethrow at your discretion.
|
||||
throw err;
|
||||
else if (err.code === "ResourceNotFoundException")
|
||||
// We can't find the resource that you asked for.
|
||||
// Deal with the exception here, and/or rethrow at your discretion.
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
module.exports = SecretsManager;
|
||||
@@ -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'
|
||||
}`;
|
||||
|
||||
Reference in New Issue
Block a user