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.
 
 

265 regels
10 KiB

  1. // material-ui
  2. import {
  3. Grid,
  4. Typography,
  5. Stack,
  6. Button,
  7. } from '@mui/material';
  8. import * as React from "react";
  9. import * as HttpUtils from "utils/HttpUtils";
  10. import { useNavigate } from "react-router-dom";
  11. import FpsIcon from "assets/images/icons/fps.svg";
  12. import { useLocation } from 'react-router-dom';
  13. import {paymentPath} from "auth/utils";
  14. // import {poll} from "utils/Utils";
  15. import Loadable from 'components/Loadable';
  16. const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent')));
  17. import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png'
  18. const BackgroundHead = {
  19. backgroundImage: `url(${titleBackgroundImg})`,
  20. width: '100%',
  21. height: '100%',
  22. backgroundSize: 'contain',
  23. backgroundRepeat: 'no-repeat',
  24. backgroundColor: '#0C489E',
  25. backgroundPosition: 'right'
  26. }
  27. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  28. const Index = () => {
  29. const navigate = useNavigate()
  30. const location = useLocation();
  31. const [paymentData, setPaymentData] = React.useState({});
  32. const [onReady, setOnReady] = React.useState(false);
  33. const [paymentid, setPaymentid] = React.useState("");
  34. const [fpsmerchanttimeoutdatetime, setFpsmerchanttimeoutdatetime] = React.useState("");
  35. const [fpsqrcodeimgbase64, setFpsqrcodeimgbase64] = React.useState("");
  36. // const [paymentstatuscode, setPaymentstatuscode] = React.useState("");
  37. // const [fpsqrcodeurl, setFpsqrcodeurl] = React.useState("");
  38. // const pasgPath = 'https://fps.payapps.hkicl.com.hk'; //PRD
  39. // const pasgPath = 'https://sim.fps.payapps.hkicl.com.hk'; //Testing
  40. // const loadPaymentUrl = "/api/payment/wallet/fps";
  41. const cancelPaymentUrl = "/api/payment/cancelpayment";
  42. // const paymentStatusApi = "/api/payment/status/";
  43. // const payloadUrl = "/api/payment/wallet/fps/enquiryfpspayload/";
  44. // const receiverUrl = "/noti-api/payment/payment-notification";
  45. //timer
  46. const currentTimer = React.useRef();
  47. const [time, setTime] = React.useState(0);
  48. React.useEffect(() => {
  49. setFpsqrcodeimgbase64("")
  50. if(location.state != undefined){
  51. setPaymentData(location.state)
  52. }
  53. loadForm();
  54. currentTimer.current = setInterval(() => {
  55. getPaymentStatus();
  56. setTime((prevTime) => prevTime + 1);
  57. }, 500);
  58. return () => clearInterval(currentTimer.current);
  59. }, []);
  60. React.useEffect(() => {
  61. setOnReady(true);
  62. }, [fpsqrcodeimgbase64]);
  63. const loadForm = () => {
  64. const timeoutdatetime = "2023-10-26T09:04:30Z[UTC]"
  65. const convertedDateString = timeoutdatetime.replace("[UTC]", "");
  66. setFpsmerchanttimeoutdatetime(convertedDateString)
  67. setPaymentid("C202310268000681")
  68. // HttpUtils.post({
  69. // url: paymentPath+loadPaymentUrl,
  70. // params:{
  71. // "transactionid": paymentData.transactionid,
  72. // "webtoken": paymentData.webtoken,
  73. // "paymentmethod":"04,BCFP,FPS",
  74. // "order": {
  75. // "totalamount":paymentData.amount,
  76. // "currency":"HKD",
  77. // "orderdetail":
  78. // [
  79. // {
  80. // "itemid": "1",
  81. // "qty":"1",
  82. // "unitprice":paymentData.amount,
  83. // "amount":paymentData.amount
  84. // },
  85. // ]
  86. // },
  87. // // "locale":"<locale>",
  88. // // "eserviceid":"<eserviceid>"
  89. // },
  90. // onSuccess: function(responseData){
  91. // /*
  92. // {
  93. // "paymentid": "<paymentid>",
  94. // "paymentstatus": "<paymentstatus>",
  95. // "fpsmerchanttimeoutdatetime": <fpsmerchanttimeoutdatetime>,
  96. // "fpsqrcodeimgbase64": "<fpsqrcodeimgbase64>",
  97. // "fpsqrcodeurl": "<fpsqrcodeurl>"
  98. // }
  99. // */
  100. // setFpsqrcodeimgbase64(responseData.fpsqrcodeimgbase64);
  101. // setPaymentid(responseData.paymentid);
  102. // setFpsmerchanttimeoutdatetime(responseData.fpsmerchanttimeoutdatetime);
  103. // setPaymentstatuscode(responseData.paymentstatuscode);
  104. // // const parsedUrl = new URL(responseData.fpsqrcodeurl);
  105. // // const fpsqrcodeurl = parsedUrl.pathname;
  106. // // const openPASGUrl = pasgPath + '?pay_req_obj=' + encodeURIComponent(responseData.fpsqrcodeurl) + '&callback='
  107. // // + encodeURIComponent(paymentPath + payment.config.fpscallbackPage);
  108. // // setFpsqrcodeurl(openPASGUrl)
  109. // }
  110. // });
  111. }
  112. const getPaymentStatus = () => {
  113. // HttpUtils.post({
  114. // url: paymentPath+paymentStatusApi+paymentid,
  115. // params:{
  116. // "apprefid": paymentData.transactionid,
  117. // "webtoken": paymentData.webtoken,
  118. // },
  119. // onSuccess: function(responseData){
  120. // const paymentstatuscode = responseData.paymentdetail.result.paymentstatuscode;
  121. // if (paymentstatuscode === 'APPR') {
  122. // const timestamp = '?t=' + Date.now();
  123. // window.top.location.href = paymentPath + payment.config.ackPagePath + timestamp;
  124. // } else if (paymentstatuscode === 'CANC') {
  125. // window.top.location.href = paymentPath + payment.config.indexPagePath;
  126. // } else {
  127. // window.top.location.href = paymentPath + payment.config.errPagePath;
  128. // }
  129. // },
  130. // onError: function(){
  131. // cancelPayment()
  132. // clearInterval(currentTimer.current);
  133. // }
  134. // });
  135. };
  136. React.useEffect(() => {
  137. const timeOutDate = new Date(fpsmerchanttimeoutdatetime);
  138. const currentTime = new Date;
  139. if (timeOutDate.getTime()<currentTime.getTime()){
  140. console.log("stop");
  141. clearInterval(currentTimer.current);
  142. }
  143. },[time])
  144. const cancelPayment = ()=>{
  145. HttpUtils.post({
  146. url: paymentPath+cancelPaymentUrl,
  147. params:{
  148. "transactionid": paymentData.transactionid,
  149. "webtoken": paymentData.webtoken,
  150. "paymentid": paymentid
  151. },
  152. onSuccess: function(){
  153. navigate("/dashboard");
  154. }
  155. });
  156. }
  157. // const getPayload = ()=>{
  158. // HttpUtils.get({
  159. // url: payloadUrl+"<paymenttoken>",
  160. // onSuccess: function(responseData){
  161. // /*
  162. // {
  163. // "payload": "<payload>"
  164. // }
  165. // */
  166. // }
  167. // });
  168. // }
  169. // const getReceiver = ()=>{
  170. // HttpUtils.get({
  171. // url: receiverUrl+"<paymenttoken>",
  172. // onSuccess: function(responseData){
  173. // /*
  174. // {
  175. // "payload": "<payload>"
  176. // }
  177. // */
  178. // }
  179. // });
  180. // }
  181. return (
  182. !onReady ?
  183. <LoadingComponent />
  184. :
  185. (
  186. <Grid container sx={{ minHeight: '110vh', backgroundColor: '#fff' }} direction="column" justifyContent="flex-start" alignItems="center" >
  187. <Grid item xs={12} width="100%">
  188. <div style={BackgroundHead} width="100%">
  189. <Stack direction="row" height='70px'>
  190. <Typography ml={15} color='#FFF' variant="h4" sx={{ pt: 2 }}>公共啟事:FPS付款</Typography>
  191. </Stack>
  192. </div>
  193. </Grid>
  194. {/*row 1*/}
  195. <Grid item xs={12} md={12} >
  196. <Grid container justifyContent="flex-start" alignItems="center" >
  197. <center>
  198. <Grid item xs={12} md={12} >
  199. <Typography variant="h3" sx={{ ml: 8, mt: 4, mr: 8, textAlign: "center" }}>
  200. <img src={FpsIcon} width="80" height="80" alt="FPS"></img>
  201. <br />
  202. 支付金額
  203. <br />
  204. {"$HK " + paymentData.amount}
  205. </Typography>
  206. <Typography variant="h3" sx={{ ml: 8, mt: 4, mr: 8, textAlign: "center" }}>
  207. 請掃描以下二維碼
  208. <br />
  209. <img src={fpsqrcodeimgbase64} alt="QR Code"/>
  210. <img src={fpsqrcodeurl} alt="QR Code"/>
  211. <br />
  212. 二維碼有效期限10分鐘
  213. <br />
  214. 請在規定時間內完成付款流程 ({fpsmerchanttimeoutdatetime})
  215. </Typography>
  216. <Typography variant="h3" sx={{ ml: 8, mt: 4, mr: 8, textAlign: "center" }}>
  217. <Button
  218. component="span"
  219. variant="contained"
  220. size="large"
  221. color="error"
  222. onClick={()=>{
  223. cancelPayment();
  224. }}
  225. sx={{ m: 4 }}
  226. >取消付款</Button>
  227. </Typography>
  228. </Grid>
  229. </center>
  230. </Grid>
  231. </Grid>
  232. {/*row 2*/}
  233. </Grid >
  234. )
  235. );
  236. };
  237. export default Index;