Skip to content

Commit

Permalink
v0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
tjconcept committed Mar 14, 2015
0 parents commit 56aafee
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules
3 changes: 3 additions & 0 deletions .npmignore
@@ -0,0 +1,3 @@
/test.js
/README.md
/script.js
46 changes: 46 additions & 0 deletions README.md
@@ -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.
42 changes: 42 additions & 0 deletions index.js
@@ -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);
}
33 changes: 33 additions & 0 deletions package.json
@@ -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"
}
51 changes: 51 additions & 0 deletions test.js
@@ -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);
});
});

0 comments on commit 56aafee

Please sign in to comment.