Files

20 lines
1.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use strict';
// 手续费预览使用整数分;真实费用由服务端按每笔客户付款生成。
(function(root){
const isAccount=account=>['助理信用卡','助理1信用卡','麦麦信用卡','助理2信用卡'].includes(account);
const ratePermille=6;
function rate(value=ratePermille){
if(!Number.isSafeInteger(value)||value<0||value>1000)throw new Error('信用卡手续费率须为0~1000的整数‰');
return value;
}
const normalizeAccount=account=>isAccount(account)?'麦麦信用卡':account;
const note=(value=ratePermille)=>`信用卡手续费(${rate(value)}‰)`;
const isFee=item=>item?.system==='credit_card'||String(item?.key||'').startsWith('card_fee:');
function amount(cents,value=ratePermille){
if(!Number.isSafeInteger(cents)||cents<0||cents>100000000000)throw new Error('客户付款金额无效');
return Number((BigInt(cents)*BigInt(rate(value))+500n)/1000n);
}
const api={isAccount,isFee,amount,rate,ratePermille,normalizeAccount,note};
if(typeof module==='object'&&module.exports)module.exports=api;else root.CreditCardFees=api;
})(typeof globalThis==='object'?globalThis:this);