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.

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