Last active
November 30, 2023 02:14
-
-
Save quentinlamamy/8f3a63dd66940d4139e3b03ac7126b0c to your computer and use it in GitHub Desktop.
A emv smartcard parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Parse the first track of an emv smartcard | |
* @param {String} data - The first track of the card | |
*/ | |
async function parseStripe(data) { | |
let split = data.split("^"); | |
let cardNumber = split[0].substring(2); | |
let name = split[1]; | |
let expiration = split[2].substring(0, 4); | |
let serviceCode = split[2].substring(4, 7); | |
let discretionaryData = split[2].substring(7); | |
let bin = cardNumber.substring(0, 6); | |
await fetch('https://data.handyapi.com/bin/' + bin) | |
.then(response => response.json()) | |
.then(data => { | |
console.log( | |
data?.Scheme?.padEnd(13, " "), | |
data?.Type?.padEnd(7, " "), | |
cardNumber.padEnd(20, " "), | |
name.replaceAll(" ","").trim().padEnd(20, " "), | |
expiration.trim().padEnd(5, " "), | |
data.CardTier ? data.CardTier.padEnd(30, " ") : "".padEnd(30, "*"), | |
data.Country && data.Country.Name ? data.Country.Name.padEnd(15, " ") : "".padEnd(15, "*"), | |
); | |
}) | |
.catch(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment