|
|
@@ -38,13 +38,19 @@ const Index = () => { |
|
|
|
const [paymentid, setPaymentid] = React.useState(""); |
|
|
|
const [fpsmerchanttimeoutdatetime, setFpsmerchanttimeoutdatetime] = React.useState(""); |
|
|
|
const [fpsqrcodeimgbase64, setFpsqrcodeimgbase64] = React.useState(""); |
|
|
|
const [fpsqrcodeurl, setFpsqrcodeurl] = React.useState(""); |
|
|
|
|
|
|
|
const loadPaymentUrl = "/api/payment/wallet/fps"; |
|
|
|
// const [paymentstatuscode, setPaymentstatuscode] = React.useState(""); |
|
|
|
// const [fpsqrcodeurl, setFpsqrcodeurl] = React.useState(""); |
|
|
|
// const pasgPath = 'https://fps.payapps.hkicl.com.hk'; //PRD |
|
|
|
// const pasgPath = 'https://sim.fps.payapps.hkicl.com.hk'; //Testing |
|
|
|
// const loadPaymentUrl = "/api/payment/wallet/fps"; |
|
|
|
const cancelPaymentUrl = "/api/payment/cancelpayment"; |
|
|
|
const paymentStatusApi = "/api/payment/status/"; |
|
|
|
// const paymentStatusApi = "/api/payment/status/"; |
|
|
|
// const payloadUrl = "/api/payment/wallet/fps/enquiryfpspayload/"; |
|
|
|
// const receiverUrl = "/noti-api/payment/payment-notification"; |
|
|
|
|
|
|
|
//timer |
|
|
|
const currentTimer = React.useRef(); |
|
|
|
const [time, setTime] = React.useState(0); |
|
|
|
|
|
|
|
React.useEffect(() => { |
|
|
|
setFpsqrcodeimgbase64("") |
|
|
@@ -52,6 +58,11 @@ const Index = () => { |
|
|
|
setPaymentData(location.state) |
|
|
|
} |
|
|
|
loadForm(); |
|
|
|
currentTimer.current = setInterval(() => { |
|
|
|
getPaymentStatus(); |
|
|
|
setTime((prevTime) => prevTime + 1); |
|
|
|
}, 500); |
|
|
|
return () => clearInterval(currentTimer.current); |
|
|
|
}, []); |
|
|
|
|
|
|
|
React.useEffect(() => { |
|
|
@@ -60,82 +71,90 @@ const Index = () => { |
|
|
|
|
|
|
|
|
|
|
|
const loadForm = () => { |
|
|
|
HttpUtils.post({ |
|
|
|
url: paymentPath+loadPaymentUrl, |
|
|
|
params:{ |
|
|
|
"transactionid": paymentData.transactionid, |
|
|
|
"webtoken": paymentData.webtoken, |
|
|
|
"paymentmethod":"04,BCFP,FPS", |
|
|
|
"order": { |
|
|
|
"totalamount":paymentData.amount, |
|
|
|
"currency":"HKD", |
|
|
|
"orderdetail": |
|
|
|
[ |
|
|
|
{ |
|
|
|
"itemid": "1", |
|
|
|
"qty":"1", |
|
|
|
"unitprice":paymentData.amount, |
|
|
|
"amount":paymentData.amount |
|
|
|
}, |
|
|
|
] |
|
|
|
}, |
|
|
|
// "locale":"<locale>", |
|
|
|
// "eserviceid":"<eserviceid>" |
|
|
|
}, |
|
|
|
onSuccess: function(responseData){ |
|
|
|
/* |
|
|
|
{ |
|
|
|
"paymentid": "<paymentid>", |
|
|
|
"paymentstatus": "<paymentstatus>", |
|
|
|
"fpsmerchanttimeoutdatetime": <fpsmerchanttimeoutdatetime>, |
|
|
|
"fpsqrcodeimgbase64": "<fpsqrcodeimgbase64>", |
|
|
|
"fpsqrcodeurl": "<fpsqrcodeurl>" |
|
|
|
} |
|
|
|
*/ |
|
|
|
setFpsqrcodeimgbase64(responseData.fpsqrcodeimgbase64); |
|
|
|
setPaymentid(responseData.paymentid); |
|
|
|
setFpsmerchanttimeoutdatetime(responseData.fpsmerchanttimeoutdatetime); |
|
|
|
const parsedUrl = new URL(responseData.fpsqrcodeurl); |
|
|
|
const fpsqrcodeurl = parsedUrl.pathname |
|
|
|
setFpsqrcodeurl(fpsqrcodeurl) |
|
|
|
polling() |
|
|
|
} |
|
|
|
}); |
|
|
|
const timeoutdatetime = "2023-10-26T09:04:30Z[UTC]" |
|
|
|
const convertedDateString = timeoutdatetime.replace("[UTC]", ""); |
|
|
|
setFpsmerchanttimeoutdatetime(convertedDateString) |
|
|
|
setPaymentid("C202310268000681") |
|
|
|
|
|
|
|
// HttpUtils.post({ |
|
|
|
// url: paymentPath+loadPaymentUrl, |
|
|
|
// params:{ |
|
|
|
// "transactionid": paymentData.transactionid, |
|
|
|
// "webtoken": paymentData.webtoken, |
|
|
|
// "paymentmethod":"04,BCFP,FPS", |
|
|
|
// "order": { |
|
|
|
// "totalamount":paymentData.amount, |
|
|
|
// "currency":"HKD", |
|
|
|
// "orderdetail": |
|
|
|
// [ |
|
|
|
// { |
|
|
|
// "itemid": "1", |
|
|
|
// "qty":"1", |
|
|
|
// "unitprice":paymentData.amount, |
|
|
|
// "amount":paymentData.amount |
|
|
|
// }, |
|
|
|
// ] |
|
|
|
// }, |
|
|
|
// // "locale":"<locale>", |
|
|
|
// // "eserviceid":"<eserviceid>" |
|
|
|
// }, |
|
|
|
// onSuccess: function(responseData){ |
|
|
|
// /* |
|
|
|
// { |
|
|
|
// "paymentid": "<paymentid>", |
|
|
|
// "paymentstatus": "<paymentstatus>", |
|
|
|
// "fpsmerchanttimeoutdatetime": <fpsmerchanttimeoutdatetime>, |
|
|
|
// "fpsqrcodeimgbase64": "<fpsqrcodeimgbase64>", |
|
|
|
// "fpsqrcodeurl": "<fpsqrcodeurl>" |
|
|
|
// } |
|
|
|
// */ |
|
|
|
// setFpsqrcodeimgbase64(responseData.fpsqrcodeimgbase64); |
|
|
|
// setPaymentid(responseData.paymentid); |
|
|
|
// setFpsmerchanttimeoutdatetime(responseData.fpsmerchanttimeoutdatetime); |
|
|
|
// setPaymentstatuscode(responseData.paymentstatuscode); |
|
|
|
// // const parsedUrl = new URL(responseData.fpsqrcodeurl); |
|
|
|
// // const fpsqrcodeurl = parsedUrl.pathname; |
|
|
|
// // const openPASGUrl = pasgPath + '?pay_req_obj=' + encodeURIComponent(responseData.fpsqrcodeurl) + '&callback=' |
|
|
|
// // + encodeURIComponent(paymentPath + payment.config.fpscallbackPage); |
|
|
|
// // setFpsqrcodeurl(openPASGUrl) |
|
|
|
// } |
|
|
|
// }); |
|
|
|
} |
|
|
|
|
|
|
|
const getPaymentStatus = () => { |
|
|
|
HttpUtils.post({ |
|
|
|
url: paymentPath+paymentStatusApi+paymentid, |
|
|
|
params:{ |
|
|
|
"apprefid": paymentData.transactionid, |
|
|
|
"webtoken": paymentData.webtoken, |
|
|
|
}, |
|
|
|
onSuccess: function(responseData){ |
|
|
|
const paymentstatuscode = responseData.paymentdetail.result.paymentstatuscode; |
|
|
|
if (paymentstatuscode === 'APPR') { |
|
|
|
const timestamp = '?t=' + Date.now(); |
|
|
|
window.top.location.href = payment.config.domain + payment.config.ackPagePath + timestamp; |
|
|
|
} else if (paymentstatuscode === 'CANC') { |
|
|
|
window.top.location.href = payment.config.domain + payment.config.indexPagePath; |
|
|
|
} else { |
|
|
|
window.top.location.href = payment.config.domain + payment.config.errPagePath; |
|
|
|
} |
|
|
|
}, |
|
|
|
onError: function(){ |
|
|
|
cancelPayment() |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
// HttpUtils.post({ |
|
|
|
// url: paymentPath+paymentStatusApi+paymentid, |
|
|
|
// params:{ |
|
|
|
// "apprefid": paymentData.transactionid, |
|
|
|
// "webtoken": paymentData.webtoken, |
|
|
|
// }, |
|
|
|
// onSuccess: function(responseData){ |
|
|
|
// const paymentstatuscode = responseData.paymentdetail.result.paymentstatuscode; |
|
|
|
// if (paymentstatuscode === 'APPR') { |
|
|
|
// const timestamp = '?t=' + Date.now(); |
|
|
|
// window.top.location.href = paymentPath + payment.config.ackPagePath + timestamp; |
|
|
|
// } else if (paymentstatuscode === 'CANC') { |
|
|
|
// window.top.location.href = paymentPath + payment.config.indexPagePath; |
|
|
|
// } else { |
|
|
|
// window.top.location.href = paymentPath + payment.config.errPagePath; |
|
|
|
// } |
|
|
|
// }, |
|
|
|
// onError: function(){ |
|
|
|
// cancelPayment() |
|
|
|
// clearInterval(currentTimer.current); |
|
|
|
// } |
|
|
|
// }); |
|
|
|
}; |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
const timeOut = fpsmerchanttimeoutdatetime=now()?500:null; |
|
|
|
const interval = setInterval(() => { |
|
|
|
getPaymentStatus(); |
|
|
|
console.log("test"); |
|
|
|
}, timeOut); |
|
|
|
|
|
|
|
return () => clearInterval(interval); |
|
|
|
}, []); |
|
|
|
React.useEffect(() => { |
|
|
|
const timeOutDate = new Date(fpsmerchanttimeoutdatetime); |
|
|
|
const currentTime = new Date; |
|
|
|
if (timeOutDate.getTime()<currentTime.getTime()){ |
|
|
|
console.log("stop"); |
|
|
|
clearInterval(currentTimer.current); |
|
|
|
} |
|
|
|
},[time]) |
|
|
|
|
|
|
|
const cancelPayment = ()=>{ |
|
|
|
HttpUtils.post({ |
|
|
|