Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

240 righe
8.6 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. const Index = () => {
  28. const navigate = useNavigate()
  29. const location = useLocation();
  30. const [paymentData, setPaymentData] = React.useState({});
  31. const [onReady, setOnReady] = React.useState(false);
  32. const [fpsmerchanttimeoutdatetime, setFpsmerchanttimeoutdatetime] = React.useState("");
  33. const [redirecturl, setRedirectUrl] = React.useState("");
  34. // const [paymentstatuscode, setPaymentstatuscode] = React.useState("");
  35. // const [fpsqrcodeurl, setFpsqrcodeurl] = React.useState("");
  36. // const pasgPath = 'https://fps.payapps.hkicl.com.hk'; //PRD
  37. // const pasgPath = 'https://sim.fps.payapps.hkicl.com.hk'; //Testing
  38. const loadPaymentUrl = "/api/payment/web/";
  39. const cancelPaymentUrl = "/api/payment/cancelpayment";
  40. // const paymentStatusApi = "/api/payment/status/";
  41. // const payloadUrl = "/api/payment/wallet/fps/enquiryfpspayload/";
  42. // const receiverUrl = "/noti-api/payment/payment-notification";
  43. //timer
  44. const currentTimer = React.useRef();
  45. const [time, setTime] = React.useState(0);
  46. React.useEffect(() => {
  47. if (location.state != undefined) {
  48. setPaymentData(location.state)
  49. }
  50. loadForm();
  51. currentTimer.current = setInterval(() => {
  52. getPaymentStatus();
  53. setTime((prevTime) => prevTime + 1);
  54. }, 500);
  55. return () => clearInterval(currentTimer.current);
  56. }, []);
  57. React.useEffect(() => {
  58. setOnReady(true);
  59. }, [redirecturl]);
  60. const loadForm = () => {
  61. const timeoutdatetime = "2023-10-26T09:04:30Z[UTC]"
  62. const convertedDateString = timeoutdatetime.replace("[UTC]", "");
  63. setFpsmerchanttimeoutdatetime(convertedDateString)
  64. HttpUtils.post({
  65. url: paymentPath+loadPaymentUrl+paymentData.type,
  66. params:{
  67. "transactionid": paymentData.transactionid,
  68. "apprefid:": paymentData.transactionid,
  69. "webtoken": paymentData.webtoken,
  70. "paymentmethod":paymentData.paymentMethod,
  71. "order": {
  72. "totalamount":paymentData.amount,
  73. "currency":"HKD",
  74. "orderdetail":
  75. [
  76. {
  77. "itemid": "1",
  78. "qty":"1",
  79. "unitprice":paymentData.amount,
  80. "amount":paymentData.amount
  81. },
  82. ]
  83. },
  84. // "locale":"<locale>",
  85. // "eserviceid":"<eserviceid>",
  86. "returnurl": window.location.hostname+"/payment/success"
  87. },
  88. onSuccess: function(responseData){
  89. /*
  90. {
  91. "transactionid": "<transactionid>",
  92. "redirecturl": "<redirecturl>"
  93. }
  94. */
  95. setRedirectUrl(responseData.redirecturl);
  96. }
  97. });
  98. }
  99. const getPaymentStatus = () => {
  100. // HttpUtils.post({
  101. // url: paymentPath+paymentStatusApi+paymentid,
  102. // params:{
  103. // "apprefid": paymentData.transactionid,
  104. // "webtoken": paymentData.webtoken,
  105. // },
  106. // onSuccess: function(responseData){
  107. // const paymentstatuscode = responseData.paymentdetail.result.paymentstatuscode;
  108. // if (paymentstatuscode === 'APPR') {
  109. // const timestamp = '?t=' + Date.now();
  110. // window.top.location.href = paymentPath + payment.config.ackPagePath + timestamp;
  111. // } else if (paymentstatuscode === 'CANC') {
  112. // window.top.location.href = paymentPath + payment.config.indexPagePath;
  113. // } else {
  114. // window.top.location.href = paymentPath + payment.config.errPagePath;
  115. // }
  116. // },
  117. // onError: function(){
  118. // cancelPayment()
  119. // clearInterval(currentTimer.current);
  120. // }
  121. // });
  122. };
  123. React.useEffect(() => {
  124. const timeOutDate = new Date(fpsmerchanttimeoutdatetime);
  125. const currentTime = new Date;
  126. if (timeOutDate.getTime() < currentTime.getTime()) {
  127. console.log("stop");
  128. clearInterval(currentTimer.current);
  129. }
  130. }, [time])
  131. const cancelPayment = () => {
  132. HttpUtils.post({
  133. url: paymentPath + cancelPaymentUrl,
  134. params: {
  135. "transactionid": paymentData.transactionid,
  136. "webtoken": paymentData.webtoken,
  137. "paymentid": paymentid
  138. },
  139. onSuccess: function () {
  140. navigate("/dashboard");
  141. }
  142. });
  143. }
  144. // const getPayload = ()=>{
  145. // HttpUtils.get({
  146. // url: payloadUrl+"<paymenttoken>",
  147. // onSuccess: function(responseData){
  148. // /*
  149. // {
  150. // "payload": "<payload>"
  151. // }
  152. // */
  153. // }
  154. // });
  155. // }
  156. // const getReceiver = ()=>{
  157. // HttpUtils.get({
  158. // url: receiverUrl+"<paymenttoken>",
  159. // onSuccess: function(responseData){
  160. // /*
  161. // {
  162. // "payload": "<payload>"
  163. // }
  164. // */
  165. // }
  166. // });
  167. // }
  168. return (
  169. !onReady ?
  170. <LoadingComponent />
  171. :
  172. (
  173. <Grid container sx={{ minHeight: '110vh', backgroundColor: '#fff' }} direction="column" justifyContent="flex-start" alignItems="center" >
  174. <Grid item xs={12} width="100%">
  175. <div style={BackgroundHead} width="100%">
  176. <Stack direction="row" height='70px'>
  177. <Typography ml={15} color='#FFF' variant="h4" sx={{ pt: 2 }}>公共啟事: 信用卡付款</Typography>
  178. </Stack>
  179. </div>
  180. </Grid>
  181. {/*row 1*/}
  182. <Grid item xs={12} md={12} >
  183. <Grid container justifyContent="flex-start" alignItems="center" >
  184. <center>
  185. <Grid item xs={12} md={12} >
  186. <Typography variant="h3" sx={{ ml: 8, mt: 4, mr: 8, textAlign: "center" }}>
  187. <img src={FpsIcon} width="80" height="80" alt="FPS"></img>
  188. <br />
  189. 支付金額
  190. <br />
  191. {"$HK " + paymentData.amount}
  192. </Typography>
  193. <Typography variant="h3" sx={{ ml: 8, mt: 4, mr: 8, textAlign: "center" }}>
  194. <Button
  195. component="span"
  196. variant="contained"
  197. size="large"
  198. color="error"
  199. onClick={() => {
  200. cancelPayment();
  201. }}
  202. sx={{ m: 4 }}
  203. >取消付款</Button>
  204. </Typography>
  205. </Grid>
  206. </center>
  207. </Grid>
  208. </Grid>
  209. {/*row 2*/}
  210. </Grid >
  211. )
  212. );
  213. }
  214. export default Index;