Reputation: 41
I need to detect the card type: Debit or Credit when the customer is on website's checkout page.
I am using the library i.e https://github.com/braintree/credit-card-type already to determine the card brand i.e Visa,Amex,Mastercard etc. But these don't provide the card type info. Is this possible at all.
Upvotes: 3
Views: 9801
Reputation: 40
`
// 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`);
}
}
`
Upvotes: -1
Reputation: 632
Another api solution at rapidapi Bank Card Bin Num Check there are 250K+ issued card type.
Just one GET request with cards first 6 number. and see result
{ "bin_number": 535177, "bank": "Finansbank A.S.", "scheme": "MASTERCARD", "type": "Debit", "country": "Turkey" }
Upvotes: 0
Reputation: 219924
Yes, it is possible. You need to get a list of BIN (Bank Identification Numbers) which correlate to card type (debit or credit). You then can compare the BIN number, which is the first 4-9 numbers of the card, to that list which will tell you the card type.
Processors like Worldpay and Card Connect make lists like this available. I am unsure if there is a cost or not. I found this free one but you'll need to massage it a bit to consume it programmatically. This API also claims to be free.
Upvotes: 3