// material-ui import { Grid, Typography, Stack, Button, } from '@mui/material'; import * as React from "react"; import * as HttpUtils from "utils/HttpUtils"; import { useNavigate } from "react-router-dom"; import { useLocation } from 'react-router-dom'; import {paymentPath} from "auth/utils"; // import {poll} from "utils/Utils"; 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 Loadable from 'components/Loadable'; const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent'))); 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 navigate = useNavigate() const location = useLocation(); const [paymentData, setPaymentData] = React.useState({}); const [onReady, setOnReady] = React.useState(false); const [fpsmerchanttimeoutdatetime, setFpsmerchanttimeoutdatetime] = React.useState(""); const [redirecturl, setRedirectUrl] = React.useState(""); // const [paymentstatuscode, setPaymentstatuscode] = React.useState(""); // const [fpsqrcodeurl, setFpsqrcodeurl] = React.useState(""); // const pasgPath = 'https://fps.payapps.hkicl.com.hk'; //PRD // const pasgPath = 'https://sim.fps.payapps.hkicl.com.hk'; //Testing const loadPaymentUrl = "/api/payment/web/"; const cancelPaymentUrl = "/api/payment/cancelpayment"; // const paymentStatusApi = "/api/payment/status/"; // const payloadUrl = "/api/payment/wallet/fps/enquiryfpspayload/"; // const receiverUrl = "/noti-api/payment/payment-notification"; //timer const currentTimer = React.useRef(); const [time, setTime] = React.useState(0); React.useEffect(() => { if (location.state != undefined) { setPaymentData(location.state) } loadForm(); currentTimer.current = setInterval(() => { getPaymentStatus(); setTime((prevTime) => prevTime + 1); }, 500); return () => clearInterval(currentTimer.current); }, []); React.useEffect(() => { setOnReady(true); }, [redirecturl]); const loadForm = () => { const timeoutdatetime = "2023-10-26T09:04:30Z[UTC]" const convertedDateString = timeoutdatetime.replace("[UTC]", ""); setFpsmerchanttimeoutdatetime(convertedDateString) HttpUtils.post({ url: paymentPath+loadPaymentUrl+(paymentData.type=="PPS"?"pps":"creditcard"), params:{ "transactionid": paymentData.transactionid, "apprefid:": paymentData.transactionid, "webtoken": paymentData.webtoken, "paymentmethod":paymentData.paymentMethod, "order": { "totalamount":paymentData.amount, "currency":"HKD", "orderdetail": [ { "itemid": "1", "qty":"1", "unitprice":paymentData.amount, "amount":paymentData.amount }, ] }, // "locale":"", // "eserviceid":"", "returnurl": window.location.hostname+"/payment/success" }, onSuccess: function(responseData){ /* { "transactionid": "", "redirecturl": "" } */ setRedirectUrl(responseData.redirecturl); window.open(redirecturl); } }); } const getPaymentStatus = () => { // HttpUtils.post({ // url: paymentPath+paymentStatusApi+paymentid, // params:{ // "apprefid": paymentData.transactionid, // "webtoken": paymentData.webtoken, // }, // onSuccess: function(responseData){ // const paymentstatuscode = responseData.paymentdetail.result.paymentstatuscode; // if (paymentstatuscode === 'APPR') { // const timestamp = '?t=' + Date.now(); // window.top.location.href = paymentPath + payment.config.ackPagePath + timestamp; // } else if (paymentstatuscode === 'CANC') { // window.top.location.href = paymentPath + payment.config.indexPagePath; // } else { // window.top.location.href = paymentPath + payment.config.errPagePath; // } // }, // onError: function(){ // cancelPayment() // clearInterval(currentTimer.current); // } // }); }; React.useEffect(() => { const timeOutDate = new Date(fpsmerchanttimeoutdatetime); const currentTime = new Date; if (timeOutDate.getTime() < currentTime.getTime()) { console.log("stop"); clearInterval(currentTimer.current); } }, [time]) const cancelPayment = () => { HttpUtils.post({ url: paymentPath + cancelPaymentUrl, params: { "transactionid": paymentData.transactionid, "webtoken": paymentData.webtoken, "paymentid": paymentid }, onSuccess: function () { navigate("/dashboard"); } }); } // const getPayload = ()=>{ // HttpUtils.get({ // url: payloadUrl+"", // onSuccess: function(responseData){ // /* // { // "payload": "" // } // */ // } // }); // } // const getReceiver = ()=>{ // HttpUtils.get({ // url: receiverUrl+"", // onSuccess: function(responseData){ // /* // { // "payload": "" // } // */ // } // }); // } const getIcon = () => { if(paymentData.type=="Visa") return VisaIcon; if(paymentData.type=="Mastercard") return MasterIcon; if(paymentData.type=="UnionPay") return UnionPayIcon; if(paymentData.type=="JCB") return JcbIcon; if(paymentData.type=="PPS") return PpsIcon; } return ( !onReady ? : (
公共啟事: 信用卡付款
{/*row 1*/}
{paymentData.type}
支付金額
{"$HK " + paymentData.amount}
{/*row 2*/}
) ); } export default Index;