瀏覽代碼

fix payment limit check

CR023
Jason Chuang 1 周之前
父節點
當前提交
fe574f6fbf
共有 2 個檔案被更改,包括 84 行新增29 行删除
  1. +6
    -6
      src/pages/Payment/MultiPaymentWindow.js
  2. +78
    -23
      src/pages/Payment/index.js

+ 6
- 6
src/pages/Payment/MultiPaymentWindow.js 查看文件

@@ -346,27 +346,27 @@ const MultiPaymentWindow = (props) => {
</Grid> </Grid>
<Grid item sx={{display: { sm: 'block', md: 'none' }}}></Grid> <Grid item sx={{display: { sm: 'block', md: 'none' }}}></Grid>
<Grid item> <Grid item>
<Button variant="contained" color="white" onClick={selectedPaymentMethodHandle("FPS")} disabled={props.fpsStatus.active === "N" || isPaying}>
<Button variant="contained" color="white" onClick={selectedPaymentMethodHandle("FPS")} disabled={props.fpsStatus.active !== "Y" || isPaying}>
<img className={fpsClass} src={FpsIcon} width="80" height="80" alt="FPS"></img> <img className={fpsClass} src={FpsIcon} width="80" height="80" alt="FPS"></img>
</Button> </Button>
</Grid> </Grid>
<Grid item> <Grid item>
<Button variant="contained" color="white" onClick={selectedPaymentMethodHandle("Visa")} disabled={props.creditCardStatus.active === "N" || isPaying}>
<Button variant="contained" color="white" onClick={selectedPaymentMethodHandle("Visa")} disabled={props.creditCardStatus.active !== "Y" || isPaying}>
<img className={visaClass} src={VisaIcon} width="80" height="80" alt="Visa"></img> <img className={visaClass} src={VisaIcon} width="80" height="80" alt="Visa"></img>
</Button> </Button>
</Grid> </Grid>
<Grid item> <Grid item>
<Button variant="contained" color="white" onClick={selectedPaymentMethodHandle("MasterCard")} disabled={props.creditCardStatus.active === "N" || isPaying}>
<Button variant="contained" color="white" onClick={selectedPaymentMethodHandle("MasterCard")} disabled={props.creditCardStatus.active !== "Y" || isPaying}>
<img className={mastercardClass} src={MasterIcon} width="80" height="80" alt="MasterCard"></img> <img className={mastercardClass} src={MasterIcon} width="80" height="80" alt="MasterCard"></img>
</Button> </Button>
</Grid> </Grid>
<Grid item> <Grid item>
<Button variant="contained" color="white" onClick={selectedPaymentMethodHandle("UnionPay")} disabled={props.unionPayStatus.active === "N" || isPaying}>
<Button variant="contained" color="white" onClick={selectedPaymentMethodHandle("UnionPay")} disabled={props.unionPayStatus.active !== "Y" || isPaying}>
<img className={unionPayClass} src={UnionPayIcon} width="80" height="80" alt="UnionPay"></img> <img className={unionPayClass} src={UnionPayIcon} width="80" height="80" alt="UnionPay"></img>
</Button> </Button>
</Grid> </Grid>
<Grid item> <Grid item>
<Button variant="contained" color="white" onClick={selectedPaymentMethodHandle("JCB")} disabled={props.unionPayStatus.active === "N" || isPaying}>
<Button variant="contained" color="white" onClick={selectedPaymentMethodHandle("JCB")} disabled={props.creditCardStatus.active !== "Y" || isPaying}>
<img className={jCBClass} src={JcbIcon} width="80" height="80" alt="JCB"></img> <img className={jCBClass} src={JcbIcon} width="80" height="80" alt="JCB"></img>
</Button> </Button>
</Grid> </Grid>
@@ -374,7 +374,7 @@ const MultiPaymentWindow = (props) => {
{props.browserType==mobileBrowser? {props.browserType==mobileBrowser?
null null
: :
<Button variant="contained" color="white" onClick={selectedPaymentMethodHandle("PPS")} disabled={props.ppsStatus.active === "N" || isPaying}>
<Button variant="contained" color="white" onClick={selectedPaymentMethodHandle("PPS")} disabled={props.ppsStatus.active !== "Y" || isPaying}>
<img className={pPSClass} src={PpsIcon} width="80" height="80" alt="PPS"></img> <img className={pPSClass} src={PpsIcon} width="80" height="80" alt="PPS"></img>
</Button> </Button>
} }


+ 78
- 23
src/pages/Payment/index.js 查看文件

@@ -106,6 +106,12 @@ const Index = () => {
setTotalAmount(totalAmount); setTotalAmount(totalAmount);
setSelectedPaymentMethod("") setSelectedPaymentMethod("")
setConfirmPayment(false) setConfirmPayment(false)
setOnReady(false)
setAvailableMethods([])
setFPSStatus({})
setCreditCardStatus({})
setUnionPayStatus({})
setPPSStatus({})
if (totalAmount > 0) { if (totalAmount > 0) {
getAvailablePayment() getAvailablePayment()
getTransactionId() getTransactionId()
@@ -190,48 +196,97 @@ const Index = () => {
} }
}, [afterConfirmPayment]); }, [afterConfirmPayment]);


