You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

399 line
18 KiB

  1. import {
  2. useEffect,
  3. useState
  4. } from "react";
  5. import * as React from "react";
  6. import {getBowserType} from "auth/utils";
  7. // material-ui
  8. import {
  9. Button,
  10. FormLabel,
  11. Stack,
  12. Typography,
  13. Dialog,
  14. DialogActions,
  15. DialogContent,
  16. DialogContentText,
  17. DialogTitle,
  18. Grid,
  19. Box
  20. } from '@mui/material';
  21. import { useFormik, FormikProvider } from 'formik';
  22. import * as yup from 'yup';
  23. import Loadable from 'components/Loadable';
  24. const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent')));
  25. import * as FormatUtils from "utils/FormatUtils";
  26. import VisaIcon from "assets/images/icons/visacard.svg";
  27. import MasterIcon from "assets/images/icons/mastercard.svg";
  28. import JcbIcon from "assets/images/icons/jcb.svg";
  29. import UnionPayIcon from "assets/images/icons/unionpay.svg";
  30. import PpsIcon from "assets/images/icons/ppshk.svg";
  31. import FpsIcon from "assets/images/icons/fps.svg";
  32. import {FormattedMessage, useIntl} from "react-intl";
  33. const MultiPaymentWindow = (props) => {
  34. const intl = useIntl();
  35. const windowTitle = intl.formatMessage({id: 'selectPaymentMethod'});
  36. // const [content, setContent] = useState();
  37. const [loadtTransactionData, setLoadtTransactionData] = useState({});
  38. const [loadAvailableMethodData, setLoadAvailableMethodData] = useState([]);
  39. const [paymentMethod, setPaymentMethod] = useState("");
  40. const [isLimit, setIsLimit] = useState(false);
  41. const [isPPSLimit, setIsPPSLimit] = useState(false);
  42. const [transactionData, setTransactionData] = useState({});
  43. const [availableMethodData, setAvailableMethodData] = useState([]);
  44. const [fpsClass, setFpsClass] = useState("");
  45. const [visaClass, setVisaClass] = useState("");
  46. const [mastercardClass, setMastercardClass] = useState("");
  47. const [jCBClass, setJCBClass] = useState("");
  48. const [unionPayClass, setUnionPayClass] = useState("");
  49. const [pPSClass, setPPSlass] = useState("");
  50. const [filteredPaymentMethod, setFilteredPaymentMethod] = useState([]);
  51. const [onReady, setOnReady] = useState(false);
  52. useEffect(() => {
  53. // console.log(props.transactionData)
  54. if(Object.keys(props.transactionData).length > 0){
  55. setLoadtTransactionData(props.transactionData)
  56. }
  57. }, [props.transactionData]);
  58. useEffect(() => {
  59. // console.log(props.availableMethods)
  60. if(props.availableMethods.length > 0){
  61. setLoadAvailableMethodData(props.availableMethods)
  62. }
  63. }, [props.availableMethods]);
  64. useEffect(() => {
  65. if(Object.keys(loadtTransactionData).length > 0){
  66. setTransactionData(loadtTransactionData)
  67. }
  68. }, [loadtTransactionData]);
  69. useEffect(() => {
  70. if(Object.keys(transactionData).length > 0&&props.availableMethods.length > 0){
  71. setLoadAvailableMethodData(props.availableMethods)
  72. }
  73. }, [transactionData]);
  74. useEffect(() => {
  75. if(loadAvailableMethodData.length > 0){
  76. setAvailableMethodData(loadAvailableMethodData)
  77. }
  78. }, [loadAvailableMethodData]);
  79. useEffect(() => {
  80. if(filteredPaymentMethod!= undefined && filteredPaymentMethod.length>0){
  81. setOnReady(true)
  82. } else if(filteredPaymentMethod!= undefined && Object.keys(filteredPaymentMethod).length > 0){
  83. setOnReady(true)
  84. }
  85. }, [filteredPaymentMethod]);
  86. useEffect(() => {
  87. const availableMethod = availableMethodData;
  88. if(props.availableMethods.length > 0){
  89. const filteringPaymentMethod = availableMethod.filter(obj => {
  90. if (obj.supportedcard && obj.supportedcard.includes(paymentMethod)) {
  91. return obj.subtype === "CreditCard";
  92. }
  93. return obj.subtype === paymentMethod;
  94. });
  95. if (isLimit && filteringPaymentMethod!= undefined && filteringPaymentMethod.length>0){
  96. if (paymentMethod == "FPS" || paymentMethod == "PPS"){
  97. filteringPaymentMethod[0].pointstonote = paymentMethod + intl.formatMessage({id: 'paymentLimitPrice1'})
  98. setFilteredPaymentMethod(filteringPaymentMethod[0]);
  99. } else if (isLimit) {
  100. filteringPaymentMethod[0].pointstonote = paymentMethod + intl.formatMessage({id: 'paymentLimitPrice2'})
  101. setFilteredPaymentMethod(filteringPaymentMethod[0]);
  102. }
  103. }
  104. if (!isLimit && filteringPaymentMethod!= undefined && filteringPaymentMethod.length>0){
  105. setFilteredPaymentMethod(filteringPaymentMethod);
  106. }
  107. if(isPPSLimit && filteringPaymentMethod!= undefined && filteringPaymentMethod.length>0 && paymentMethod =="PPS"){
  108. filteringPaymentMethod[0].pointstonote = paymentMethod + intl.formatMessage({id: 'paymentLimitPPS'})
  109. setFilteredPaymentMethod(filteringPaymentMethod[0]);
  110. }
  111. setFpsClass(paymentMethod == "FPS" || paymentMethod == "" ? "" : "grayscale")
  112. setVisaClass(paymentMethod == "Visa" || paymentMethod == "" ? "" : "grayscale")
  113. setMastercardClass(paymentMethod == "MasterCard" || paymentMethod == "" ? "" : "grayscale")
  114. setJCBClass(paymentMethod == "JCB" || paymentMethod == "" ? "" : "grayscale")
  115. setUnionPayClass(paymentMethod == "UnionPay" || paymentMethod == "" ? "" : "grayscale")
  116. setPPSlass(paymentMethod == "PPS" || paymentMethod == "" ? "" : "grayscale")
  117. }
  118. }, [paymentMethod]);
  119. const selectedPaymentMethodHandle = (method) => () =>{
  120. if (method != paymentMethod){
  121. resetForm()
  122. let totalAmount = props.totalAmount;
  123. // totalAmount = 99999999.99
  124. // totalAmount = 0.01
  125. const paymentLimitList = props.paymentLimit
  126. let limitRecordList;
  127. switch (method) {
  128. case "Visa":
  129. case "JCB":
  130. case "MasterCard":
  131. limitRecordList = paymentLimitList.creditCardLimitRecord;
  132. break;
  133. case "FPS":
  134. limitRecordList = paymentLimitList.fpsLimitRecord;
  135. break;
  136. case "PPS":
  137. limitRecordList = paymentLimitList.ppsbLimitRecord;
  138. break;
  139. case "UnionPay":
  140. limitRecordList = paymentLimitList.unionPlayLimitRecord;
  141. break;
  142. default:
  143. break;
  144. }
  145. if (totalAmount >= limitRecordList.minLimit && totalAmount <= limitRecordList.maxLimit) {
  146. setIsLimit(false)
  147. } else {
  148. setIsLimit(true)
  149. }
  150. if (getBowserType() === "PC_Browser"){
  151. setPaymentMethod(method)
  152. props.setSelectedPaymentMethod(method);
  153. setIsPPSLimit(false)
  154. } else if (getBowserType() !== "PC_Browser" && method !== "PPS"){
  155. setPaymentMethod(method)
  156. props.setSelectedPaymentMethod(method);
  157. } else {
  158. setPaymentMethod(method)
  159. setIsPPSLimit(true)
  160. }
  161. }
  162. };
  163. const confirmPaymentHandle = () => () =>{
  164. props.setConfirmPayment(true);
  165. };
  166. const closeHandle = () => () =>{
  167. resetForm()
  168. props.setOpen(false)
  169. };
  170. const resetForm = () =>{
  171. setOnReady(false)
  172. setPaymentMethod("")
  173. setFilteredPaymentMethod([])
  174. setIsLimit(false)
  175. setIsPPSLimit(false)
  176. };
  177. useEffect(() => {
  178. if(props.selectedPaymentMethod === ""){
  179. setPaymentMethod("")
  180. }
  181. }, [availableMethodData]);
  182. const formik = useFormik({
  183. initialValues: ({
  184. username: '',
  185. }),
  186. validationSchema: yup.object().shape({
  187. }),
  188. });
  189. return (
  190. <Dialog
  191. open={props.open}
  192. onClose={() => props.setOpen(false)}
  193. fullWidth={true}
  194. maxWidth={'xl'}
  195. fullScreen={props.isFullScreen}
  196. >
  197. <DialogTitle >
  198. <Grid container>
  199. <Grid item>
  200. <Stack direction="row" justifyContent="flex-start" alignItems="center">
  201. <Typography variant="h4">
  202. {windowTitle}
  203. </Typography>
  204. </Stack>
  205. </Grid>
  206. </Grid>
  207. </DialogTitle>
  208. <FormikProvider value={formik}>
  209. <form>
  210. <DialogContent>
  211. <DialogContentText>
  212. <Grid item xs={12} md={12} sx={{ pt: 2 }} style={{ height: '100%' }} width="100%">
  213. <Box xs={12} md={12} sx={{ p: 4, border: '3px solid #eee', borderRadius: '10px' }} >
  214. <Grid container justifyContent="flex-start" alignItems="left" >
  215. <center>
  216. <Grid item xs={12} md={12} width="100%">
  217. <Typography variant="h5" sx={{ textAlign: "left" }}>
  218. <FormattedMessage id="transactionRefNo"/>: {transactionData.transactionid}
  219. </Typography>
  220. {/* <Typography variant="h5" sx={{ textAlign: "left" }}>
  221. 支付金額: HK$ {FormatUtils.currencyFormat(props.totalAmount)}
  222. </Typography> */}
  223. {!props.onReady ?
  224. <LoadingComponent />
  225. :availableMethodData.length>0?
  226. <Grid container spacing={2} direction="column" justifyContent="space-between" alignItems="flex-start">
  227. <Grid item xs={12} md={12}>
  228. <Grid container spacing={1} direction="row" justifyContent="flex-start" alignItems="center">
  229. <Grid item>
  230. <Typography variant="h5" sx={{ textAlign: "left" }}>
  231. <FormattedMessage id="selectPaymentMethod"/>:
  232. </Typography>
  233. </Grid>
  234. <Grid item sx={{display: { sm: 'block', md: 'none' }}}></Grid>
  235. <Grid item>
  236. <Button variant="contained" color="white" onClick={selectedPaymentMethodHandle("FPS")} disabled={props.fpsStatus.active === "N"}>
  237. <img className={fpsClass} src={FpsIcon} width="80" height="80" alt="FPS"></img>
  238. </Button>
  239. </Grid>
  240. <Grid item>
  241. <Button variant="contained" color="white" onClick={selectedPaymentMethodHandle("Visa")} disabled={props.creditCardStatus.active === "N"}>
  242. <img className={visaClass} src={VisaIcon} width="80" height="80" alt="Visa"></img>
  243. </Button>
  244. </Grid>
  245. <Grid item>
  246. <Button variant="contained" color="white" onClick={selectedPaymentMethodHandle("MasterCard")} disabled={props.creditCardStatus.active === "N"}>
  247. <img className={mastercardClass} src={MasterIcon} width="80" height="80" alt="MasterCard"></img>
  248. </Button>
  249. </Grid>
  250. <Grid item>
  251. <Button variant="contained" color="white" onClick={selectedPaymentMethodHandle("UnionPay")} disabled={props.unionPayStatus.active === "N"}>
  252. <img className={unionPayClass} src={UnionPayIcon} width="80" height="80" alt="UnionPay"></img>
  253. </Button>
  254. </Grid>
  255. <Grid item>
  256. <Button variant="contained" color="white" onClick={selectedPaymentMethodHandle("JCB")} disabled={props.unionPayStatus.active === "N"}>
  257. <img className={jCBClass} src={JcbIcon} width="80" height="80" alt="JCB"></img>
  258. </Button>
  259. </Grid>
  260. <Grid item>
  261. <Button variant="contained" color="white" onClick={selectedPaymentMethodHandle("PPS")} disabled={props.ppsStatus.active === "N"}>
  262. <img className={pPSClass} src={PpsIcon} width="80" height="80" alt="PPS"></img>
  263. </Button>
  264. </Grid>
  265. </Grid>
  266. </Grid>
  267. {paymentMethod !=""?
  268. <Grid item xs={12} md={12}>
  269. <Grid container direction="row" justifyContent="flex-start" alignItems="center">
  270. <Grid item>
  271. <FormLabel sx={{ fontSize: "20px", color: "#000000", textAlign: "center" }}>
  272. <FormattedMessage id="selectedPaymentMethod"/>:&nbsp;
  273. </FormLabel>
  274. </Grid>
  275. <Grid item>
  276. <FormLabel sx={{ fontSize: "20px", color: "#000000", textAlign: "center" }}>
  277. {paymentMethod}
  278. </FormLabel>
  279. </Grid>
  280. </Grid>
  281. </Grid>
  282. : null}
  283. </Grid>:
  284. <Grid container direction="row" justifyContent="center" alignItems="center">
  285. <FormLabel sx={{ fontSize: "20px", color: "#000000", textAlign: "center"}}>
  286. <FormattedMessage id="paymentMethodNotAvailable"/>。
  287. </FormLabel>
  288. </Grid>
  289. }
  290. </Grid>
  291. <Grid item xs={12} md={12}>
  292. <Grid container >
  293. <Grid item>
  294. <Typography variant="pnspsFormParagraphBold" sx={{ color: "#000000", textAlign: "left" }}>
  295. <FormattedMessage id="payTotal"/>(HK$):&nbsp;
  296. </Typography>
  297. </Grid>
  298. <Grid item>
  299. <Typography variant="pnspsFormParagraphBold" sx={{color: "#000000", textAlign: "left" }}>
  300. {" HK$ " + FormatUtils.currencyFormat(props.totalAmount)}
  301. </Typography>
  302. </Grid>
  303. </Grid>
  304. {paymentMethod === "" ?
  305. paymentMethod !="" && !onReady ? <LoadingComponent/> : null
  306. :
  307. !isLimit?
  308. !onReady? <LoadingComponent/> :
  309. !isLimit?
  310. filteredPaymentMethod.map((availableMethod) => {
  311. return (
  312. <Grid container key={availableMethod.subtype} className={"css-1tx0bae"} sx={{ mt: 1, p:2 }}>
  313. {
  314. availableMethod.pointstonote.map((pointstonote) => {
  315. return (
  316. <Grid container key={pointstonote.order} sx={{ p:0.5 }} direction="row" justifyContent="flex-start" alignItems="center">
  317. <Grid item>
  318. <Typography sx={{fontSize: "16px", color: "#000000", textAlign: "left" }}>
  319. {pointstonote.content}
  320. </Typography>
  321. </Grid>
  322. </Grid>
  323. );
  324. })
  325. }
  326. </Grid>
  327. );
  328. })
  329. : null
  330. :
  331. !onReady? <LoadingComponent/> :
  332. <Grid container className={"css-1tx0bae"} sx={{ mt: 1, p:2 }}>
  333. <Grid container sx={{ p:0.5 }} direction="row" justifyContent="flex-start" alignItems="center">
  334. <Grid item>
  335. <Typography color="error" sx={{fontSize: "16px", textAlign: "left" }}>
  336. {filteredPaymentMethod.pointstonote}
  337. </Typography>
  338. </Grid>
  339. </Grid>
  340. </Grid>
  341. }
  342. </Grid>
  343. </center>
  344. </Grid>
  345. </Box>
  346. </Grid>
  347. </DialogContentText>
  348. </DialogContent>
  349. </form>
  350. </FormikProvider>
  351. <Stack direction="row" justifyContent="space-around">
  352. <DialogActions>
  353. <Button variant="contained" onClick={closeHandle()} autoFocus >
  354. <FormattedMessage id="cancel"/>
  355. </Button>
  356. </DialogActions>
  357. <DialogActions>
  358. <Button variant="contained" color="success" onClick={confirmPaymentHandle()} disabled={paymentMethod === "" || isLimit || isPPSLimit}>
  359. <FormattedMessage id="pay"/>
  360. </Button>
  361. </DialogActions>
  362. </Stack>
  363. </Dialog>
  364. );
  365. };
  366. export default MultiPaymentWindow;