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.

342 righe
18 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,useIntl} 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 [onDownload, setOnDownload] = React.useState(false);
  39. const [transactionData, setTransactionData] = React.useState({});
  40. // const [transactionDate, setTransactionDate] = React.useState("");
  41. // const [transactionTime, setTransactionTime] = React.useState("");
  42. const [onReady, setOnReady] = React.useState(false);
  43. // const updatePaymentApi = "/api/payment/updatepayment";
  44. // const paymentStatusApi = "/api/payment/status/";
  45. const intl = useIntl();
  46. const { locale } = intl;
  47. React.useEffect(() => {
  48. loadForm();
  49. }, []);
  50. React.useEffect(() => {
  51. if (Object.keys(responeData).length > 0) {
  52. console.log(responeData)
  53. setTransactionData(responeData)
  54. }
  55. }, [responeData]);
  56. React.useEffect(() => {
  57. if (Object.keys(transactionData).length > 0) {
  58. console.log(transactionData)
  59. console.log(itemList)
  60. console.log(paymentData)
  61. setOnReady(true);
  62. }
  63. }, [transactionData]);
  64. const loadForm = () => {
  65. // const date = new Date();
  66. // const trnDate = date.getDate() + "/" + date.getMonth() + "/" + date.getFullYear();
  67. // const trnTime = date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
  68. // setTransactionDate(trnDate)
  69. // setTransactionTime(trnTime)
  70. const params = new URLSearchParams(window.location.search);
  71. let transactionid = params.get("TRANSACTION_ID")
  72. let receipt_token = params.get("RECEIPT_TOKEN").replace("%3D", "=")
  73. HttpUtils.post({
  74. url: UrlUtils.UPDATE_PAYMENT_API,
  75. params: {
  76. "transactionid": transactionid,
  77. "receipttoken": receipt_token,
  78. },
  79. onSuccess: function () {
  80. // {
  81. // "amount": 999.99,
  82. // "currencycode": "HKD",
  83. // "paymentdetail": {
  84. // "attemptno": 1,
  85. // "channel": "MobileWallet",
  86. // "paymentid": "C202310268000681",
  87. // "paymentmethod": "04",
  88. // "result": {
  89. // "canretry": "Y",
  90. // "description": "CANC - Cancelled by user or Payment Server.",
  91. // "paymentstatuscode": "CANC",
  92. // "rejectreasoncode": "Payment Cancelled. [PAY-E-9022]"
  93. // },
  94. // "subtype": "FPS",
  95. // "time": "2023-10-26T09:02:17Z[UTC]"
  96. // },
  97. // "transactionid": "20231026170103921"
  98. // }
  99. // )
  100. HttpUtils.post({
  101. url: UrlUtils.PAYMENT_CALLBACK_STATUS_API,
  102. params: {
  103. "apprefid": transactionid,
  104. // "webtoken": localStorage.getItem("webtoken"),
  105. // "paymentId": localStorage.getItem("paymentId"),
  106. "transactionid":Number(transactionid)
  107. },
  108. onSuccess: function (responseData) {
  109. if (responseData.paymentdetail?.result?.paymentstatuscode === "APPR") {
  110. localStorage.removeItem("webtoken");
  111. localStorage.removeItem("transactionid");
  112. }
  113. responseData.data["transDateStr"] = responseData.data.transDateTime;
  114. responseData.data["transTimeStr"] = DateUtils.dateFormat(responseData.data.transDateTime, "HH:mm:ss");
  115. setResponeDataData(responseData.transactionData)
  116. setItemList(responseData.paymentItemList)
  117. setPaymentData(responseData.data);
  118. // if (responseData.paymentdetail?.result?.paymentstatuscode === "APPR") {
  119. // }
  120. // HttpUtils.post({
  121. // url: UrlUtils.PAYMENT_SAVE,
  122. // params: {
  123. // id: localStorage.getItem("paymentId"),
  124. // transNo: responseData.transactionid,
  125. // transDateTime: new Date(responseData.paymentdetail.time).toISOString(),
  126. // egisRefNo: responseData.paymentdetail.paymentid,
  127. // status: responseData.paymentdetail.result.paymentstatuscode,
  128. // payload: responseData
  129. // },
  130. // onSuccess: function (responseData2) {
  131. // responseData2.data["transDateStr"] = DateUtils.dateFormat(responseData2.data.transDateTime, "DD/MM/YYYY");
  132. // responseData2.data["transTimeStr"] = DateUtils.dateFormat(responseData2.data.transDateTime, "HH:mm:ss");
  133. // setItemList(responseData2.paymentItemList)
  134. // setPaymentData(responseData2.data);
  135. // // localStorage.removeItem("paymentId");
  136. // // setPaymentId(responseData2.id)
  137. // }
  138. // });
  139. }
  140. });
  141. }
  142. });
  143. }
  144. const doPrint = () => {
  145. // window.print();
  146. setOnDownload(true)
  147. const local = locale
  148. console.log(local)
  149. HttpUtils.fileDownload({
  150. // url: UrlUtils.GEN_PAYMENT_RECEIPT+"/"+localStorage.getItem("paymentId")+"/"+local,
  151. url: UrlUtils.GEN_PAYMENT_RECEIPT+"/"+paymentData.id+"/"+local,
  152. onResponse:()=>{
  153. setOnDownload(false)
  154. },
  155. onError:()=>{
  156. setOnDownload(false)
  157. }
  158. });
  159. };
  160. return (
  161. !onReady ?
  162. <Grid container sx={{ minHeight: '87vh', mb: 3 }} direction="column" justifyContent="center" alignItems="center">
  163. <Grid item>
  164. <LoadingComponent />
  165. </Grid>
  166. </Grid>
  167. :
  168. transactionData.paymentdetail?.result?.paymentstatuscode === "APPR" ?
  169. (
  170. <div>
  171. <style>
  172. {`@media print {.printHidden{display: none;} .printOrder{order:-1 !important;}`}
  173. </style>
  174. <Grid container className="printheight" sx={{ minHeight: '80%', backgroundColor: '#fff' }} direction="column" justifyContent="flex-start" alignItems="center">
  175. <Grid className="printHidden" item xs={12} width="100%">
  176. <div style={BackgroundHead} width="100%">
  177. <Stack direction="row" height='70px'>
  178. <Typography ml={15} color='#FFF' variant="h4" sx={{ pt: 2 }}>
  179. <FormattedMessage id="publicNoticePaymentSuccess"/>
  180. </Typography>
  181. </Stack>
  182. </div>
  183. </Grid>
  184. {/*row 1*/}
  185. <Grid item xs={12} md={12} spacing={2} sx={{ textAlign: "center" }}>
  186. <Typography variant="h3" sx={{ ml: 8, mt: 4, mr: 8, textAlign: "center" }}>
  187. <FormattedMessage id="MSG.paymentMsg"/>
  188. </Typography>
  189. <Grid container justifyContent="center" direction="column" spacing={2} sx={{ p: 2 }} alignitems="stretch" >
  190. <Grid item className="printOrder" xs={12} md={12} sx={{ pt: 2 }} style={{ height: '100%', order: 1 }}>
  191. <Box xs={12} md={12} sx={{ border: '3px solid #eee', borderRadius: '10px' }} >
  192. <PaymentDetails
  193. formData={paymentData}
  194. doPrint={doPrint}
  195. onDownload={onDownload}
  196. style={{
  197. display: "flex",
  198. height: "100%",
  199. flex: 1
  200. }}
  201. />
  202. </Box>
  203. </Grid>
  204. <Grid item xs={12} md={12} sx={{ pt: 1, pb: 2 }} style={{ height: '100%', order: 2 }}>
  205. <Box xs={12} md={12} sx={{ border: '3px solid #eee', borderRadius: '10px' }} >
  206. <DataGrid
  207. recordList={itemList}
  208. />
  209. </Box>
  210. </Grid>
  211. </Grid>
  212. </Grid>
  213. {/*row 2*/}
  214. </Grid >
  215. </div>
  216. ) :
  217. (transactionData.paymentdetail?.result?.paymentstatuscode === "CANC" ?
  218. <div>
  219. <style>
  220. {`@media print {.printHidden{display: none;} .printOrder{order:-1 !important;}`}
  221. </style>
  222. <Grid container className="printheight" sx={{ minHeight: '80%', backgroundColor: '#fff' }} direction="column" justifyContent="flex-start" alignItems="center" >
  223. <Grid className="printHidden" item xs={12} width="100%">
  224. <div style={BackgroundHead} width="100%">
  225. <Stack direction="row" height='70px'>
  226. <Typography ml={15} color='#FFF' variant="h4" sx={{ pt: 2 }}>
  227. <FormattedMessage id="publicNoticePaymentCancel"/>
  228. </Typography>
  229. </Stack>
  230. </div>
  231. </Grid>
  232. {/*row 1*/}
  233. <Grid item xs={12} md={12} >
  234. <Grid container justifyContent="flex-start" alignItems="center" >
  235. <center>
  236. <Grid item xs={12} md={8} >
  237. <Typography variant="h5" sx={{ ml: 8, mt: 4, mr: 8, textAlign: "left" }}>
  238. <FormattedMessage id="MSG.paymentCancelMsg1"/>
  239. <br /><br />
  240. <FormattedMessage id="MSG.paymentCancelMsg2"/>
  241. <br /><br />
  242. <FormattedMessage id="MSG.paymentCancelMsg3"/>
  243. <br />
  244. <FormattedMessage id="MSG.paymentCancelMsg4"/>
  245. <br /><br />
  246. <FormattedMessage id="MSG.paymentCancelMsg5"/>
  247. <br />
  248. <FormattedMessage id="MSG.paymentCancelMsg6"/>
  249. <br />
  250. <FormattedMessage id="MSG.paymentCancelMsg7"/>
  251. <br /><br />
  252. <FormattedMessage id="MSG.paymentCancelMsg8"/>
  253. </Typography>
  254. </Grid>
  255. </center>
  256. </Grid>
  257. </Grid>
  258. {/*row 2*/}
  259. </Grid >
  260. </div>
  261. :
  262. <div>
  263. <style>
  264. {`@media print {.printHidden{display: none;} .printOrder{order:-1 !important;}`}
  265. </style>
  266. <Grid container className="printheight" sx={{ minHeight: '80%', backgroundColor: '#fff' }}direction="column" justifyContent="flex-start" alignItems="center" >
  267. <Grid className="printHidden" item xs={12} width="100%">
  268. <div style={BackgroundHead} width="100%">
  269. <Stack direction="row" height='70px'>
  270. <Typography ml={15} color='#FFF' variant="h4" sx={{ pt: 2 }}>
  271. <FormattedMessage id="publicNoticePaymentFail"/>
  272. </Typography>
  273. </Stack>
  274. </div>
  275. </Grid>
  276. {/*row 1*/}
  277. <Grid item xs={12} md={12} >
  278. <Grid container justifyContent="flex-start" alignItems="center" >
  279. <center>
  280. <Grid item xs={12} md={8} >
  281. <Typography variant="h5" sx={{ ml: 8, mt: 4, mr: 8, textAlign: "left" }}>
  282. <FormattedMessage id="MSG.paymentFailMsg1"/>
  283. <br /><br />
  284. <FormattedMessage id="MSG.paymentFailMsg2"/>
  285. <br /><br />
  286. <ul>
  287. <li>
  288. <FormattedMessage id="MSG.paymentFailMsg3"/>
  289. </li>
  290. <li>
  291. <FormattedMessage id="MSG.paymentFailMsg4"/>
  292. </li>
  293. <li>
  294. <FormattedMessage id="MSG.paymentFailMsg5"/>
  295. </li>
  296. </ul>
  297. <br /><br />
  298. <FormattedMessage id="MSG.paymentFailMsg6"/>
  299. <br /><br />
  300. <ul>
  301. <li>
  302. <FormattedMessage id="MSG.paymentFailMsg7"/>
  303. </li>
  304. <li>
  305. <FormattedMessage id="MSG.paymentFailMsg8"/>
  306. </li>
  307. <li>
  308. <FormattedMessage id="MSG.paymentFailMsg9"/>
  309. </li>
  310. </ul>
  311. <br /><br />
  312. <FormattedMessage id="MSG.paymentFailMsg10"/>
  313. </Typography>
  314. </Grid>
  315. </center>
  316. </Grid>
  317. </Grid>
  318. {/*row 2*/}
  319. </Grid >
  320. </div>
  321. )
  322. );
  323. };
  324. export default Index;