Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

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