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.

303 righe
16 KiB

  1. // material-ui
  2. import {
  3. Grid,
  4. Typography,
  5. Stack,
  6. Box
  7. // Button,
  8. // FormLabel,
  9. } from '@mui/material';
  10. import * as React from "react";
  11. import * as HttpUtils from "utils/HttpUtils";
  12. import * as UrlUtils from "utils/ApiPathConst";
  13. //import { useNavigate } from 'react-router-dom';
  14. import { paymentPath } from "auth/utils";
  15. import * as DateUtils from "utils/DateUtils"
  16. import Loadable from 'components/Loadable';
  17. const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent')));
  18. const PaymentDetails = Loadable(React.lazy(() => import('./Details_Public/PaymentDetails')));
  19. const DataGrid = Loadable(React.lazy(() => import('./Details_Public/DataGrid')));
  20. import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png'
  21. import {FormattedMessage} from "react-intl";
  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. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  32. const Index = () => {
  33. //const navigate = useNavigate()
  34. const [responeData, setResponeDataData] = React.useState({});
  35. const [paymentData, setPaymentData] = React.useState({});
  36. const [itemList, setItemList] = React.useState([]);
  37. const [paymentId, setPaymentId] = React.useState("");
  38. const [transactionData, setTransactionData] = React.useState({});
  39. // const [transactionDate, setTransactionDate] = React.useState("");
  40. // const [transactionTime, setTransactionTime] = React.useState("");
  41. const [onReady, setOnReady] = React.useState(false);
  42. const updatePaymentApi = "/api/payment/updatepayment";
  43. const paymentStatusApi = "/api/payment/status/";
  44. React.useEffect(() => {
  45. loadForm();
  46. }, []);
  47. React.useEffect(() => {
  48. console.log(responeData)
  49. if (Object.keys(responeData).length > 0) {
  50. setTransactionData(responeData)
  51. }
  52. }, [responeData]);
  53. React.useEffect(() => {
  54. console.log(transactionData)
  55. if (Object.keys(transactionData).length > 0) {
  56. setOnReady(true);
  57. }
  58. }, [transactionData]);
  59. const loadForm = () => {
  60. // const date = new Date();
  61. // const trnDate = date.getDate() + "/" + date.getMonth() + "/" + date.getFullYear();
  62. // const trnTime = date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
  63. // setTransactionDate(trnDate)
  64. // setTransactionTime(trnTime)
  65. const params = new URLSearchParams(window.location.search);
  66. let transactionid = params.get("TRANSACTION_ID")
  67. let receipt_token = params.get("RECEIPT_TOKEN").replace("%3D", "=")
  68. HttpUtils.post({
  69. url: paymentPath + updatePaymentApi,
  70. params: {
  71. "transactionid": transactionid,
  72. "receipttoken": receipt_token,
  73. },
  74. onSuccess: function () {
  75. // {
  76. // "amount": 999.99,
  77. // "currencycode": "HKD",
  78. // "paymentdetail": {
  79. // "attemptno": 1,
  80. // "channel": "MobileWallet",
  81. // "paymentid": "C202310268000681",
  82. // "paymentmethod": "04",
  83. // "result": {
  84. // "canretry": "Y",
  85. // "description": "CANC - Cancelled by user or Payment Server.",
  86. // "paymentstatuscode": "CANC",
  87. // "rejectreasoncode": "Payment Cancelled. [PAY-E-9022]"
  88. // },
  89. // "subtype": "FPS",
  90. // "time": "2023-10-26T09:02:17Z[UTC]"
  91. // },
  92. // "transactionid": "20231026170103921"
  93. // }
  94. // )
  95. HttpUtils.post({
  96. url: paymentPath + paymentStatusApi + transactionid,
  97. params: {
  98. "apprefid": transactionid,
  99. "webtoken": localStorage.getItem("webtoken"),
  100. },
  101. onSuccess: function (responseData) {
  102. setResponeDataData(responseData)
  103. if (responseData.paymentdetail?.result?.paymentstatuscode === "APPR") {
  104. localStorage.removeItem("webtoken");
  105. localStorage.removeItem("transactionid");
  106. }
  107. HttpUtils.post({
  108. url: UrlUtils.PAYMENT_SAVE,
  109. params: {
  110. id: localStorage.getItem("paymentId"),
  111. transNo: responseData.transactionid,
  112. transDateTime: responseData.paymentdetail.time.replace("[UTC]", ""),
  113. egisRefNo: responseData.paymentdetail.paymentid,
  114. status: responseData.paymentdetail.result.paymentstatuscode,
  115. payload: responseData
  116. },
  117. onSuccess: function (responseData2) {
  118. responseData2.data["transDateStr"] = DateUtils.dateFormat(responseData2.data.transDateTime, "DD/MM/YYYY");
  119. responseData2.data["transTimeStr"] = DateUtils.dateFormat(responseData2.data.transDateTime, "HH:mm:ss");
  120. setItemList(responseData2.paymentItemList)
  121. setPaymentData(responseData2.data);
  122. localStorage.removeItem("paymentId");
  123. setPaymentId(responseData2.id)
  124. }
  125. });
  126. }
  127. });
  128. }
  129. });
  130. }
  131. const doPrint = () => {
  132. // window.print();
  133. HttpUtils.fileDownload({
  134. url: UrlUtils.GEN_PAYMENT_RECEIPT+"/"+paymentId,
  135. });
  136. };
  137. return (
  138. !onReady ?
  139. <LoadingComponent />
  140. :
  141. transactionData.paymentdetail?.result?.paymentstatuscode === "APPR" ?
  142. (
  143. <div>
  144. <style>
  145. {`@media print {.printHidden{display: none;} .printOrder{order:-1 !important;}`}
  146. </style>
  147. <Grid container className="printheight" sx={{ minHeight: '80%', backgroundColor: '#fff' }} direction="column" justifyContent="flex-start" alignItems="center">
  148. <Grid className="printHidden" item xs={12} width="100%">
  149. <div style={BackgroundHead} width="100%">
  150. <Stack direction="row" height='70px'>
  151. <Typography ml={15} color='#FFF' variant="h4" sx={{ pt: 2 }}>
  152. <FormattedMessage id="publicNoticePaymentSuccess"/>
  153. </Typography>
  154. </Stack>
  155. </div>
  156. </Grid>
  157. {/*row 1*/}
  158. <Grid item xs={12} md={12} spacing={2} sx={{ textAlign: "center" }}>
  159. <Typography variant="h3" sx={{ ml: 8, mt: 4, mr: 8, textAlign: "center" }}>
  160. 您的申請和付款已收到
  161. </Typography>
  162. <Grid container justifyContent="center" direction="column" spacing={2} sx={{ p: 2 }} alignitems="stretch" >
  163. <Grid item className="printOrder" xs={12} md={12} sx={{ pt: 2 }} style={{ height: '100%', order: 1 }}>
  164. <Box xs={12} md={12} sx={{ border: '3px solid #eee', borderRadius: '10px' }} >
  165. <PaymentDetails
  166. formData={paymentData}
  167. doPrint={doPrint}
  168. style={{
  169. display: "flex",
  170. height: "100%",
  171. flex: 1
  172. }}
  173. />
  174. </Box>
  175. </Grid>
  176. <Grid item xs={12} md={12} sx={{ pt: 1, pb: 2 }} style={{ height: '100%', order: 2 }}>
  177. <Box xs={12} md={12} sx={{ border: '3px solid #eee', borderRadius: '10px' }} >
  178. <DataGrid
  179. recordList={itemList}
  180. />
  181. </Box>
  182. </Grid>
  183. </Grid>
  184. </Grid>
  185. {/*row 2*/}
  186. </Grid >
  187. </div>
  188. ) :
  189. (transactionData.paymentdetail?.result?.paymentstatuscode === "CANC" ?
  190. <div>
  191. <style>
  192. {`@media print {.printHidden{display: none;} .printOrder{order:-1 !important;}`}
  193. </style>
  194. <Grid container className="printheight" sx={{ minHeight: '80%', backgroundColor: '#fff' }} direction="column" justifyContent="flex-start" alignItems="center" >
  195. <Grid className="printHidden" item xs={12} width="100%">
  196. <div style={BackgroundHead} width="100%">
  197. <Stack direction="row" height='70px'>
  198. <Typography ml={15} color='#FFF' variant="h4" sx={{ pt: 2 }}>
  199. <FormattedMessage id="publicNoticePaymentCancel"/>
  200. </Typography>
  201. </Stack>
  202. </div>
  203. </Grid>
  204. {/*row 1*/}
  205. <Grid item xs={12} md={12} >
  206. <Grid container justifyContent="flex-start" alignItems="center" >
  207. <center>
  208. <Grid item xs={12} md={8} >
  209. <Typography variant="h5" sx={{ ml: 8, mt: 4, mr: 8, textAlign: "left" }}>
  210. 付款取消訊息:
  211. <br /><br />
  212. 您的付款已被取消。我們收到了您的付款請求,但由於某些原因,付款無法完成。請注意以下事項:
  213. <br /><br />
  214. 如果您主動取消了支付,請確認並確保取消是您的意願。
  215. <br />
  216. 如果付款被取消是由於系統問題或其他原因,請您嘗試以下解決方法:
  217. <br /><br />
  218. 檢查您的支付帳戶是否有任何異常或限制。
  219. <br />
  220. 確保您的付款資訊準確無誤。
  221. <br />
  222. 檢查您的網路連線是否正常。
  223. <br /><br />
  224. 如果您需要進一步的協助或有任何疑問,請隨時與我們聯繫,我們將盡快解決您的付款問題。謝謝!
  225. </Typography>
  226. </Grid>
  227. </center>
  228. </Grid>
  229. </Grid>
  230. {/*row 2*/}
  231. </Grid >
  232. </div>
  233. :
  234. <div>
  235. <style>
  236. {`@media print {.printHidden{display: none;} .printOrder{order:-1 !important;}`}
  237. </style>
  238. <Grid container className="printheight" sx={{ minHeight: '80%', backgroundColor: '#fff' }}direction="column" justifyContent="flex-start" alignItems="center" >
  239. <Grid className="printHidden" item xs={12} width="100%">
  240. <div style={BackgroundHead} width="100%">
  241. <Stack direction="row" height='70px'>
  242. <Typography ml={15} color='#FFF' variant="h4" sx={{ pt: 2 }}>
  243. <FormattedMessage id="publicNoticePaymentFail"/>
  244. </Typography>
  245. </Stack>
  246. </div>
  247. </Grid>
  248. {/*row 1*/}
  249. <Grid item xs={12} md={12} >
  250. <Grid container justifyContent="flex-start" alignItems="center" >
  251. <center>
  252. <Grid item xs={12} md={8} >
  253. <Typography variant="h5" sx={{ ml: 8, mt: 4, mr: 8, textAlign: "left" }}>
  254. 付款失敗訊息:
  255. <br /><br />
  256. 親愛的用戶,很遺憾地告訴您,您的付款操作未成功。我們在處理您的付款時遇到了問題。請您仔細檢查以下事項:
  257. <br /><br />
  258. 您的支付帳戶餘額是否足夠。
  259. <br />
  260. 您提供的付款資訊是否準確無誤。
  261. <br />
  262. 請檢查您的網路連線是否正常。
  263. <br /><br />
  264. 如果您已確認以上問題無誤,但付款失敗,請您嘗試以下解決方法:
  265. <br /><br />
  266. 嘗試使用其他付款方式進行付款。
  267. <br />
  268. 檢查您的支付帳戶是否有異常或限制。
  269. <br />
  270. 聯絡我們的客服人員尋求協助。
  271. <br /><br />
  272. 如果您需要進一步的協助或有任何疑問,請隨時與我們聯繫。非常抱歉給您帶來不便,我們將盡快解決您的付款問題。謝謝!
  273. </Typography>
  274. </Grid>
  275. </center>
  276. </Grid>
  277. </Grid>
  278. {/*row 2*/}
  279. </Grid >
  280. </div>
  281. )
  282. );
  283. };
  284. export default Index;