Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

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