import { useEffect, useState } from "react"; import * as React from "react"; // material-ui import { Button, FormLabel, Stack, Typography, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, Grid, Box } from '@mui/material'; import { useFormik, FormikProvider } from 'formik'; import * as yup from 'yup'; import Loadable from 'components/Loadable'; const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent'))); import * as FormatUtils from "utils/FormatUtils"; import VisaIcon from "assets/images/icons/visacard.svg"; import MasterIcon from "assets/images/icons/mastercard.svg"; import JcbIcon from "assets/images/icons/jcb.svg"; import UnionPayIcon from "assets/images/icons/unionpay.svg"; import PpsIcon from "assets/images/icons/ppshk.svg"; import FpsIcon from "assets/images/icons/fps.svg"; import {FormattedMessage, useIntl} from "react-intl"; const MultiPaymentWindow = (props) => { const intl = useIntl(); const windowTitle = intl.formatMessage({id: 'selectPaymentMethod'}); // const [content, setContent] = useState(); const [loadtTransactionData, setLoadtTransactionData] = useState({}); const [loadAvailableMethodData, setLoadAvailableMethodData] = useState([]); const [paymentMethod, setPaymentMethod] = useState(""); const [transactionData, setTransactionData] = useState({}); const [availableMethodData, setAvailableMethodData] = useState([]); const [fpsClass, setFpsClass] = useState(""); const [visaClass, setVisaClass] = useState(""); const [mastercardClass, setMastercardClass] = useState(""); const [jCBClass, setJCBClass] = useState(""); const [unionPayClass, setUnionPayClass] = useState(""); const [pPSClass, setPPSlass] = useState(""); const [filteredPaymentMethod, setFilteredPaymentMethod] = useState([]); // const [onReady, setOnReady] = useState(false); useEffect(() => { // console.log(props.transactionData) if(Object.keys(props.transactionData).length > 0){ setLoadtTransactionData(props.transactionData) } }, [props.transactionData]); useEffect(() => { // console.log(props.availableMethods) if(props.availableMethods.length > 0){ setLoadAvailableMethodData(props.availableMethods) } }, [props.availableMethods]); useEffect(() => { if(Object.keys(loadtTransactionData).length > 0){ setTransactionData(loadtTransactionData) } }, [loadtTransactionData]); useEffect(() => { if(Object.keys(transactionData).length > 0&&props.availableMethods.length > 0){ setLoadAvailableMethodData(props.availableMethods) } }, [transactionData]); useEffect(() => { if(loadAvailableMethodData.length > 0){ setAvailableMethodData(loadAvailableMethodData) } }, [loadAvailableMethodData]); // useEffect(() => { // if(availableMethodData.length > 0 && Object.keys(transactionData).length > 0){ // setOnReady(true) // } // }, [availableMethodData]); useEffect(() => { // console.log(paymentMethod) // const subtype = (paymentMethod === "Visa" || paymentMethod === "MasterCard" || paymentMethod === "JCB" || paymentMethod === "UnionPay") ? "CreditCard" : paymentMethod; // const filteredPaymentMethod = availableMethodData.filter(obj => obj.subtype === subtype); const filteredPaymentMethod = availableMethodData.filter(obj => { if (obj.supportedcard && obj.supportedcard.includes(paymentMethod)) { return obj.subtype === "CreditCard"; } return obj.subtype === paymentMethod; }); // console.log(filteredPaymentMethod) setFilteredPaymentMethod(filteredPaymentMethod); setFpsClass(paymentMethod == "FPS" || paymentMethod == "" ? "" : "grayscale") setVisaClass(paymentMethod == "Visa" || paymentMethod == "" ? "" : "grayscale") setMastercardClass(paymentMethod == "MasterCard" || paymentMethod == "" ? "" : "grayscale") setJCBClass(paymentMethod == "JCB" || paymentMethod == "" ? "" : "grayscale") setUnionPayClass(paymentMethod == "UnionPay" || paymentMethod == "" ? "" : "grayscale") setPPSlass(paymentMethod == "PPS" || paymentMethod == "" ? "" : "grayscale") // getMethodImgClass(paymentMethod) }, [paymentMethod]); const selectedPaymentMethodHandle = (method) => () =>{ setPaymentMethod(method) props.setSelectedPaymentMethod(method); }; const confirmPaymentHandle = () => () =>{ props.setConfirmPayment(true); }; useEffect(() => { if(props.selectedPaymentMethod === ""){ setPaymentMethod("") } }, [availableMethodData]); const formik = useFormik({ initialValues: ({ username: '', }), validationSchema: yup.object().shape({ }), }); return ( props.setOpen(false)} fullWidth={true} maxWidth={'xl'} > {windowTitle}
: {transactionData.transactionid} {/* 支付金額: HK$ {FormatUtils.currencyFormat(props.totalAmount)} */} {!props.onReady ? :availableMethodData.length>0? : {paymentMethod !=""? {paymentMethod} : null} : } (HK$):  {" HK$ " + FormatUtils.currencyFormat(props.totalAmount)} {paymentMethod !=""? filteredPaymentMethod.map((availableMethod) => { return ( {availableMethod.pointstonote.map((pointstonote) => { return ( {pointstonote.content} ); })} ); }) : null}
); }; export default MultiPaymentWindow;