Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 56aafee
Showing
6 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/test.js | ||
/README.md | ||
/script.js |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# BIN/IIN look up | ||
|
||
This module uses the https://binlist.net service to return information about a | ||
card by it's BIN number. | ||
|
||
## What is a BIN? | ||
|
||
The BIN is the first 4-8 characters of a card number: `xxxx xxxx ...`. You can | ||
pass any range of 4-8 numbers. More numbers will return more information. | ||
|
||
## Use | ||
|
||
```js | ||
// paid plan | ||
var b = require('binlookup')('my-api-key'); | ||
|
||
// free plan | ||
var b = require('binlookup')(); | ||
|
||
b('457173', function( err, data ){ | ||
if (err) | ||
return console.error(err); | ||
|
||
console.log(data); | ||
}); | ||
``` | ||
|
||
An example of the `data` variable: | ||
|
||
```js | ||
{ | ||
bin: "45717360", | ||
brand: "VISA", | ||
sub_brand: "DANKORT", | ||
country_code: "DK", | ||
country_name: "Denmark", | ||
bank: "Jyske Bank", | ||
card_type: "DEBIT", | ||
card_category: "CLASSIC", | ||
latitude: "56", | ||
longitude: "10", | ||
query_time: "352.309µs", | ||
} | ||
``` | ||
|
||
If you're using their free plan, just leave out the api key. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use strict'; | ||
|
||
module.exports = bl; | ||
|
||
bl.lookup = lookup; | ||
|
||
function bl( key ){ | ||
return function( bin, cb ){ | ||
lookup(key, bin, cb); | ||
} | ||
} | ||
|
||
function lookup( key, bin, cb ){ | ||
var proto = (key ? 'https' : 'http'); | ||
var url = proto + '://www.binlist.net/json/' + bin.slice(0, 8); | ||
|
||
var xhr = new XMLHttpRequest(); | ||
xhr.open('GET', url, true /* async*/); | ||
|
||
xhr.onreadystatechange = function(){ | ||
xhrcb(xhr, cb); | ||
}; | ||
|
||
if (key) | ||
xhr.setRequestHeader('Authorization', 'Basic ' + btoa(key + ':')); | ||
|
||
xhr.send(); | ||
} | ||
|
||
function xhrcb( xhr, cb ){ | ||
if (xhr.readyState !== 4) | ||
return; | ||
|
||
var status; | ||
|
||
try { status = xhr.status } catch(e) { status = 0; } | ||
|
||
var ok = status && (status / 100 | 0) === 2; | ||
var body = ok ? JSON.parse(xhr.responseText) : null; | ||
|
||
cb && cb(ok ? null : xhr, body); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "binlookup", | ||
"version": "0.0.1", | ||
"description": "Look up BIN/IIN numbers using binlist.net", | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:paylike/binlookup.git" | ||
}, | ||
"testling": { | ||
"files": "test.js", | ||
"browsers": [ | ||
"ie/6..latest", | ||
"chrome/22..latest", | ||
"firefox/16..latest", | ||
"safari/latest", | ||
"opera/11.0..latest", | ||
"iphone/6", | ||
"ipad/6", | ||
"android-browser/latest" | ||
] | ||
}, | ||
"scripts": { | ||
"test": "npm run test:browser", | ||
"test:browser": "testling" | ||
}, | ||
"author": "Thomas Jensen <thomas@paylike.io> (https://paylike.io)", | ||
"devDependencies": { | ||
"tape": "^3.5.0", | ||
"testling": "^1.7.1", | ||
"without-keys": "^0.0.3" | ||
}, | ||
"license": "MIT" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use strict'; | ||
|
||
var test = require('tape'); | ||
var withoutKeys = require('without-keys'); | ||
var bl = require('./'); | ||
|
||
var bin = '45717360'; | ||
var result = { | ||
bin: "45717360", | ||
brand: "VISA", | ||
sub_brand: "DANKORT", | ||
country_code: "DK", | ||
country_name: "Denmark", | ||
bank: "Jyske Bank", | ||
card_type: "DEBIT", | ||
card_category: "CLASSIC", | ||
latitude: "56", | ||
longitude: "10", | ||
}; | ||
|
||
test('without a key', function( t ){ | ||
t.plan(4); | ||
|
||
var b = bl(); | ||
|
||
b(bin, function( err, r ){ | ||
t.notOk(err); | ||
t.deepEqual(withoutKeys(r, [ 'query_time' ]), result); | ||
}); | ||
|
||
b('bad', function( err, r ){ | ||
t.ok(err); | ||
t.notOk(r); | ||
}); | ||
}); | ||
|
||
test('with a key', { skip: !process.env.KEY }, function( t ){ | ||
t.plan(4); | ||
|
||
var b = bl(process.env.KEY); | ||
|
||
b(bin, function( err, r ){ | ||
t.notOk(err); | ||
t.deepEqual(withoutKeys(r, [ 'query_time' ]), result); | ||
}); | ||
|
||
b('bad', function( err, r ){ | ||
t.ok(err); | ||
t.notOk(r); | ||
}); | ||
}); |