25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 

568 satır
30 KiB

  1. import * as React from "react";
  2. import * as HttpUtils from "utils/HttpUtils";
  3. import * as UrlUtils from "utils/ApiPathConst";
  4. import Loadable from 'components/Loadable';
  5. // const MultiPaymentWindow = Loadable(React.lazy(() => import('./MultiPaymentWindow')));
  6. const DataGrid = Loadable(React.lazy(() => import('./Details_Public/DataGrid')));
  7. // const FPS = Loadable(React.lazy(() => import('./FPS')));
  8. import { useEffect, useState } from "react";
  9. import { useNavigate, useLocation } from "react-router-dom";
  10. import { paymentPath } from "auth/utils";
  11. import * as FormatUtils from "utils/FormatUtils";
  12. const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent')));
  13. import {
  14. Button,
  15. Grid,
  16. Typography,
  17. Stack,
  18. Box,
  19. Dialog, DialogTitle, DialogContent, DialogActions,
  20. } from '@mui/material';
  21. //icon
  22. import VisaIcon from "assets/images/icons/visacard.svg";
  23. import MasterIcon from "assets/images/icons/mastercard.svg";
  24. import JcbIcon from "assets/images/icons/jcb.svg";
  25. import UnionPayIcon from "assets/images/icons/unionpay.svg";
  26. import PpsIcon from "assets/images/icons/ppshk.svg";
  27. import FpsIcon from "assets/images/icons/fps.svg";
  28. import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png'
  29. const BackgroundHead = {
  30. backgroundImage: `url(${titleBackgroundImg})`,
  31. width: '100%',
  32. height: '100%',
  33. backgroundSize: 'contain',
  34. backgroundRepeat: 'no-repeat',
  35. backgroundColor: '#0C489E',
  36. backgroundPosition: 'right'
  37. }
  38. const Index = () => {
  39. const getAvailablePaymentUrl = "/api/payment/availability";
  40. const getTransactionIdUrl = "/api/payment/transaction";
  41. const navigate = useNavigate()
  42. const location = useLocation();
  43. // const local = {en:"en-us", zh:"zh-hk", cn:"zh-cn"};
  44. const preferpaymentmethods = ['visa', 'mastercard', 'pps', 'creditcard', 'fps'];
  45. const [totalAmount, setTotalAmount] = useState(0);
  46. const [appIds, setAppIds] = useState([]);
  47. //statusWindow
  48. // const [open, setOpen] = useState(false);
  49. const [availableMethods, setAvailableMethods] = useState([]);
  50. const [transactionData, setTransactionData] = useState({});
  51. const [fpsStatus, setFPSStatus] = useState({});
  52. const [creditCardStatus, setCreditCardStatus] = useState({});
  53. const [unionPayStatus, setUnionPayStatus] = useState({});
  54. const [ppsStatus, setPPSStatus] = useState({});
  55. const [selectedPaymentMethod, setSelectedPaymentMethod] = useState("");
  56. const [confirmPayment, setConfirmPayment] = useState(false);
  57. const [itemList, setItemList] = useState([]);
  58. const [onReady, setOnReady] = useState(false);
  59. const [expiryDateErrText, setExpiryDateErrText] = React.useState("");
  60. const [expiryDateErr, setExpiryDateErr] = React.useState(false);
  61. useEffect(() => {
  62. setAppIds(location.state?.appIdList ?? [])
  63. setTotalAmount(location.state?.amount ?? 2000)
  64. getAvailablePayment()
  65. getTransactionId()
  66. }, []);
  67. useEffect(() => {
  68. if (appIds != [] && appIds.length > 0)
  69. getAppList();
  70. }, [appIds]);
  71. // const handleClose = () => {
  72. // // handleReset()
  73. // setOpen(false);
  74. // getTransactionId()
  75. // getAvailablePayment()
  76. // };
  77. // const paymentClick = () => {
  78. // setTotalAmount(totalAmount);
  79. // setSelectedPaymentMethod("")
  80. // setConfirmPayment(false)
  81. // if (totalAmount > 0) {
  82. // getTransactionId()
  83. // // setOpen(true)
  84. // }
  85. // };
  86. useEffect(() => {
  87. if (confirmPayment) {
  88. // setOpen(false);
  89. // let transactionid = "";
  90. // let webtoken = "";
  91. let page = "";
  92. let stateParams = {};
  93. let paymentMethod = "";
  94. if (selectedPaymentMethod === "FPS") {
  95. page = '/paymentPage/fps';
  96. stateParams = { state: { amount: totalAmount, transactionid: transactionData.transactionid, webtoken: transactionData.webtoken } }
  97. paymentMethod = "04,BCFP,FPS";
  98. } else if (selectedPaymentMethod === "Visa") {
  99. page = '/paymentPage/card';
  100. stateParams = { state: { amount: totalAmount, transactionid: transactionData.transactionid, webtoken: transactionData.webtoken, type: "Visa", paymentMethod: "02,BCMP,CreditCard" } }
  101. paymentMethod = "02,BCMP,CreditCard";
  102. } else if (selectedPaymentMethod === "Mastercard") {
  103. page = '/paymentPage/card';
  104. stateParams = { state: { amount: totalAmount, transactionid: transactionData.transactionid, webtoken: transactionData.webtoken, type: "Mastercard", paymentMethod: "02,BCMP,CreditCard" } }
  105. paymentMethod = "02,BCMP,CreditCard";
  106. } else if (selectedPaymentMethod === "JCB") {
  107. page = '/paymentPage/card';
  108. stateParams = { state: { amount: totalAmount, transactionid: transactionData.transactionid, webtoken: transactionData.webtoken, type: "JCB", paymentMethod: "02,BCMP,CreditCard" } }
  109. paymentMethod = "02,BCMP,CreditCard";
  110. } else if (selectedPaymentMethod === "UnionPay") {
  111. page = '/paymentPage/card';
  112. stateParams = { state: { amount: totalAmount, transactionid: transactionData.transactionid, webtoken: transactionData.webtoken, type: "UnionPay", paymentMethod: "03,BCMP,CreditCard" } }
  113. paymentMethod = "03,BCMP,CreditCard";
  114. } else if (selectedPaymentMethod === "PPS") {
  115. page = '/paymentPage/card';
  116. stateParams = { state: { amount: totalAmount, transactionid: transactionData.transactionid, webtoken: transactionData.webtoken, type: "PPS", paymentMethod: "01,PPSB,PPS" } }
  117. paymentMethod = "01,PPSB,PPS";
  118. }
  119. if (paymentMethod != "") {
  120. HttpUtils.post({
  121. url: UrlUtils.PAYMENT_CREATE,
  122. params: {
  123. transNo: transactionData.transactionid,
  124. payMethod: paymentMethod,
  125. payAmount: totalAmount,
  126. appIdList: location.state?.appIdList ?? []
  127. },
  128. onSuccess: function (responData) {
  129. localStorage.removeItem("paymentId");
  130. localStorage.setItem("paymentId", responData.id)
  131. navigate(page, stateParams);
  132. }
  133. });
  134. }
  135. }
  136. }, [confirmPayment]);
  137. const getAvailablePayment = () => {
  138. HttpUtils.post({
  139. url: paymentPath + getAvailablePaymentUrl,
  140. params: {
  141. // "locale": local.zh,;
  142. "amount": totalAmount,
  143. // "eserviceids": [
  144. // "<eserviceid>", "<eserviceid>"
  145. // ],
  146. "preferpaymentmethods": preferpaymentmethods
  147. },
  148. onSuccess: (responseData) => {
  149. let availableMethods = responseData.availablepaymentmethods;
  150. setAvailableMethods(availableMethods);
  151. }
  152. });
  153. // const responseData = {
  154. // "availablepaymentmethods": [
  155. // {
  156. // "active": "Y",
  157. // "code": "04,BCFP,FPS",
  158. // "pointstonote": [
  159. // {
  160. // "content": "Please take note of the transaction reference number or PRINT this page for making enquiry on the payment status when necessary.",
  161. // "order": 10,
  162. // "type": "INFO"
  163. // },
  164. // {
  165. // "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.",
  166. // "order": 11,
  167. // "type": "INFO"
  168. // }
  169. // ],
  170. // "subtype": "FPS"
  171. // },
  172. // {
  173. // "active": "Y",
  174. // "code": "02,BCMP,CreditCard",
  175. // "pointstonote": [
  176. // {
  177. // "content": "Please take note of the transaction reference number or PRINT this page for making enquiry on the payment status when necessary.",
  178. // "order": 10,
  179. // "type": "INFO"
  180. // },
  181. // {
  182. // "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.",
  183. // "order": 11,
  184. // "type": "INFO"
  185. // },
  186. // {
  187. // "content": "Merchant Name is applicable to credit card payment method only.",
  188. // "order": 40,
  189. // "type": "INFO"
  190. // },
  191. // {
  192. // "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.",
  193. // "order": 41,
  194. // "type": "INFO"
  195. // },
  196. // {
  197. // "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.",
  198. // "order": 42,
  199. // "type": "INFO"
  200. // },
  201. // {
  202. // "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. ",
  203. // "order": 43,
  204. // "type": "INFO"
  205. // }
  206. // ],
  207. // "subtype": "CreditCard",
  208. // "supportedcard": [
  209. // "JCB",
  210. // "MasterCard",
  211. // "Visa"
  212. // ]
  213. // },
  214. // {
  215. // "active": "Y",
  216. // "code": "03,BCMP,CreditCard",
  217. // "pointstonote": [
  218. // {
  219. // "content": "Please take note of the transaction reference number or PRINT this page for making enquiry on the payment status when necessary.",
  220. // "order": 10,
  221. // "type": "INFO"
  222. // },
  223. // {
  224. // "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.",
  225. // "order": 11,
  226. // "type": "INFO"
  227. // },
  228. // {
  229. // "content": "Merchant Name is applicable to credit card payment method only.",
  230. // "order": 40,
  231. // "type": "INFO"
  232. // },
  233. // {
  234. // "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.",
  235. // "order": 41,
  236. // "type": "INFO"
  237. // },
  238. // {
  239. // "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.",
  240. // "order": 42,
  241. // "type": "INFO"
  242. // },
  243. // {
  244. // "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. ",
  245. // "order": 43,
  246. // "type": "INFO"
  247. // }
  248. // ],
  249. // "subtype": "CreditCard",
  250. // "supportedcard": [
  251. // "UnionPay"
  252. // ]
  253. // },
  254. // {
  255. // "active": "Y",
  256. // "code": "01,PPSB,PPS",
  257. // "pointstonote": [
  258. // {
  259. // "content": "Please take note of the transaction reference number or PRINT this page for making enquiry on the payment status when necessary.",
  260. // "order": 10,
  261. // "type": "INFO"
  262. // },
  263. // {
  264. // "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.",
  265. // "order": 11,
  266. // "type": "INFO"
  267. // },
  268. // {
  269. // "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. ",
  270. // "order": 21,
  271. // "type": "INFO"
  272. // }
  273. // ],
  274. // "subtype": "PPS"
  275. // }
  276. // ]
  277. // };
  278. // let availableMethods = responseData.availablepaymentmethods;
  279. // setAvailableMethods(availableMethods);
  280. // if (availableMethods.length>0){
  281. // availableMethods.forEach((method)=>{
  282. // if(method.subtype === "FPS" ){
  283. // setFPSStatus(method)
  284. // }else if (method.subtype === "CreditCard"){
  285. // method.supportedcard.forEach((supportedcard)=>{
  286. // if (supportedcard === "JCB" || supportedcard === "MasterCard" || supportedcard === "Visa"){
  287. // setCreditCardStatus(method)
  288. // } else {
  289. // if (supportedcard === "UnionPay"){
  290. // setUnionPayStatus(method)
  291. // }
  292. // }
  293. // })
  294. // }else if (method.subtype === "PPS" ){
  295. // setPPSStatus(method)
  296. // }
  297. // });
  298. // }
  299. }
  300. useEffect(() => {
  301. console.log(availableMethods)
  302. if (availableMethods.length > 0) {
  303. availableMethods.forEach((method) => {
  304. if (method.subtype === "FPS") {
  305. setFPSStatus(method)
  306. } else if (method.subtype === "CreditCard") {
  307. method.supportedcard.forEach((supportedcard) => {
  308. if (supportedcard === "JCB" || supportedcard === "MasterCard" || supportedcard === "Visa") {
  309. setCreditCardStatus(method)
  310. } else {
  311. if (supportedcard === "UnionPay") {
  312. setUnionPayStatus(method)
  313. }
  314. }
  315. })
  316. } else if (method.subtype === "PPS") {
  317. setPPSStatus(method)
  318. }
  319. });
  320. setOnReady(true)
  321. }
  322. }, [availableMethods]);
  323. const getTransactionId = () => {
  324. HttpUtils.get({
  325. url: paymentPath + getTransactionIdUrl,
  326. onSuccess: (responseData) => {
  327. // const transactionData = responseData;
  328. setTransactionData(responseData)
  329. }
  330. });
  331. }
  332. // useEffect(() => {
  333. // if (availableMethods.length > 0 && Object.keys(transactionData).length > 0) {
  334. // setOnReady(true)
  335. // }
  336. // }, [transactionData, availableMethods]);
  337. const getAppList = () => {
  338. HttpUtils.post({
  339. url: UrlUtils.PAYMENT_APP_LIST,
  340. params: {
  341. appIds: appIds
  342. },
  343. onSuccess: (responseData) => {
  344. setItemList(responseData)
  345. }
  346. });
  347. }
  348. const selectedPaymentMethodHandle = (method) => () => {
  349. setSelectedPaymentMethod(method);
  350. };
  351. const confirmPaymentHandle = () => () => {
  352. HttpUtils.post({
  353. url: UrlUtils.POST_CHECK_APP_EXPRITY_DATE,
  354. params: {
  355. ids: appIds
  356. },
  357. onSuccess: (responData) => {
  358. if (responData.success == true) {
  359. setConfirmPayment(true);
  360. return;
  361. }
  362. let str = "";
  363. responData.msg.forEach((item) => {
  364. str += "App: " + item.appNo + ", 到期日: " + DateUtils.datetimeStr_Cht(item.expiryDate) + "\n";
  365. });
  366. setExpiryDateErrText(str.split('\n').map(str => <>{str}<br/></>));
  367. setExpiryDateErr(true);
  368. }
  369. });
  370. };
  371. const getMethodImgClass = (method) => {
  372. return selectedPaymentMethod == method || selectedPaymentMethod == "" ? "" : "grayscale";
  373. }
  374. return (
  375. <Grid container sx={{ minHeight: '110vh', backgroundColor: '#fff' }} direction="column" justifyContent="flex-start" alignItems="center" >
  376. <Grid item xs={12} width="100%">
  377. <div style={BackgroundHead} width="100%">
  378. <Stack direction="row" height='70px'>
  379. <Typography ml={15} color='#FFF' variant="h4" sx={{ pt: 2 }}>公共啟事:付款</Typography>
  380. </Stack>
  381. </div>
  382. </Grid>
  383. {/*row 1*/}
  384. <Grid item xs={12} md={12} width="100%">
  385. <Grid container justifyContent="center" spacing={2} sx={{ p: 2 }} alignitems="stretch" >
  386. <Grid item xs={12} md={5} style={{ height: '100%' }}>
  387. <Box xs={12} md={12} sx={{ p: 4, border: '3px solid #eee', borderRadius: '10px' }} >
  388. <DataGrid
  389. recordList={itemList}
  390. />
  391. </Box>
  392. </Grid>
  393. <Grid item xs={12} md={5} sx={{ pt: 2 }} style={{ height: '100%' }}>
  394. <Box xs={12} md={12} sx={{ p: 4, border: '3px solid #eee', borderRadius: '10px' }} >
  395. <Grid container justifyContent="flex-start" alignItems="left" >
  396. <center>
  397. <Grid item xs={12} md={12} >
  398. <Typography variant="h5" sx={{ textAlign: "left" }}>
  399. 交易參考號: {transactionData.transactionid}
  400. </Typography>
  401. <Typography variant="h5" sx={{ textAlign: "left" }}>
  402. 支付金額: HK$ {FormatUtils.currencyFormat(totalAmount)}
  403. </Typography>
  404. {/* <Button
  405. component="span"
  406. variant="contained"
  407. size="large"
  408. // color="error"
  409. onClick={() => paymentClick()}
  410. sx={{ mt: 4 }}
  411. >選擇付款方式</Button> */}
  412. </Grid>
  413. <Grid item xs={12} md={12}>
  414. <Grid container >
  415. <Grid item>
  416. <Typography variant="h5" sx={{ textAlign: "left" }}>
  417. 付款金額:
  418. </Typography>
  419. </Grid>
  420. <Grid item>
  421. <Typography variant="h5" sx={{ textAlign: "left" }}>
  422. {"HK$ " + FormatUtils.currencyFormat(totalAmount)}
  423. </Typography>
  424. </Grid>
  425. </Grid>
  426. </Grid>
  427. {availableMethods.length > 0 ?
  428. !onReady ?
  429. <LoadingComponent /> :
  430. <Grid item xs={12} md={12}>
  431. <Grid container spacing={1} direction="row" justifyContent="flex-start" alignItems="center">
  432. <Grid item>
  433. <Typography variant="h5" sx={{ textAlign: "left" }}>
  434. 請選擇付款方式:
  435. </Typography>
  436. </Grid>
  437. <Grid item>
  438. <Button variant="contained" color="white" onClick={selectedPaymentMethodHandle("FPS")} disabled={fpsStatus.active === "N"}>
  439. <img className={getMethodImgClass("FPS")} src={FpsIcon} width="80" height="80" alt="FPS"></img>
  440. </Button>
  441. </Grid>
  442. <Grid item>
  443. <Button variant="contained" color="white" onClick={selectedPaymentMethodHandle("Visa")} disabled={creditCardStatus.active === "N"}>
  444. <img className={getMethodImgClass("Visa")} src={VisaIcon} width="80" height="80" alt="Visa"></img>
  445. </Button>
  446. </Grid>
  447. <Grid item>
  448. <Button variant="contained" color="white" onClick={selectedPaymentMethodHandle("Mastercard")} disabled={creditCardStatus.active === "N"}>
  449. <img className={getMethodImgClass("Mastercard")} src={MasterIcon} width="80" height="80" alt="Mastercard"></img>
  450. </Button>
  451. </Grid>
  452. <Grid item>
  453. <Button variant="contained" color="white" onClick={selectedPaymentMethodHandle("UnionPay")} disabled={unionPayStatus.active === "N"}>
  454. <img className={getMethodImgClass("UnionPay")} src={UnionPayIcon} width="80" height="80" alt="UnionPay"></img>
  455. </Button>
  456. </Grid>
  457. <Grid item>
  458. <Button variant="contained" color="white" onClick={selectedPaymentMethodHandle("JCB")} disabled={unionPayStatus.active === "N"}>
  459. <img className={getMethodImgClass("JCB")} src={JcbIcon} width="80" height="80" alt="JCB"></img>
  460. </Button>
  461. </Grid>
  462. <Grid item>
  463. <Button variant="contained" color="white" onClick={selectedPaymentMethodHandle("PPS")} disabled={ppsStatus.active === "N"}>
  464. <img className={getMethodImgClass("PPS")} src={PpsIcon} width="80" height="80" alt="PPS"></img>
  465. </Button>
  466. </Grid>
  467. </Grid>
  468. {selectedPaymentMethod != "" ?
  469. <Grid item xs={12} md={12}>
  470. <Grid container direction="row" justifyContent="flex-start" alignItems="center">
  471. <Grid item>
  472. <Typography variant="h5" sx={{ textAlign: "left" }}>
  473. 已選擇付款方式:
  474. </Typography>
  475. </Grid>
  476. <Grid item>
  477. <Typography variant="h5" sx={{ textAlign: "left" }}>
  478. {selectedPaymentMethod}
  479. </Typography>
  480. </Grid>
  481. </Grid>
  482. </Grid>
  483. : null}
  484. <Button variant="contained" size="large" color="success" onClick={confirmPaymentHandle()} disabled={selectedPaymentMethod === ""}>
  485. 確認
  486. </Button>
  487. </Grid> :
  488. <Grid container direction="row" justifyContent="center" alignItems="center">
  489. <Typography sx={{ fontSize: "20px", color: "#000000", textAlign: "center" }}>
  490. 付款功能現在不可用。
  491. </Typography>
  492. </Grid>
  493. }
  494. </center>
  495. </Grid>
  496. {/* <MultiPaymentWindow open={open}
  497. handleCose={handleClose}
  498. availableMethods={availableMethods}
  499. transactionData={transactionData}
  500. totalAmount={totalAmount}
  501. fpsStatus={fpsStatus}
  502. creditCardStatus={creditCardStatus}
  503. unionPayStatus={unionPayStatus}
  504. ppsStatus={ppsStatus}
  505. setSelectedPaymentMethod={setSelectedPaymentMethod}
  506. selectedPaymentMethod={selectedPaymentMethod}
  507. setConfirmPayment={setConfirmPayment}
  508. /> */}
  509. </Box>
  510. </Grid>
  511. </Grid>
  512. </Grid>
  513. <Grid item xs={12} md={12} >
  514. </Grid>
  515. {/*row 2*/}
  516. <div>
  517. <Dialog open={expiryDateErr} onClose={() => setExpiryDateErr(false)} >
  518. <DialogTitle></DialogTitle>
  519. <Typography variant="h2" style={{ padding: '16px' }}>行動失敗</Typography>
  520. <DialogContent style={{ display: 'flex', }}>
  521. <Stack direction="column" justifyContent="space-between">
  522. {
  523. expiryDateErrText
  524. }
  525. </Stack>
  526. </DialogContent>
  527. <DialogActions>
  528. <Button onClick={() => setExpiryDateErr(false)}><Typography variant="h5">關閉</Typography></Button>
  529. </DialogActions>
  530. </Dialog>
  531. </div>
  532. </Grid >
  533. );
  534. }
  535. export default Index;