feature/IO-2885-IntelliPay-App-Postback-Support
- Clean intellipay.js, add new route scaffolding
This commit is contained in:
@@ -1,7 +1,3 @@
|
|||||||
const path = require("path");
|
|
||||||
require("dotenv").config({
|
|
||||||
path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
|
|
||||||
});
|
|
||||||
const queries = require("../graphql-client/queries");
|
const queries = require("../graphql-client/queries");
|
||||||
const Dinero = require("dinero.js");
|
const Dinero = require("dinero.js");
|
||||||
const qs = require("query-string");
|
const qs = require("query-string");
|
||||||
@@ -10,18 +6,22 @@ const moment = require("moment");
|
|||||||
const logger = require("../utils/logger");
|
const logger = require("../utils/logger");
|
||||||
const { sendTaskEmail } = require("../email/sendemail");
|
const { sendTaskEmail } = require("../email/sendemail");
|
||||||
const generateEmailTemplate = require("../email/generateTemplate");
|
const generateEmailTemplate = require("../email/generateTemplate");
|
||||||
|
|
||||||
const domain = process.env.NODE_ENV ? "secure" : "test";
|
|
||||||
|
|
||||||
const { SecretsManagerClient, GetSecretValueCommand } = require("@aws-sdk/client-secrets-manager");
|
const { SecretsManagerClient, GetSecretValueCommand } = require("@aws-sdk/client-secrets-manager");
|
||||||
const { InstanceRegion, InstanceEndpoints } = require("../utils/instanceMgr");
|
const { InstanceRegion, InstanceEndpoints } = require("../utils/instanceMgr");
|
||||||
|
|
||||||
|
const domain = process.env.NODE_ENV ? "secure" : "test";
|
||||||
|
|
||||||
const client = new SecretsManagerClient({
|
const client = new SecretsManagerClient({
|
||||||
region: InstanceRegion()
|
region: InstanceRegion()
|
||||||
});
|
});
|
||||||
|
|
||||||
const gqlClient = require("../graphql-client/graphql-client").client;
|
const gqlClient = require("../graphql-client/graphql-client").client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Get shop credentials from AWS Secrets Manager
|
||||||
|
* @param bodyshop
|
||||||
|
* @returns {Promise<{error}|{merchantkey: *, apikey: *}|any>}
|
||||||
|
*/
|
||||||
const getShopCredentials = async (bodyshop) => {
|
const getShopCredentials = async (bodyshop) => {
|
||||||
// Development only
|
// Development only
|
||||||
if (process.env.NODE_ENV === undefined) {
|
if (process.env.NODE_ENV === undefined) {
|
||||||
@@ -49,16 +49,27 @@ const getShopCredentials = async (bodyshop) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Decode the comment from base64
|
||||||
|
* @param comment
|
||||||
|
* @returns {any|null}
|
||||||
|
*/
|
||||||
const decodeComment = (comment) => {
|
const decodeComment = (comment) => {
|
||||||
try {
|
try {
|
||||||
return comment ? JSON.parse(Buffer.from(comment, "base64").toString()) : null;
|
return comment ? JSON.parse(Buffer.from(comment, "base64").toString()) : null;
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return null; // Handle malformed base64 string gracefully
|
return null; // Handle malformed base64 string gracefully
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.lightbox_credentials = async (req, res) => {
|
/**
|
||||||
|
* @description Get lightbox credentials for the shop
|
||||||
|
* @param req
|
||||||
|
* @param res
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
const lightboxCredentials = async (req, res) => {
|
||||||
const decodedComment = decodeComment(req.body?.comment);
|
const decodedComment = decodeComment(req.body?.comment);
|
||||||
const logMeta = {
|
const logMeta = {
|
||||||
iPayData: req.body?.iPayData,
|
iPayData: req.body?.iPayData,
|
||||||
@@ -119,7 +130,13 @@ exports.lightbox_credentials = async (req, res) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.payment_refund = async (req, res) => {
|
/**
|
||||||
|
* @description Process payment refund
|
||||||
|
* @param req
|
||||||
|
* @param res
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
const paymentRefund = async (req, res) => {
|
||||||
const decodedComment = decodeComment(req.body.iPayData?.comment);
|
const decodedComment = decodeComment(req.body.iPayData?.comment);
|
||||||
const logResponseMeta = {
|
const logResponseMeta = {
|
||||||
iPayData: req.body?.iPayData,
|
iPayData: req.body?.iPayData,
|
||||||
@@ -190,7 +207,13 @@ exports.payment_refund = async (req, res) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.generate_payment_url = async (req, res) => {
|
/**
|
||||||
|
* @description Generate payment URL for the shop
|
||||||
|
* @param req
|
||||||
|
* @param res
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
const generatePaymentUrl = async (req, res) => {
|
||||||
const decodedComment = decodeComment(req.body.comment);
|
const decodedComment = decodeComment(req.body.comment);
|
||||||
const logResponseMeta = {
|
const logResponseMeta = {
|
||||||
iPayData: req.body?.iPayData,
|
iPayData: req.body?.iPayData,
|
||||||
@@ -261,8 +284,14 @@ exports.generate_payment_url = async (req, res) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//Reference: https://intellipay.com/dist/webapi26.html#operation/fee
|
/**
|
||||||
exports.checkfee = async (req, res) => {
|
* @description Check the fee for a given amount
|
||||||
|
* Reference: https://intellipay.com/dist/webapi26.html#operation/fee
|
||||||
|
* @param req
|
||||||
|
* @param res
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
const checkFee = async (req, res) => {
|
||||||
const logResponseMeta = {
|
const logResponseMeta = {
|
||||||
bodyshop: {
|
bodyshop: {
|
||||||
id: req.body?.bodyshop?.id,
|
id: req.body?.bodyshop?.id,
|
||||||
@@ -359,7 +388,13 @@ exports.checkfee = async (req, res) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.postback = async (req, res) => {
|
/**
|
||||||
|
* @description Handle the postback from Intellipay
|
||||||
|
* @param req
|
||||||
|
* @param res
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
const postBack = async (req, res) => {
|
||||||
const { body: values } = req;
|
const { body: values } = req;
|
||||||
const decodedComment = decodeComment(values?.comment);
|
const decodedComment = decodeComment(values?.comment);
|
||||||
|
|
||||||
@@ -474,6 +509,7 @@ exports.postback = async (req, res) => {
|
|||||||
const bodyshop = await gqlClient.request(queries.GET_BODYSHOP_BY_ID, {
|
const bodyshop = await gqlClient.request(queries.GET_BODYSHOP_BY_ID, {
|
||||||
id: job.jobs_by_pk.shopid
|
id: job.jobs_by_pk.shopid
|
||||||
});
|
});
|
||||||
|
|
||||||
const ipMapping = bodyshop.bodyshops_by_pk.intellipay_config?.payment_map;
|
const ipMapping = bodyshop.bodyshops_by_pk.intellipay_config?.payment_map;
|
||||||
|
|
||||||
logger.log("intellipay-postback-invoice-job-fetched", "DEBUG", "api", null, {
|
logger.log("intellipay-postback-invoice-job-fetched", "DEBUG", "api", null, {
|
||||||
@@ -525,3 +561,14 @@ exports.postback = async (req, res) => {
|
|||||||
res.status(400).json({ successful: false, error: error.message, ...logResponseMeta });
|
res.status(400).json({ successful: false, error: error.message, ...logResponseMeta });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const postBackCallBack = async (req, res) => {};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
lightboxCredentials,
|
||||||
|
paymentRefund,
|
||||||
|
generatePaymentUrl,
|
||||||
|
checkFee,
|
||||||
|
postBack,
|
||||||
|
postBackCallBack
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,12 +1,20 @@
|
|||||||
const express = require("express");
|
const express = require("express");
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const validateFirebaseIdTokenMiddleware = require("../middleware/validateFirebaseIdTokenMiddleware");
|
const validateFirebaseIdTokenMiddleware = require("../middleware/validateFirebaseIdTokenMiddleware");
|
||||||
const { lightbox_credentials, payment_refund, generate_payment_url, postback, checkfee } = require("../intellipay/intellipay");
|
const {
|
||||||
|
lightboxCredentials,
|
||||||
|
paymentRefund,
|
||||||
|
generatePaymentUrl,
|
||||||
|
postBack,
|
||||||
|
checkFee,
|
||||||
|
postBackCallBack
|
||||||
|
} = require("../intellipay/intellipay");
|
||||||
|
|
||||||
router.post("/lightbox_credentials", validateFirebaseIdTokenMiddleware, lightbox_credentials);
|
router.post("/lightbox_credentials", validateFirebaseIdTokenMiddleware, lightboxCredentials);
|
||||||
router.post("/payment_refund", validateFirebaseIdTokenMiddleware, payment_refund);
|
router.post("/payment_refund", validateFirebaseIdTokenMiddleware, paymentRefund);
|
||||||
router.post("/generate_payment_url", validateFirebaseIdTokenMiddleware, generate_payment_url);
|
router.post("/generate_payment_url", validateFirebaseIdTokenMiddleware, generatePaymentUrl);
|
||||||
router.post("/checkfee", validateFirebaseIdTokenMiddleware, checkfee);
|
router.post("/checkfee", validateFirebaseIdTokenMiddleware, checkFee);
|
||||||
router.post("/postback", postback);
|
router.post("/postback", postBack);
|
||||||
|
router.post("/postback-callback", postBackCallBack);
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
Reference in New Issue
Block a user