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 Dinero = require("dinero.js");
|
||||
const qs = require("query-string");
|
||||
@@ -10,18 +6,22 @@ const moment = require("moment");
|
||||
const logger = require("../utils/logger");
|
||||
const { sendTaskEmail } = require("../email/sendemail");
|
||||
const generateEmailTemplate = require("../email/generateTemplate");
|
||||
|
||||
const domain = process.env.NODE_ENV ? "secure" : "test";
|
||||
|
||||
const { SecretsManagerClient, GetSecretValueCommand } = require("@aws-sdk/client-secrets-manager");
|
||||
const { InstanceRegion, InstanceEndpoints } = require("../utils/instanceMgr");
|
||||
|
||||
const domain = process.env.NODE_ENV ? "secure" : "test";
|
||||
|
||||
const client = new SecretsManagerClient({
|
||||
region: InstanceRegion()
|
||||
});
|
||||
|
||||
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) => {
|
||||
// Development only
|
||||
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) => {
|
||||
try {
|
||||
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) {
|
||||
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 logMeta = {
|
||||
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 logResponseMeta = {
|
||||
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 logResponseMeta = {
|
||||
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 = {
|
||||
bodyshop: {
|
||||
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 decodedComment = decodeComment(values?.comment);
|
||||
|
||||
@@ -474,6 +509,7 @@ exports.postback = async (req, res) => {
|
||||
const bodyshop = await gqlClient.request(queries.GET_BODYSHOP_BY_ID, {
|
||||
id: job.jobs_by_pk.shopid
|
||||
});
|
||||
|
||||
const ipMapping = bodyshop.bodyshops_by_pk.intellipay_config?.payment_map;
|
||||
|
||||
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 });
|
||||
}
|
||||
};
|
||||
|
||||
const postBackCallBack = async (req, res) => {};
|
||||
|
||||
module.exports = {
|
||||
lightboxCredentials,
|
||||
paymentRefund,
|
||||
generatePaymentUrl,
|
||||
checkFee,
|
||||
postBack,
|
||||
postBackCallBack
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user