From 88ee4f13e138d8490e9103776b31efb6e3d5aba8 Mon Sep 17 00:00:00 2001 From: swtmply Date: Sat, 18 Mar 2023 02:45:00 +0800 Subject: [PATCH] code cleanup and translations --- .../card-payment-modal.component..jsx | 2 +- .../card-payment-modal.container..jsx | 4 +- .../payment-expanded-row.component.jsx | 58 +++++++++++++------ client/src/translations/en_us/common.json | 24 ++++++++ server.js | 6 ++ server/intellipay/intellipay.js | 6 ++ 6 files changed, 81 insertions(+), 19 deletions(-) diff --git a/client/src/components/card-payment-modal/card-payment-modal.component..jsx b/client/src/components/card-payment-modal/card-payment-modal.component..jsx index 658019872..3c3b397c1 100644 --- a/client/src/components/card-payment-modal/card-payment-modal.component..jsx +++ b/client/src/components/card-payment-modal/card-payment-modal.component..jsx @@ -236,7 +236,7 @@ const CardPaymentModalComponent = ({ className="ipayfield" disabled={!amount || !payer || !jobid} > - Proceed to Payment + {t("job_payments.buttons.proceedtopayment")} {context?.balance && ( { toggleModalVisible(); @@ -38,7 +40,7 @@ function CardPaymentModalContainer({ onCancel={handleCancel} footer={[ , ]} width="60%" diff --git a/client/src/components/payment-expanded-row/payment-expanded-row.component.jsx b/client/src/components/payment-expanded-row/payment-expanded-row.component.jsx index 6d2559188..da3e79e20 100644 --- a/client/src/components/payment-expanded-row/payment-expanded-row.component.jsx +++ b/client/src/components/payment-expanded-row/payment-expanded-row.component.jsx @@ -5,17 +5,26 @@ import { INSERT_PAYMENT_RESPONSE, QUERY_PAYMENT_RESPONSE_BY_PAYMENT_ID, } from "../../graphql/payment_response.queries"; -import { Button, Descriptions, InputNumber, Modal } from "antd"; +import { Button, Descriptions, InputNumber, Modal, notification } from "antd"; import moment from "moment"; import axios from "axios"; import { INSERT_NEW_PAYMENT } from "../../graphql/payments.queries"; +import { useTranslation } from "react-i18next"; const { confirm } = Modal; +const openNotificationWithIcon = (type, t) => { + notification[type]({ + message: t("job_payments.notifications.error.title"), + description: t("job_payments.notifications.error.description"), + }); +}; + const PaymentExpandedRowComponent = ({ record }) => { const [refundAmount, setRefundAmount] = useState(0); const [insertPayment] = useMutation(INSERT_NEW_PAYMENT); const [insertPaymentResponse] = useMutation(INSERT_PAYMENT_RESPONSE); + const { t } = useTranslation(); const { loading, error, data } = useQuery( QUERY_PAYMENT_RESPONSE_BY_PAYMENT_ID, @@ -28,11 +37,14 @@ const PaymentExpandedRowComponent = ({ record }) => { } ); - const { data: refundable_amount } = useQuery(GET_REFUNDABLE_AMOUNT_BY_JOBID, { - variables: { - jobid: record.jobid, - }, - }); + const { data: refundable_amount, refetch } = useQuery( + GET_REFUNDABLE_AMOUNT_BY_JOBID, + { + variables: { + jobid: record.jobid, + }, + } + ); const insertPayments = async (payment_response, refund_response) => { await insertPayment({ @@ -88,7 +100,15 @@ const PaymentExpandedRowComponent = ({ record }) => { paymentid: payment_response.ext_paymentid, }); + if (refundResponse.data.status < 0) { + openNotificationWithIcon("error", t); + return; + } + insertPayments(payment_response, refundResponse); + + // refetch refundable amount + refetch(); }, onCancel() {}, }); @@ -100,34 +120,38 @@ const PaymentExpandedRowComponent = ({ record }) => { const payment_response = data.payment_response[0]; const max_refundable_amount = - refundable_amount.payment_response_aggregate.aggregate.sum.amount; + refundable_amount?.payment_response_aggregate.aggregate.sum.amount; return (
- {record.payer} - + + {record.payer} + + {payment_response?.response?.nameOnCard ?? ""} - {record.amount} - + + {record.amount} + + {moment(record.created_at).format("YYYY-MM-DD HH:mm:ss")} - + {record.transactionid} - + {payment_response?.response?.paymentreferenceid ?? ""} - + {record.type} {payment_response && ( - + { /> )} diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json index 691918729..25508060d 100644 --- a/client/src/translations/en_us/common.json +++ b/client/src/translations/en_us/common.json @@ -956,6 +956,30 @@ "priorsuccesfulexport": "This record has previously been exported successfully. Please make sure it has already been deleted in the target system." } }, + "job_payments": { + "buttons": { + "refundpayment": "Refund Payment", + "proceedtopayment": "Proceed to Payment", + "goback": "Go Back" + }, + "titles": { + "descriptions": "Payment Details", + "payer": "Payer", + "payername": "Payer Name", + "amount": "Amount", + "dateOfPayment": "Date of Payment", + "transactionid": "Transaction ID", + "paymentid": "Payment Reference ID", + "paymenttype": "Payment Type", + "refundamount": "Refund Amount" + }, + "notifications": { + "error": { + "title": "Error placing refund", + "description": "Please try again. Make sure the refund amount does not exceeds the payment amount." + } + } + }, "general": { "actions": { "add": "Add", diff --git a/server.js b/server.js index 531c7813f..0224f66e2 100644 --- a/server.js +++ b/server.js @@ -244,6 +244,12 @@ app.post( intellipay.generate_payment_url ); +app.post( + "/intellipay/postback", + // fb.validateFirebaseIdToken, + intellipay.postback +); + var ioevent = require("./server/ioevent/ioevent"); app.post("/ioevent", ioevent.default); app.post("/newlog", (req, res) => { diff --git a/server/intellipay/intellipay.js b/server/intellipay/intellipay.js index c9646088b..97d9771af 100644 --- a/server/intellipay/intellipay.js +++ b/server/intellipay/intellipay.js @@ -104,3 +104,9 @@ exports.generate_payment_url = async (req, res) => { res.json({ error }); } }; + +exports.postback = async (req, res) => { + console.log("postback as", req.body); + + res.send({ message: "postback" }); +};