Add server side logging for intellipay.

This commit is contained in:
Patrick Fic
2023-08-23 13:26:17 -07:00
parent eb48b56f47
commit 94e47d14ad
6 changed files with 118 additions and 99 deletions

View File

@@ -1,4 +1,4 @@
<babeledit_project version="1.2" be_version="2.7.1"> <babeledit_project be_version="2.7.1" version="1.2">
<!-- <!--
BabelEdit project file BabelEdit project file

View File

@@ -97,6 +97,11 @@ function Header({
{}, {},
bodyshop && bodyshop.imexshopid bodyshop && bodyshop.imexshopid
); );
const { ImEXPay } = useTreatments(
["ImEXPay"],
{},
bodyshop && bodyshop.imexshopid
);
const { t } = useTranslation(); const { t } = useTranslation();
@@ -243,19 +248,20 @@ function Header({
> >
{t("menus.header.enterpayment")} {t("menus.header.enterpayment")}
</Menu.Item> </Menu.Item>
{/* TODO: Enter Card Payment */} {ImEXPay.treatment === "on" && (
<Menu.Item <Menu.Item
key="entercardpayments" key="entercardpayments"
onClick={() => { onClick={() => {
setCardPaymentContext({ setCardPaymentContext({
actions: {}, actions: {},
context: null, context: null,
}); });
}} }}
icon={<Icon component={FaCreditCard} />} icon={<Icon component={FaCreditCard} />}
> >
{t("menus.header.entercardpayment")} {t("menus.header.entercardpayment")}
</Menu.Item> </Menu.Item>
)}
<Menu.Divider key="div5" /> <Menu.Divider key="div5" />
<Menu.Item key="timetickets" icon={<FieldTimeOutlined />}> <Menu.Item key="timetickets" icon={<FieldTimeOutlined />}>
<Link to="/manage/timetickets"> <Link to="/manage/timetickets">

View File

@@ -20,6 +20,7 @@ import DataLabel from "../data-label/data-label.component";
import PaymentExpandedRowComponent from "../payment-expanded-row/payment-expanded-row.component"; import PaymentExpandedRowComponent from "../payment-expanded-row/payment-expanded-row.component";
import PaymentsGenerateLink from "../payments-generate-link/payments-generate-link.component"; import PaymentsGenerateLink from "../payments-generate-link/payments-generate-link.component";
import PrintWrapperComponent from "../print-wrapper/print-wrapper.component"; import PrintWrapperComponent from "../print-wrapper/print-wrapper.component";
import { useTreatments } from "@splitsoftware/splitio-react";
const mapStateToProps = createStructuredSelector({ const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop, bodyshop: selectBodyshop,
@@ -45,6 +46,12 @@ export function JobPayments({
setCardPaymentContext, setCardPaymentContext,
refetch, refetch,
}) { }) {
const { ImEXPay } = useTreatments(
["ImEXPay"],
{},
bodyshop && bodyshop.imexshopid
);
const { t } = useTranslation(); const { t } = useTranslation();
const [state, setState] = useState({ const [state, setState] = useState({
sortedInfo: {}, sortedInfo: {},
@@ -163,7 +170,21 @@ export function JobPayments({
title={t("payments.labels.title")} title={t("payments.labels.title")}
extra={ extra={
<Space wrap> <Space wrap>
<PaymentsGenerateLink job={job} /> {ImEXPay.treatment === "on" && (
<>
<Button
onClick={() =>
setCardPaymentContext({
actions: { refetch },
context: { jobid: job.id, balance },
})
}
>
{t("menus.header.entercardpayment")}
</Button>
<PaymentsGenerateLink job={job} />
</>
)}
<Button <Button
disabled={!job.converted} disabled={!job.converted}
onClick={() => onClick={() =>
@@ -176,16 +197,6 @@ export function JobPayments({
{t("menus.header.enterpayment")} {t("menus.header.enterpayment")}
</Button> </Button>
<Button
onClick={() =>
setCardPaymentContext({
actions: { refetch },
context: { jobid: job.id, balance },
})
}
>
{t("menus.header.entercardpayment")}
</Button>
<DataLabel <DataLabel
valueStyle={{ color: balance.getAmount() !== 0 ? "red" : "green" }} valueStyle={{ color: balance.getAmount() !== 0 ? "red" : "green" }}
label={t("payments.labels.balance")} label={t("payments.labels.balance")}

View File

@@ -8,8 +8,8 @@ import { useTranslation } from "react-i18next";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { createStructuredSelector } from "reselect"; import { createStructuredSelector } from "reselect";
import { import {
openChatByPhone, openChatByPhone,
setMessage, setMessage,
} from "../../redux/messaging/messaging.actions"; } from "../../redux/messaging/messaging.actions";
import { selectBodyshop } from "../../redux/user/user.selectors"; import { selectBodyshop } from "../../redux/user/user.selectors";
import CurrencyFormItemComponent from "../form-items-formatted/currency-form-item.component"; import CurrencyFormItemComponent from "../form-items-formatted/currency-form-item.component";
@@ -52,7 +52,6 @@ export function PaymentsGenerateLink({
invoice: job.id, invoice: job.id,
}); });
setLoading(false); setLoading(false);
setPaymentLink(response.data.shorUrl); setPaymentLink(response.data.shorUrl);
openChatByPhone({ openChatByPhone({
@@ -60,7 +59,7 @@ export function PaymentsGenerateLink({
jobid: job.id, jobid: job.id,
}); });
setMessage( setMessage(
t("appointments.labels.smspaymentreminder", { t("payments.labels.smspaymentreminder", {
shopname: bodyshop.shopname, shopname: bodyshop.shopname,
amount: amount, amount: amount,
payment_link: response.data.shorUrl, payment_link: response.data.shorUrl,
@@ -70,14 +69,6 @@ export function PaymentsGenerateLink({
//Add in confirmation & errors. //Add in confirmation & errors.
if (callback) callback(); if (callback) callback();
// if (res.errors) {
// notification["error"]({
// message: t("documents.errors.updating", {
// message: JSON.stringify(res.errors),
// }),
// });
// }
// setVisible(false); // setVisible(false);
setLoading(false); setLoading(false);
}; };
@@ -142,7 +133,13 @@ export function PaymentsGenerateLink({
<Button type="primary" onClick={() => form.submit()}> <Button type="primary" onClick={() => form.submit()}>
{t("general.actions.submit")} {t("general.actions.submit")}
</Button> </Button>
<Button onClick={() => setVisible(false)}> <Button
onClick={() => {
form.resetFields();
setPaymentLink(null);
setVisible(false);
}}
>
{t("general.actions.cancel")} {t("general.actions.cancel")}
</Button> </Button>
</Space> </Space>

View File

@@ -2233,7 +2233,7 @@
"markforreexport": "Mark for Re-export", "markforreexport": "Mark for Re-export",
"new": "New Payment", "new": "New Payment",
"signup": "Please contact support to sign up for electronic payments.", "signup": "Please contact support to sign up for electronic payments.",
"smspaymentreminder": "This is {{shopname}} reminding you about your balance of {{amount}}. To pay for the said balance click the link {{payment_link}}.", "smspaymentreminder": "This is {{shopname}} reminding you about your balance of {{amount}}. To pay, click the following link {{payment_link}}.",
"title": "Payments", "title": "Payments",
"totalpayments": "Total Payments" "totalpayments": "Total Payments"
}, },

View File

@@ -5,6 +5,8 @@ const Dinero = require("dinero.js");
const qs = require("query-string"); const qs = require("query-string");
const axios = require("axios"); const axios = require("axios");
const moment = require("moment"); const moment = require("moment");
const logger = require("../utils/logger");
require("dotenv").config({ require("dotenv").config({
path: path.resolve( path: path.resolve(
process.cwd(), process.cwd(),
@@ -14,7 +16,6 @@ require("dotenv").config({
const domain = process.env.NODE_ENV ? "secure" : "test"; const domain = process.env.NODE_ENV ? "secure" : "test";
const SecretsManager = require("./aws-secrets-manager");
const { const {
SecretsManagerClient, SecretsManagerClient,
GetSecretValueCommand, GetSecretValueCommand,
@@ -46,14 +47,28 @@ const getShopCredentials = async (bodyshop) => {
); );
return JSON.parse(secret.SecretString); return JSON.parse(secret.SecretString);
} catch (error) { } catch (error) {
console.log(error); return {
error: error.message,
};
} }
} }
}; };
exports.lightbox_credentials = async (req, res) => { exports.lightbox_credentials = async (req, res) => {
logger.log(
"intellipay-lightbox-credentials",
"DEBUG",
req.user?.email,
null,
null
);
const shopCredentials = await getShopCredentials(req.body.bodyshop); const shopCredentials = await getShopCredentials(req.body.bodyshop);
if (shopCredentials.error) {
res.json(shopCredentials);
return;
}
try { try {
const options = { const options = {
method: "POST", method: "POST",
@@ -72,11 +87,20 @@ exports.lightbox_credentials = async (req, res) => {
res.send(response.data); res.send(response.data);
} catch (error) { } catch (error) {
console.log(error); console.log(error);
logger.log(
"intellipay-lightbox-credentials-error",
"ERROR",
req.user?.email,
null,
{ error: JSON.stringify(error) }
);
res.json({ error }); res.json({ error });
} }
}; };
exports.payment_refund = async (req, res) => { exports.payment_refund = async (req, res) => {
logger.log("intellipay-refund", "DEBUG", req.user?.email, null, null);
const shopCredentials = await getShopCredentials(req.body.bodyshop); const shopCredentials = await getShopCredentials(req.body.bodyshop);
try { try {
@@ -98,11 +122,15 @@ exports.payment_refund = async (req, res) => {
res.send(response.data); res.send(response.data);
} catch (error) { } catch (error) {
console.log(error); console.log(error);
logger.log("intellipay-refund-error", "ERROR", req.user?.email, null, {
error: JSON.stringify(error),
});
res.json({ error }); res.json({ error });
} }
}; };
exports.generate_payment_url = async (req, res) => { exports.generate_payment_url = async (req, res) => {
logger.log("intellipay-payment-url", "DEBUG", req.user?.email, null, null);
const shopCredentials = await getShopCredentials(req.body.bodyshop); const shopCredentials = await getShopCredentials(req.body.bodyshop);
try { try {
const options = { const options = {
@@ -112,7 +140,6 @@ exports.generate_payment_url = async (req, res) => {
data: qs.stringify({ data: qs.stringify({
...shopCredentials, ...shopCredentials,
...req.body, ...req.body,
bodyshopid: "1234",
createshorturl: true, createshorturl: true,
//The postback URL is set at the CP teller global terminal settings page. //The postback URL is set at the CP teller global terminal settings page.
}), }),
@@ -124,13 +151,15 @@ exports.generate_payment_url = async (req, res) => {
res.send(response.data); res.send(response.data);
} catch (error) { } catch (error) {
console.log(error); console.log(error);
logger.log("intellipay-payment-url-error", "ERROR", req.user?.email, null, {
error: JSON.stringify(error),
});
res.json({ error }); res.json({ error });
} }
}; };
exports.postback = async (req, res) => { exports.postback = async (req, res) => {
console.log("postback as", req.body); logger.log("intellipay-postback", "ERROR", req.user?.email, null, req.body);
const { body: values } = req; const { body: values } = req;
if (!values.invoice) { if (!values.invoice) {
@@ -143,61 +172,37 @@ exports.postback = async (req, res) => {
}); });
// TODO add mutation to database // TODO add mutation to database
const paymentResult = await gqlClient.request(queries.INSERT_NEW_PAYMENT, { try {
paymentInput: { const paymentResult = await gqlClient.request(queries.INSERT_NEW_PAYMENT, {
amount: values.total, paymentInput: {
transactionid: `C00 ${values.authcode}`, amount: values.total,
payer: "Customer", transactionid: `C00 ${values.authcode}`,
type: values.cardtype, payer: "Customer",
jobid: values.invoice, type: values.cardtype,
date: moment(Date.now()), jobid: values.invoice,
}, date: moment(Date.now()),
}); },
});
await gqlClient.request(queries.INSERT_PAYMENT_RESPONSE, { await gqlClient.request(queries.INSERT_PAYMENT_RESPONSE, {
paymentResponse: { paymentResponse: {
amount: values.total, amount: values.total,
bodyshopid: job.jobs_by_pk.shopid, bodyshopid: job.jobs_by_pk.shopid,
paymentid: paymentResult.id, paymentid: paymentResult.id,
jobid: values.invoice, jobid: values.invoice,
declinereason: "Approved", declinereason: "Approved",
ext_paymentid: values.paymentid, ext_paymentid: values.paymentid,
successful: true, successful: true,
response: values, response: values,
}, },
}); });
res.send({ message: "Postback Successful" }); res.send({ message: "Postback Successful" });
} catch (error) {
logger.log("intellipay-postback-error", "ERROR", req.user?.email, null, {
error: JSON.stringify(error),
body: req.body,
});
res.status(400).json({ succesful: false, error: error.message });
}
}; };
`{
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'
}`;