From e327c8a231c888f38d912dc98c8755128cd7e24c Mon Sep 17 00:00:00 2001 From: Alex Cheung Date: Thu, 26 Oct 2023 18:04:42 +0800 Subject: [PATCH] add multi payment select page --- src/pages/Payment/MultiPaymentWindow.js | 157 ++++++++++ src/pages/Payment/index.js | 384 ++++++++++++++++++++---- src/routes/PublicUserRoutes.js | 5 + 3 files changed, 482 insertions(+), 64 deletions(-) create mode 100644 src/pages/Payment/MultiPaymentWindow.js diff --git a/src/pages/Payment/MultiPaymentWindow.js b/src/pages/Payment/MultiPaymentWindow.js new file mode 100644 index 0000000..6d81b2a --- /dev/null +++ b/src/pages/Payment/MultiPaymentWindow.js @@ -0,0 +1,157 @@ +import { + useEffect, + useState +} from "react"; + +// material-ui +import { + Button, + FormLabel, + Stack, + Typography, + Dialog, + DialogActions, + DialogContent, + DialogContentText, + DialogTitle, + Grid +} from '@mui/material'; +import { useFormik, FormikProvider } from 'formik'; +import * as yup from 'yup'; + + +const MultiPaymentWindow = (props) => { + + const windowTitle = "請選擇付款方式"; + const [content, setContent] = useState(); + + useEffect(() => { + console.log(props.fpsStatus) + console.log(props.creditCardStatus) + console.log(props.unionPayStatus) + console.log(props.ppsStatus) + if(props.availableMethods.length > 0){ + setContent( + + + + + + 交易參考編號: + + + + + {props.transactionData.transicationId} + + + + + + + + + 付款金額: + + + + + {"HK$ "+props.totalAmount} + + + + + + + + + 付款方式: + + + + + + + + + + + + + + + + + + ) + }else{ + setContent( + + + 付款功能現在不可用。 + + + ) + } + }, [props.open]); + + const formik = useFormik({ + initialValues: ({ + username: '', + }), + validationSchema: yup.object().shape({ + }), + }); + + return ( + + + + + + + {windowTitle} + + + + + + +
+ + + {content} + + +
+
+ + + + + + + + +
+ ); +}; + +export default MultiPaymentWindow; diff --git a/src/pages/Payment/index.js b/src/pages/Payment/index.js index 1a08143..9513b0b 100644 --- a/src/pages/Payment/index.js +++ b/src/pages/Payment/index.js @@ -1,90 +1,346 @@ import * as React from "react"; +import { lazy } from 'react'; import * as HttpUtils from "utils/HttpUtils"; import Loadable from 'components/Loadable'; -const FPS = Loadable(React.lazy(() => import('./FPS'))); +const MultiPaymentWindow = Loadable(lazy(() => import('./MultiPaymentWindow'))); +// const FPS = Loadable(React.lazy(() => import('./FPS'))); +import {useEffect, useState} from "react"; -const Index = ({amount}) => { - const getAvailablePaymentUrl = "/api/payment/availability"; - const getTransactionIdUrl = "/api/payment/transaction"; +import { + Button, + Grid, + Typography, + Stack +} from '@mui/material'; - React.useEffect({ - - }, []); - - const local = {en:"en-us", zh:"zh-hk", cn:"zh-cn"}; - const preferpaymentmethods = ['visa','mastercard','pps','creditcard','fps']; - - const getAvailablePayment = () => { - HttpUtils.post({ - url: getAvailablePaymentUrl, - params: { - "locale": local.zh, - "amount": amount, - // "eserviceids": [ - // "", "" - // ], - "preferpaymentmethods": preferpaymentmethods - }, - onSuccess: (responseData)=>{ - - let availableMethods = responseData.availablepaymentmethods; - - availableMethods.forEach((method)=>{ - if("CreditCard" === method.subtype){ +import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png' +const BackgroundHead = { + backgroundImage: `url(${titleBackgroundImg})`, + width: '100%', + height: '100%', + backgroundSize: 'contain', + backgroundRepeat: 'no-repeat', + backgroundColor: '#0C489E', + backgroundPosition: 'right' +} - } - }); +const Index = () => { + // const getAvailablePaymentUrl = "/payment/api/payment/availability"; + const getTransactionIdUrl = "/payment/api/payment/transaction"; + // const local = {en:"en-us", zh:"zh-hk", cn:"zh-cn"}; + // const preferpaymentmethods = ['visa','mastercard','pps','creditcard','fps']; + const [totalAmount,setTotalAmount] = useState(0); + const id =1; + const [availableMethods,setAvailableMethods] = useState([]); + const [transactionData,setTransactionData] = useState({}); + const [fpsStatus,setFPSStatus] = useState({}); + const [creditCardStatus,setCreditCardStatus] = useState({}); + const [unionPayStatus,setUnionPayStatus] = useState({}); + const [ppsStatus,setPPSStatus] = useState({}); - /* + //statusWindow + const [open, setOpen] = useState(false); -'pps' for PPS, ‘creditcard’ for Visa / MasterCard / -JCB / UnionPay (FI code = BCMP), and for backward -compatibility - 'visa' for Visa (FI code = BOCI), -'mastercard' for MasterCard (FI code = BOCI) + useEffect(() => { + if(id > 0 ){ + setTotalAmount(2000) + } + }, []); + const handleClose = () => { + // handleReset() + setOpen(false); + }; - { - "availablepaymentmethods": [ - { - "code": "", // e.g. "02,BCMP,ApplePay" = "PAYMENT_MTD_CODE, FI_CODE, subtype" - "subtype": "", //ApplePay, AndroidPay, Visa, MasterCard, CreditCard, PPS, eChq - "active":"",//Y/N - "pointstonote":[ - { - "type":"", - "content":"", - "order": - } , ... - ] - "supportedcard" - :[ - "",... //Visa, MasterCard - ] - },... + const paymentClick = () => { + setTotalAmount(totalAmount); + if (totalAmount>0){ + setOpen(true) + getAvailablePayment() + getTransactionId() + } + }; + + const getAvailablePayment = () => { + const responseData = { + "availablepaymentmethods": [ + { + "active": "Y", + "code": "04,BCFP,FPS", + "pointstonote": [ + { + "content": "Please take note of the transaction reference number or PRINT this page for making enquiry on the payment status when necessary.", + "order": 10, + "type": "INFO" + }, + { + "content": "After pressing the 'Pay' button, please DO NOT leave this e-service until you receive the acknowledgement page, otherwise your transaction may not be successful.", + "order": 11, + "type": "INFO" + } + ], + "subtype": "FPS" + }, + { + "active": "Y", + "code": "02,BCMP,CreditCard", + "pointstonote": [ + { + "content": "Please take note of the transaction reference number or PRINT this page for making enquiry on the payment status when necessary.", + "order": 10, + "type": "INFO" + }, + { + "content": "After pressing the 'Pay' button, please DO NOT leave this e-service until you receive the acknowledgement page, otherwise your transaction may not be successful.", + "order": 11, + "type": "INFO" + }, + { + "content": "Merchant Name is applicable to credit card payment method only.", + "order": 40, + "type": "INFO" + }, + { + "content": "Under exceptional conditions, a refund may need to be arranged. If the payment is made by Credit Card, the refund can normally be made to the Credit Card account that is used for the payment.", + "order": 41, + "type": "INFO" + }, + { + "content": "Some users may receive an error page or have to wait for several minutes before they get a response from the credit card payment gateway. If you experience such a problem, please wait a moment and retry, or change to use other available payment methods. We apologise for any inconvenience caused.", + "order": 42, + "type": "INFO" + }, + { + "content": "Different credit card issuers may have implemented different mechanisms to authenticate the cardholder's identity during online payment. Please contact your card issuer if you want to learn more about the J/Secure, Mastercard SecureCode and Verified by Visa service. ", + "order": 43, + "type": "INFO" + } + ], + "subtype": "CreditCard", + "supportedcard": [ + "JCB", + "MasterCard", + "Visa" ] - } - */ - } - }); + }, + { + "active": "N", + "code": "03,BCMP,CreditCard", + "pointstonote": [ + { + "content": "Please take note of the transaction reference number or PRINT this page for making enquiry on the payment status when necessary.", + "order": 10, + "type": "INFO" + }, + { + "content": "After pressing the 'Pay' button, please DO NOT leave this e-service until you receive the acknowledgement page, otherwise your transaction may not be successful.", + "order": 11, + "type": "INFO" + }, + { + "content": "Merchant Name is applicable to credit card payment method only.", + "order": 40, + "type": "INFO" + }, + { + "content": "Under exceptional conditions, a refund may need to be arranged. If the payment is made by Credit Card, the refund can normally be made to the Credit Card account that is used for the payment.", + "order": 41, + "type": "INFO" + }, + { + "content": "Some users may receive an error page or have to wait for several minutes before they get a response from the credit card payment gateway. If you experience such a problem, please wait a moment and retry, or change to use other available payment methods. We apologise for any inconvenience caused.", + "order": 42, + "type": "INFO" + }, + { + "content": "Different credit card issuers may have implemented different mechanisms to authenticate the cardholder's identity during online payment. Please contact your card issuer if you want to learn more about the J/Secure, Mastercard SecureCode and Verified by Visa service. ", + "order": 43, + "type": "INFO" + } + ], + "subtype": "CreditCard", + "supportedcard": [ + "UnionPay" + ] + }, + { + "active": "Y", + "code": "01,PPSB,PPS", + "pointstonote": [ + { + "content": "Please take note of the transaction reference number or PRINT this page for making enquiry on the payment status when necessary.", + "order": 10, + "type": "INFO" + }, + { + "content": "After pressing the 'Pay' button, please DO NOT leave this e-service until you receive the acknowledgement page, otherwise your transaction may not be successful.", + "order": 11, + "type": "INFO" + }, + { + "content": "PPS Shop&Buy (PPS) does not support payment via browsers of mobile devices (including mobile phones and tablets) at the moment. If you wish to pay by PPS, please change to use desktop computer. ", + "order": 21, + "type": "INFO" + } + ], + "subtype": "PPS" + } + ] + }; + let availableMethods = responseData.availablepaymentmethods; + setAvailableMethods(availableMethods); + if (availableMethods.length>0){ + availableMethods.forEach((method)=>{ + if(method.subtype === "FPS" ){ + setFPSStatus(method) + }else if (method.subtype === "CreditCard"){ + method.supportedcard.forEach((supportedcard)=>{ + if (supportedcard === "JCB" || supportedcard === "MasterCard" || supportedcard === "Visa"){ + setCreditCardStatus(method) + } else { + if (supportedcard === "UnionPay"){ + setUnionPayStatus(method) + } + } + }) + }else if (method.subtype === "PPS" ){ + setPPSStatus(method) + } + }); + } + + // HttpUtils.post({ + // url: getAvailablePaymentUrl, + // params: { + // // "locale": local.zh,; + // "amount": totalAmount, + // // "eserviceids": [ + // // "", "" + // // ], + // "preferpaymentmethods": preferpaymentmethods + // }, + // onSuccess: (responseData)=>{ + // let availableMethods = responseData.availablepaymentmethods; + // setAvailableMethods(availableMethods); + // if (availableMethods.length>0){ + // availableMethods.forEach((method)=>{ + // if(method.subtype === "FPS" ){ + // setFPSStatus(method) + // }else if (method.subtype === "CreditCard"){ + // method.supportedcard.forEach((supportedcard)=>{ + // if (supportedcard === "JCB" || supportedcard === "MasterCard" || supportedcard === "Visa"){ + // setCreditCardStatus(method) + // } else { + // if (supportedcard === "UnionPay"){ + // setUnionPayStatus(method) + // } + // } + // }) + // }else if (method.subtype === "PPS" ){ + // setPPSStatus(method) + // } + // }); + // } + // } + // }); } const getTransactionId = () => { HttpUtils.get({ url: getTransactionIdUrl, onSuccess: (responseData)=>{ - /* - { - "transactionid":"" - } - */ + const transactionData = responseData; + setTransactionData(transactionData) } }); } + // const startFPSTransaction = () => { + // HttpUtils.post({ + // url: getAvailablePaymentUrl, + // params: { + // // "locale": local.zh,; + // "amount": totalAmount, + // // "eserviceids": [ + // // "", "" + // // ], + // "preferpaymentmethods": preferpaymentmethods + // }, + // onSuccess: (responseData)=>{ + // let availableMethods = responseData.availablepaymentmethods; + // setAvailableMethods(availableMethods); + // if (availableMethods.length>0){ + // availableMethods.forEach((method)=>{ + // if(method.subtype === "FPS" ){ + // setFPSStatus(method) + // }else if (method.subtype === "CreditCard"){ + // method.supportedcard.forEach((supportedcard)=>{ + // if (supportedcard === "JCB" || supportedcard === "MasterCard" || supportedcard === "Visa"){ + // setCreditCardStatus(method) + // } else { + // if (supportedcard === "UnionPay"){ + // setUnionPayStatus(method) + // } + // } + // }) + // }else if (method.subtype === "PPS" ){ + // setPPSStatus(method) + // } + // }); + // } + // } + // }); + // } + return ( - + + +
+ + 公共啟事:付款 + +
+
+ {/*row 1*/} + + +
+ + + +
+ 支付金額 +
+ $ {totalAmount} +
+ + + + +
+
+
+ +
+ {/*row 2*/} +
); } diff --git a/src/routes/PublicUserRoutes.js b/src/routes/PublicUserRoutes.js index 8bcabc4..0ce294a 100644 --- a/src/routes/PublicUserRoutes.js +++ b/src/routes/PublicUserRoutes.js @@ -14,6 +14,7 @@ const PublicNoticeDetail = Loadable(lazy(() => import('pages/PublicNotice/Detail const ProofReply = Loadable(lazy(() => import('pages/Proof/Reply_Public'))); const ProofSearch = Loadable(lazy(() => import('pages/Proof/Search_Public'))); const ProofPayment = Loadable(lazy(() => import('pages/Proof/Payment'))); +const Payment_Multi = Loadable(lazy(() => import('pages/Payment'))); const Payment_FPS = Loadable(lazy(() => import('pages/Payment/FPS'))); // ==============================|| MAIN ROUTING ||============================== // @@ -61,6 +62,10 @@ const PublicDashboard = { path: 'proof/pay/:id', element: }, + { + path: 'payment', + element: + }, { path: 'payment/fps', element: