選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

index.js 6.4 KiB

2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 [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/web/";
  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. React.useEffect(() => {
  46. if (location.state != undefined) {
  47. setPaymentData(location.state)
  48. }
  49. }, []);
  50. React.useEffect(() => {
  51. if (Object.keys(paymentData).length > 0){
  52. setOnReady(true);
  53. loadForm();
  54. }
  55. }, [paymentData]);
  56. const loadForm = () => {
  57. // const timeoutdatetime = "2023-10-26T09:04:30Z[UTC]"
  58. // const convertedDateString = timeoutdatetime.replace("[UTC]", "");
  59. // setFpsmerchanttimeoutdatetime(convertedDateString)
  60. HttpUtils.post({
  61. url: paymentPath+loadPaymentUrl+(paymentData.type=="PPS"?"pps":"creditcard"),
  62. params:{
  63. "transactionid": paymentData.transactionid,
  64. "apprefid:": paymentData.transactionid,
  65. "webtoken": paymentData.webtoken,
  66. "paymentmethod":paymentData.paymentMethod,
  67. "order": {
  68. "totalamount":paymentData.amount,
  69. "currency":"HKD",
  70. "orderdetail":
  71. [
  72. {
  73. "itemid": "1",
  74. "qty":"1",
  75. "unitprice":paymentData.amount,
  76. "amount":paymentData.amount
  77. },
  78. ]
  79. },
  80. // "locale":"<locale>",
  81. // "eserviceid":"<eserviceid>",
  82. "returnurl": "http://"+window.location.hostname+"/paymentPage/success"
  83. },
  84. onSuccess: function(responseData){
  85. /*
  86. {
  87. "transactionid": "<transactionid>",
  88. "redirecturl": "<redirecturl>"
  89. }
  90. */
  91. window.open(responseData.redirecturl);
  92. }
  93. });
  94. }
  95. const cancelPayment = () => {
  96. navigate("/dashboard");
  97. }
  98. const getIcon = () => {
  99. if(paymentData.type=="Visa") return VisaIcon;
  100. if(paymentData.type=="Mastercard") return MasterIcon;
  101. if(paymentData.type=="UnionPay") return UnionPayIcon;
  102. if(paymentData.type=="JCB") return JcbIcon;
  103. if(paymentData.type=="PPS") return PpsIcon;
  104. }
  105. return (
  106. !onReady ?
  107. <LoadingComponent />
  108. :
  109. (
  110. <Grid container sx={{ minHeight: '110vh', backgroundColor: '#fff' }} direction="column" justifyContent="flex-start" alignItems="center" >
  111. <Grid item xs={12} width="100%">
  112. <div style={BackgroundHead} width="100%">
  113. <Stack direction="row" height='70px'>
  114. <Typography ml={15} color='#FFF' variant="h4" sx={{ pt: 2 }}>公共啟事: 信用卡付款</Typography>
  115. </Stack>
  116. </div>
  117. </Grid>
  118. {/*row 1*/}
  119. <Grid item xs={12} md={12} >
  120. <Grid container justifyContent="flex-start" alignItems="center" >
  121. <center>
  122. <Grid item xs={12} md={12} >
  123. <Typography variant="h3" sx={{ ml: 8, mt: 4, mr: 8, textAlign: "center" }}>
  124. <img src={getIcon()} width="80" height="80" alt={paymentData.type}></img>
  125. <br />
  126. 支付金額
  127. <br />
  128. {"$HK " + paymentData.amount}
  129. </Typography>
  130. <Typography variant="h3" sx={{ ml: 8, mt: 4, mr: 8, textAlign: "center" }}>
  131. <Button
  132. component="span"
  133. variant="contained"
  134. size="large"
  135. color="error"
  136. onClick={() => {
  137. cancelPayment();
  138. }}
  139. sx={{ m: 4 }}
  140. >取消付款</Button>
  141. </Typography>
  142. </Grid>
  143. </center>
  144. </Grid>
  145. </Grid>
  146. {/*row 2*/}
  147. </Grid >
  148. )
  149. );
  150. }
  151. export default Index;