当客户位于网站结帐页面时,我需要检测卡类型:借记卡或信用卡。
我正在使用该库,即 https://github.com/braintree/credit-card-type 已经确定了该卡 brand 即 Visa、Amex、Mastercard 等。但这些不提供该卡 type 信息。这可能吗?
rapidapi 的另一个 api 解决方案银行卡 Bin Num Check 有 250K+ 已发行的卡类型。
只需一次 GET 请求,其中包含卡片前 6 个数字。并查看结果
{ "bin_number": 535177, "bank": "Finansbank A.S.", "scheme": "MASTERCARD", "type": "Debit", "country": "Turkey" }
`
// Function to detect card company based on the card number's first digits
function detectCardCompany(cardNumber) {
// Remove non-digit characters from the card number
const cleanedCardNumber = cardNumber.replace(/\D/g, '');
// Determine the card company based on the first digits
const firstDigits = cleanedCardNumber.slice(0, 6); // Consider the first 6 digits
switch (true) {
case /^4/.test(firstDigits):
return require(`../../assets/social/visa.png`);
case /^5[1-5]/.test(firstDigits):
return require(`../../assets/social/master.png`);
case /^3[47]/.test(firstDigits):
return require(`../../assets/social/american.png`);
case /^6/.test(firstDigits):
return require(`../../assets/social/discover.png`);
case /^30[0-5]|^36|^38|^39/.test(firstDigits):
return require(`../../assets/social/master.png`);
case /^35(2[89]|[3-8][0-9])/.test(firstDigits):
return require(`../../assets/social/jcb.png`);
case /^62/.test(firstDigits):
return require(`../../assets/social/union.png`);
default:
return require(`../../assets/social/visa.png`);
}
}
`