46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
import dayjs from "dayjs";
|
|
import md5 from "js-md5";
|
|
|
|
const handleParams = (obj) =>
|
|
Object.entries(obj).reduce((total, curr) => {
|
|
if (!total) {
|
|
total += `${curr[0]}=${curr[1]}`;
|
|
} else {
|
|
total += `|${curr[0]}=${curr[1]}`;
|
|
}
|
|
return total;
|
|
}, "");
|
|
|
|
export default function usePay() {
|
|
const payFunc = (args) => {
|
|
const { order_no, notify_url, TranAmt, MerName, sign, plain_text } = args;
|
|
const MercCode = import.meta.env.VITE_YCNC_MERCH_CODE;
|
|
const tranAmt = Number(TranAmt).toFixed(2);
|
|
const Plain = {
|
|
MercUrl: notify_url,
|
|
TranAmt: tranAmt,
|
|
TermSsn: order_no,
|
|
BackLink: encodeURIComponent(
|
|
`${window.location.origin}${
|
|
window.location.pathname || ""
|
|
}/#/pages/ycysp/orderDetail?order_no=${order_no}&isPayBack=true`
|
|
),
|
|
psbcmcc: "LSXD",
|
|
TxnDt: dayjs(Date.now()).format("YYYY-MM-DD"),
|
|
MercCode: MercCode,
|
|
IsIntegral: "1",
|
|
MerName: MerName,
|
|
};
|
|
const params = {
|
|
Plain: handleParams(Plain),
|
|
plainText: plain_text,
|
|
sign: sign,
|
|
Signature: "",
|
|
};
|
|
console.log("CodePay-plain", Plain);
|
|
console.log("CodePay-params", params);
|
|
Fw.device.api.handCodePay(params);
|
|
};
|
|
return { payFunc };
|
|
}
|