Merge branch 'feature/IO-3000-messaging-sockets-migrationv2' of bitbucket.org:snaptsoft/bodyshop into feature/IO-3000-messaging-sockets-migrationv2
This commit is contained in:
@@ -36442,6 +36442,27 @@
|
||||
</translation>
|
||||
</translations>
|
||||
</concept_node>
|
||||
<concept_node>
|
||||
<name>total_repairs_cash_discount</name>
|
||||
<definition_loaded>false</definition_loaded>
|
||||
<description></description>
|
||||
<comment></comment>
|
||||
<default_text></default_text>
|
||||
<translations>
|
||||
<translation>
|
||||
<language>en-US</language>
|
||||
<approved>false</approved>
|
||||
</translation>
|
||||
<translation>
|
||||
<language>es-MX</language>
|
||||
<approved>false</approved>
|
||||
</translation>
|
||||
<translation>
|
||||
<language>fr-CA</language>
|
||||
<approved>false</approved>
|
||||
</translation>
|
||||
</translations>
|
||||
</concept_node>
|
||||
<concept_node>
|
||||
<name>total_sales</name>
|
||||
<definition_loaded>false</definition_loaded>
|
||||
|
||||
@@ -7,6 +7,7 @@ import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import InstanceRenderManager from "../../utils/instanceRenderMgr";
|
||||
import JobTotalsCashDiscount from "./jobs-totals.cash-discount-display.component";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
//currentUser: selectCurrentUser
|
||||
@@ -149,11 +150,27 @@ export function JobTotalsTableTotals({ bodyshop, job }) {
|
||||
]
|
||||
}),
|
||||
|
||||
{
|
||||
key: t("jobs.labels.total_repairs"),
|
||||
total: job.job_totals.totals.total_repairs,
|
||||
bold: true
|
||||
},
|
||||
...(bodyshop.intellipay_config?.enable_cash_discount
|
||||
? [
|
||||
{
|
||||
key: t("jobs.labels.total_repairs_cash_discount"),
|
||||
total: job.job_totals.totals.total_repairs,
|
||||
bold: true
|
||||
},
|
||||
{
|
||||
key: t("jobs.labels.total_repairs"),
|
||||
render: <JobTotalsCashDiscount amountDinero={job.job_totals.totals.total_repairs} />,
|
||||
bold: true
|
||||
}
|
||||
]
|
||||
: [
|
||||
{
|
||||
key: t("jobs.labels.total_repairs"),
|
||||
total: job.job_totals.totals.total_repairs,
|
||||
bold: true
|
||||
}
|
||||
]),
|
||||
|
||||
{
|
||||
key: t("jobs.fields.ded_amt"),
|
||||
total: job.job_totals.totals.custPayable.deductible
|
||||
@@ -186,13 +203,7 @@ export function JobTotalsTableTotals({ bodyshop, job }) {
|
||||
},
|
||||
{
|
||||
key: t("jobs.labels.total_cust_payable"),
|
||||
total: Dinero(job.job_totals.totals.custPayable.total)
|
||||
.add(
|
||||
Dinero(job.job_totals.totals.custPayable.total).percentage(
|
||||
bodyshop.intellipay_config?.cash_discount_percentage || 0
|
||||
)
|
||||
)
|
||||
.toJSON(),
|
||||
render: <JobTotalsCashDiscount amountDinero={job.job_totals.totals.custPayable.total} />,
|
||||
bold: true
|
||||
}
|
||||
]
|
||||
@@ -228,7 +239,7 @@ export function JobTotalsTableTotals({ bodyshop, job }) {
|
||||
dataIndex: "total",
|
||||
key: "total",
|
||||
align: "right",
|
||||
render: (text, record) => Dinero(record.total).toFormat(),
|
||||
render: (text, record) => (record.render ? record.render : Dinero(record.total).toFormat()),
|
||||
width: "20%",
|
||||
onCell: (record, rowIndex) => {
|
||||
return { style: { fontWeight: record.bold && "bold" } };
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import { notification, Spin } from "antd";
|
||||
import axios from "axios";
|
||||
import Dinero from "dinero.js";
|
||||
import React, { useCallback, useEffect, useState } from "react";
|
||||
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop
|
||||
});
|
||||
const mapDispatchToProps = (dispatch) => ({});
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(JobTotalsCashDiscount);
|
||||
|
||||
export function JobTotalsCashDiscount({ bodyshop, amountDinero }) {
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [fee, setFee] = useState(0);
|
||||
|
||||
const fetchData = useCallback(async () => {
|
||||
if (amountDinero && bodyshop) {
|
||||
setLoading(true);
|
||||
let response;
|
||||
try {
|
||||
response = await axios.post("/intellipay/checkfee", {
|
||||
bodyshop: { id: bodyshop.id, imexshopid: bodyshop.imexshopid, state: bodyshop.state },
|
||||
amount: Dinero(amountDinero).toFormat("0.00")
|
||||
});
|
||||
|
||||
if (response?.data?.error) {
|
||||
notification.open({
|
||||
type: "error",
|
||||
message:
|
||||
response.data?.error ||
|
||||
"Error encountered when contacting IntelliPay service to determine cash discounted price."
|
||||
});
|
||||
} else {
|
||||
setFee(response.data?.fee || 0);
|
||||
}
|
||||
} catch (error) {
|
||||
notification.open({
|
||||
type: "error",
|
||||
message:
|
||||
error.response?.data?.error ||
|
||||
"Error encountered when contacting IntelliPay service to determine cash discounted price."
|
||||
});
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
}, [amountDinero, bodyshop]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchData();
|
||||
}, [fetchData, bodyshop, amountDinero]);
|
||||
|
||||
if (loading) return <Spin size="small" />;
|
||||
return Dinero(amountDinero)
|
||||
.add(Dinero({ amount: Math.round(fee * 100) }))
|
||||
.toFormat();
|
||||
}
|
||||
@@ -37,16 +37,6 @@ export function ShopInfoIntellipay({ bodyshop, form }) {
|
||||
>
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label={t("bodyshop.fields.intellipay_config.cash_discount_percentage")}
|
||||
dependencies={[["intellipay_config", "enable_cash_discount"]]}
|
||||
name={["intellipay_config", "cash_discount_percentage"]}
|
||||
rules={[
|
||||
({ getFieldsValue }) => ({ required: form.getFieldValue(["intellipay_config", "enable_cash_discount"]) })
|
||||
]}
|
||||
>
|
||||
<InputNumber min={0} max={100} precision={1} suffix="%" />
|
||||
</Form.Item>
|
||||
</LayoutFormRow>
|
||||
</>
|
||||
);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -14,7 +14,7 @@ require("dotenv").config({
|
||||
path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
|
||||
});
|
||||
|
||||
const domain = process.env.NODE_ENV ? "secure" : "test";
|
||||
const domain = process.env.NODE_ENV ? "secure" : "secure";
|
||||
|
||||
const { SecretsManagerClient, GetSecretValueCommand } = require("@aws-sdk/client-secrets-manager");
|
||||
const { InstanceRegion } = require("../utils/instanceMgr");
|
||||
@@ -149,6 +149,58 @@ exports.generate_payment_url = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
//Reference: https://intellipay.com/dist/webapi26.html#operation/fee
|
||||
exports.checkfee = async (req, res) => {
|
||||
// Requires amount, bodyshop.imexshopid, and state? to get data.
|
||||
logger.log("intellipay-fee-check", "DEBUG", req.user?.email, null, null);
|
||||
|
||||
//If there's no amount, there can't be a fee. Skip the call.
|
||||
if (!req.body.amount || req.body.amount <= 0) {
|
||||
res.json({ fee: 0 });
|
||||
return;
|
||||
}
|
||||
|
||||
const shopCredentials = await getShopCredentials(req.body.bodyshop);
|
||||
|
||||
try {
|
||||
const options = {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/x-www-form-urlencoded" },
|
||||
//TODO: Move these to environment variables/database.
|
||||
data: qs.stringify(
|
||||
{
|
||||
method: "fee",
|
||||
...shopCredentials,
|
||||
amount: req.body.amount,
|
||||
paymenttype: `CC`,
|
||||
cardnum: "4111111111111111", //Not needed per documentation, but incorrect values come back without it.
|
||||
state:
|
||||
req.body.bodyshop?.state && req.body.bodyshop.state?.length === 2
|
||||
? req.body.bodyshop.state.toUpperCase()
|
||||
: "ZZ" //Same as above
|
||||
},
|
||||
{ sort: false } //ColdFusion Query Strings depend on order. This preserves it.
|
||||
),
|
||||
url: `https://${domain}.cpteller.com/api/26/webapi.cfc`
|
||||
};
|
||||
|
||||
const response = await axios(options);
|
||||
if (response.data?.error) {
|
||||
res.status(400).json({ error: response.data.error });
|
||||
} else if (response.data < 0) {
|
||||
res.json({ error: "Fee amount negative. Check API credentials & account configuration." });
|
||||
} else {
|
||||
res.json({ fee: response.data });
|
||||
}
|
||||
} catch (error) {
|
||||
//console.log(error);
|
||||
logger.log("intellipay-fee-check-error", "ERROR", req.user?.email, null, {
|
||||
error: error.message
|
||||
});
|
||||
res.status(400).json({ error });
|
||||
}
|
||||
};
|
||||
|
||||
exports.postback = async (req, res) => {
|
||||
try {
|
||||
logger.log("intellipay-postback", "DEBUG", req.user?.email, null, req.body);
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
const express = require("express");
|
||||
const router = express.Router();
|
||||
const validateFirebaseIdTokenMiddleware = require("../middleware/validateFirebaseIdTokenMiddleware");
|
||||
const { lightbox_credentials, payment_refund, generate_payment_url, postback } = require("../intellipay/intellipay");
|
||||
const { lightbox_credentials, payment_refund, generate_payment_url, postback, checkfee } = require("../intellipay/intellipay");
|
||||
|
||||
router.post("/lightbox_credentials", validateFirebaseIdTokenMiddleware, lightbox_credentials);
|
||||
router.post("/payment_refund", validateFirebaseIdTokenMiddleware, payment_refund);
|
||||
router.post("/generate_payment_url", validateFirebaseIdTokenMiddleware, generate_payment_url);
|
||||
router.post("/checkfee", validateFirebaseIdTokenMiddleware, checkfee);
|
||||
router.post("/postback", postback);
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user