const getAvailablePayment = () =>{
const filterPreferPaymentMethodsByLimit = (methods, amount, limits) => {
if (!methods) {
return [];
}
if (!limits) {
return methods;
}
return methods.filter((method) => {
const key = (method || "").toLowerCase();
let maxLimit;
if (key === "fps") {
maxLimit = limits.fpsLimitRecord?.maxLimit;
} else if (key === "pps" || key === "ppsb") {
maxLimit = limits.ppsbLimitRecord?.maxLimit;
} else if (key === "unionpay") {
maxLimit = limits.unionPlayLimitRecord?.maxLimit;
} else if (key === "visa" || key === "mastercard" || key === "jcb" || key === "creditcard") {
maxLimit = limits.creditCardLimitRecord?.maxLimit;
} else {
return true;
}
return maxLimit == null || amount <= maxLimit;
});
};

const filterAvailableMethodsByLimit = (methods, amount, limits) => {
if (!methods) {
return [];
}
if (!limits) {
return methods;
}
return methods.filter((method) => {
if (method.subtype === "FPS") {
return limits.fpsLimitRecord?.maxLimit == null || amount <= limits.fpsLimitRecord.maxLimit;
}
if (method.subtype === "PPS") {
return limits.ppsbLimitRecord?.maxLimit == null || amount <= limits.ppsbLimitRecord.maxLimit;
}
if (method.subtype === "CreditCard") {
const isUnionPay = method.supportedcard?.some((card) => card === "UnionPay");
if (isUnionPay) {
return limits.unionPlayLimitRecord?.maxLimit == null || amount <= limits.unionPlayLimitRecord.maxLimit;
}
return limits.creditCardLimitRecord?.maxLimit == null || amount <= limits.creditCardLimitRecord.maxLimit;
}
return true;
});
};

const requestPaymentAvailability = (methods, limits) => {
HttpUtils.post({ HttpUtils.post({
url: UrlUtils.PAYMENT_AVAILABLE_PAYMENT, url: UrlUtils.PAYMENT_AVAILABLE_PAYMENT,
params: { params: {
"locale": locale === 'en' ?local.en:locale === 'zh-HK' ?local.zh:local.cn, "locale": locale === 'en' ?local.en:locale === 'zh-HK' ?local.zh:local.cn,
"amount": totalAmount, "amount": totalAmount,
// "eserviceids": [
// "<eserviceid>", "<eserviceid>"
// ],
"preferpaymentmethods": preferpaymentmethods
"preferpaymentmethods": methods
}, },
onSuccess: (responseData) => { onSuccess: (responseData) => {
let availableMethods = responseData.availablepaymentmethods;
let availableMethods = filterAvailableMethodsByLimit(
responseData.availablepaymentmethods || [], totalAmount, limits
);
setAvailableMethods(availableMethods); setAvailableMethods(availableMethods);
HttpUtils.get({
url: UrlUtils.PAYMENT_LIMIT_SETTING_LIST,
params: {},
onSuccess: (responseData) => {
// console.log(responseData)
setPaymentLimit(responseData)
},
onError: () =>{
// setOnReady(true)
}
});
if (availableMethods.length === 0) {
setOnReady(true)
}
}, },
onError: () =>{ onError: () =>{
setOnReady(true) setOnReady(true)
} }
}); });
};

const getAvailablePayment = () =>{
HttpUtils.get({ HttpUtils.get({
url: UrlUtils.PAYMENT_LIMIT_SETTING_LIST, url: UrlUtils.PAYMENT_LIMIT_SETTING_LIST,
params: {}, params: {},
onSuccess: (responseData) => { onSuccess: (responseData) => {
// console.log(responseData)
setPaymentLimit(responseData) setPaymentLimit(responseData)

const methodsWithinLimit = filterPreferPaymentMethodsByLimit(
preferpaymentmethods, totalAmount, responseData
);
if (methodsWithinLimit.length === 0) {
setAvailableMethods([])
setOnReady(true)
return;
}
requestPaymentAvailability(methodsWithinLimit, responseData);
}, },
onError: () =>{ onError: () =>{
// setOnReady(true)
requestPaymentAvailability(preferpaymentmethods);
} }
}); });


@@ -383,7 +438,7 @@ const Index = () => {
setFPSStatus(method) setFPSStatus(method)
} }
} else if (method.subtype === "CreditCard") { } else if (method.subtype === "CreditCard") {
method.supportedcard.forEach((supportedcard) => {
(method.supportedcard || []).forEach((supportedcard) => {
if (supportedcard === "JCB" || supportedcard === "MasterCard" || supportedcard === "Visa") { if (supportedcard === "JCB" || supportedcard === "MasterCard" || supportedcard === "Visa") {
setCreditCardStatus(method) setCreditCardStatus(method)
} else { } else {


Loading…
取消
儲存