Merge branch 'feature/intellipay' into feature/america

This commit is contained in:
Patrick Fic
2023-03-20 14:11:39 -07:00
18 changed files with 880 additions and 62 deletions

View File

@@ -0,0 +1,112 @@
const GraphQLClient = require("graphql-request").GraphQLClient;
const path = require("path");
const queries = require("../graphql-client/queries");
const Dinero = require("dinero.js");
const qs = require("query-string");
const axios = require("axios");
require("dotenv").config({
path: path.resolve(
process.cwd(),
`.env.${process.env.NODE_ENV || "development"}`
),
});
const domain = process.env.NODE_ENV ? "secure" : "test";
const getShopCredentials = () => {
// add parametes for the request
// TODO: Implement retrieval logic later.
return {
merchantkey: "3B8068", //This should be dynamic
apikey: "Oepn2B.XqRgzAqHqvOOmYUxD2VW.vGSipi", //This should be dynamic
};
};
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();
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",
}),
url: `https://${domain}.cpteller.com/api/custapi.cfc?method=autoterminal`,
};
const response = await axios(options);
res.send(response.data);
} catch (error) {
console.log(error);
res.json({ error });
}
};
exports.payment_refund = async (req, res) => {
const shopCredentials = getShopCredentials();
try {
const options = {
method: "POST",
headers: { "content-type": "application/x-www-form-urlencoded" },
data: qs.stringify({
method: "payment_refund",
...shopCredentials,
paymentid: req.body.paymentid,
amount: req.body.amount,
}),
url: `https://${domain}.cpteller.com/api/26/webapi.cfc?method=payment_refund`,
};
const response = await axios(options);
res.send(response.data);
} catch (error) {
console.log(error);
res.json({ error });
}
};
exports.generate_payment_url = async (req, res) => {
const shopCredentials = getShopCredentials();
try {
const options = {
method: "POST",
headers: { "content-type": "application/x-www-form-urlencoded" },
//TODO: Move these to environment variables/database.
data: qs.stringify({
...shopCredentials,
...req.body,
createshorturl: true,
}),
url: `https://${domain}.cpteller.com/api/custapi.cfc?method=generate_lightbox_url`,
};
const response = await axios(options);
res.send(response.data);
} catch (error) {
console.log(error);
res.json({ error });
}
};
exports.postback = async (req, res) => {
console.log("postback as", req.body);
res.send({ message: "postback" });
};