Giter Site home page Giter Site logo

ramoona / banks-db Goto Github PK

View Code? Open in Web Editor NEW
716.0 26.0 109.0 871 KB

Community driven database to get bank info (name, brand color etc.) by bankcard prefix (BIN)

Home Page: https://ramoona.github.io/banks-db-demo/

JavaScript 100.00%
card-number brand-colors bank-card bank card-info banks-db bankcard-prefix

banks-db's Introduction

Build Status Latest Stable Version NPM Downloads

Returns bank's name and brand color by bankcard prefix (BIN).

It is useful on billing pages to use bank’s brand color when user starts to type card number.

It's a community driven database, so it can potentially contains mistakes. It's not a problem for UX enhancement, but you must not use Banks DB in your billing logic.

Demo

Try your card prefix in our demo. Note that only first 6 digits of card number are required.

Usage

PostCSS

With postcss-banks-db and postcss-contrast you can generate CSS for each bank:

.billing-form {
    transition: background .6s, color .6s;
    background: #eee;
}
@banks-db-template {
    .billing-form.is-%code% {
        background-color: %color%;
        color: contrast(%color%);
    }
}

And then switch bank’s style in JS:

import banksDB from 'banks-db';

const bank = banksDB(cardNumberField.value);
if ( bank.code ) {
  billingForm.className = 'billing-form is-' + (bank.code || 'other');
  bankName.innerText = bank.country === 'ru' ? bank.localTitle : bank.engTitle;
} else {
  billingForm.className = 'billing-form';
  bankName.innerText = '';
}

CSS-in-JS

import contrast from 'contrast';
import banksDB  from 'banks-db';

BillingForm  = ({ cardNumber }) => {
  const title, color;
  const bank = banksDB(this.props.cardNumber);
  if ( bank.code ) {
    title = bank.country === 'ru' ? bank.localTitle : bank.engTitle;
    color = bank.color;
  } else {
    title = '';
    color = '#eee';
  }
  return (
    <div style={{
      transition: 'background .6s, color .6s',
      background: color,
      color:      contrast(color) === 'light' ? 'black' : 'white'
    }}>
      <h2>{ title }</h2></div>
  );
}

Other Best Practices

See also best practices for billing forms:

API

There are two options to use BanksDB depends of whether you need specific countries or not.

If you need banks for all countries

Library exports banksDB function. It accepts bankcard number and returns bank object.

var banksDB = require('banks-db');
var bank    = banksDB('5275 9400 0000 0000');
console.log(bank.code) //=> 'ru-citibank'
console.log(bank.type) //=> 'mastercard'

If database doesn't contain some bank prefix, bank object will have only type field.

var unknown = banksDB('4111 1111 1111 1111');
console.log(bank.code) //=> undefined
console.log(bank.type) //=> 'visa'

You can also get banks database by banksDB.data:

for ( let bank of banksDB.data ) {
    console.log(bank);
}

If you need only banks for specific countries

Instead of banks-db use banks-db/core:

var banksDBCore = require('banks-db/core');

Then require desired countries from banks-db/banks by two letters code:

var banksOfRussia = require('banks-db/banks/ru');
var banksOfChina = require('banks-db/banks/cn');

All that left is to call banksDBCore with your countries data to initialize. banksDBCore is a function that accepts one argument with banks data for countries that you've specified, and returns an instance of BanksDB object with findBank method and data property.

var BanksDB = banksDBCore([banksOfRussia, banksOfChina]);
// var BanksDB = banksDBCore(banksOfRussia); no need for an array if there's only one country

That's it! Ready to use:

var bank = BanksDB.findBank('5275 9400 0000 0000');
var data = BanksDB.data;

Bank Object

  • type: bankcard type. For example, 'visa' or 'mastercard'. Banks DB will return it even if bank is unknown.
  • code: unique code, contains country and name. For example, you can use it to generate CSS selectors for each bank.
  • color: bank's brand color in HEX-format.
  • localTitle: bank's title in local language.
  • engTitle: international bank's title.
  • name: short bank's name (not unique). For example, 'citibank'.
  • country: bank's operation country. For example, you can use it to display localTitle for local banks and engTitle for others.
  • url: bank's website URL.

Contributing

In case your bankcard doesn't work, please check if your bank already in Banks DB:

  • If your bank is already included, you can open an issue with your prefix (NOT full number of your card, just first 5 or 6 symbols) or send a pull request.
  • Otherwise you can add a new bank (see contributing guide).

Changelog

See CHANGELOG.md or release notes (with commits history).

banks-db's People

Contributors

achedeuzot avatar achkasov avatar ai avatar amio avatar aran112000 avatar baitun avatar c0nfusecode avatar dependabot[bot] avatar drugoi avatar dylanlacey avatar emilianox avatar fnnzzz avatar grigorii-zander avatar hz-labs avatar keksike avatar kemalturk avatar lamo2k123 avatar lari4 avatar lewiseason avatar linda-rian avatar luchanso avatar madyankin avatar maraisr avatar oguzzkilic avatar olegman avatar sashaegorov avatar sea-unicorn avatar suxxes avatar vladdenisov avatar zhurbin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

banks-db's Issues

Normalize colors

Some colors use upper #FFF, some lower case #fff. We should add it to linter and normallize current data.

Add more popular USA banks

Seems like we need to add more popular USA banks by our self. Only in this case users will trust in us and contribute.

Reddit users expect that we have AmEx, Chase, BofA, and Capital One banks.

We need to find these BINs somehow.

Add result.code

Right now banksDB usage code is quite big:

let bank = banksDB(uuser.card);
if ( bank.name ) {
    return 'is-' + bank.country + '-' + bank.name;
} else {
    return 'is-other';
}

If in findBank function we will generate code = bank.country + '-' + bank.name and add it to result.code we can simplify this usage code to:

return 'is-' + (banksDB(uuser.card).code || 'other');

tool for grab bin codes

Hi, I wrote a small tool here (just for fun), which parses bin codes of banks and allows you filter them by country and bank name.

Perhaps this will help you include more banks.
A little later I will do a pullback with a list of Ukrainian.

link: https://github.com/fnnzzz/macGRUBer

Add flag to distinguish Closed/Defunt banks

There are examples of banks that no longer issue cards to customers and banks with revoked licenses. I suggest adding some flag to json to mark those banks, for example "defunct: true"

Add LCL (France) Visa

// banks/fr/lcl.json
  {
    "name": "LCL",
    "prefixes": [
      497203
    ],
    "country": "fr",
    "localTitle": "LCL",
    "engTitle": "LCL",
    "url": "https://particuliers.secure.lcl.fr/",
    "color": "#263F92"
  }

const in for-in

if (bank) {
    for (const el in bank) {
      result[el] = bank[el];
    }
  }

const can be used in for-in loop, so this line broke Firefox.

This issue is really critical, because 0.7 can’t be used in any production build with Firefox.

Consider removing manual require of each individual banks/*.json

See index.js:

const banks = [
  require('./banks/alfabank'),
  require('./banks/raiffeisen'),
  require('./banks/sberbank'),
  require('./banks/tinkoff'),
  require('./banks/vtb24'),
  require('./banks/mdm'),
];

Those requires bloats the main file(and it will grow in future) and create unnecessary step when adding new banks. We can either move those requires to banks/index.js (1) or just import everything from /banks directory while iterating over its files(2). Either way will make at first lint test unnecessary(YAY).

Separate banks file by countries

There are many banks that work internationally, we need to have one bank-json for bank operating in each country.

For example, there are Sberbank in CZ in BY and in RU. There is VTB in RU and BY. There are Alfabank in RU and BY.

I suggest that we create directory for each country in banks folder and put ambigous jsons here.
Non-ambigous jsons may be left where they are. We also need to adjust build scripts?

What do you think? Will PR with those changes be welcome?

Add ING Direct (France) Gold Mastercard

// banks/fr/ingdirect.json
  {
    "name": "ING Direct",
    "prefixes": [
      513625
    ],
    "country": "fr",
    "localTitle": "ING Direct",
    "engTitle": "ING Direct",
    "url": "http://www.ingdirect.fr/",
    "color": "#FF6200"
  }

Add new Rocketbank

New Rockebank card uses different backend bank, so we need to add new BIN: 5321 30

Outdated banks db in demo

Looks like db in demo is outdated. For example bin 424204 is already present in database, but shows as 'unknown'.

Suggest the card type within the card number prefix data.

I have a China Merchants Bank - Dual-Currency Credit Card, prefix is 5187 10, the card type is UnionPay AND MasterCard.

I find the code, types rule is write in type.js, and one card number just have one type.

So, I suggest the card type write in the card number prefix data, like:

banks/%country%/bankName.json

{
  ...,
  "prefixes": {
    "518710": {
      "types": ["UnionPay", "MasterCard"]
    },
    "622609": {
      "types": "UnionPay"
    }
  }
}

Credit Card, Savings Deposit Card, Prepaid card ...

How about to detect this?

Usually, One card is the one category of Credit Card(CC), Savings Deposit Card(DC), Prepaid Card(PC), Semi Credit Card(SCC)

Deliver db updates without updating npm

Thanks for awesome project. I think it will be even better, if we write a web service to get bank data by AJAX request.

Some sites don't get updates of npm packages during a few years - development is stopped.
They don't receive updates (e.g. just added card prefix of bank from Russian TOP-10).

Just request with a BIN is not the best way. In future by mistake it can cause sending full card number. API for downloading full DB on page loading is better (gzip work everywhere now) and then search as now - with no requests.

@ramoona What do you think? Do you need help?

Insert a last new line to generated indexes

Project .editorconfig tells that every file should contains \n at the end. It is a good practice, because cat package.json will have better output.

But autogerenerated banks/index.js and banks/xx/index.js miss this \n. GitHub even highlight it in diff.

Error on undefined bank card

First issue from in-the-wild usage on Amplifr.

Sometimes cardNumber become to undefined in app code. And when we send undefined to banksDB error raises: Undefined method toString in undefined.

Of course, it is not a banksDB issue and can be fixed by simple user.card || '' code. But we should care about user. More love and peace =^_^=.

I suggest to add some something like cardNumber || '' into findBank function.

Add Epayments Mastercard

Prefix: 5283 93

Epayments is just a provider. The card issued by PSI-Pay Ltd. This is how the card looks like:

epayments-russia

Add indent to autogenerated indexes

We need

module.exports = [
  require('./alfabank'),
  require('./citibank'),
  require('./mdm'),
  require('./raiffeisen'),
  require('./rocketbank'),
  require('./sberbank'),
  require('./siab'),
  require('./tinkoff'),
  require('./vtb24'),
  require('./yandex')
];

instead of:

module.exports = [
require('./alfabank'),
require('./citibank'),
require('./mdm'),
require('./raiffeisen'),
require('./rocketbank'),
require('./sberbank'),
require('./siab'),
require('./tinkoff'),
require('./vtb24'),
require('./yandex')
];

Lint country

After #12 we should update linter to check conformity of country folder name and bank country.

Add full usage example

We need usage example for PostCSS (postcss-banks-db, postcss-contrast) and Inline CSS.

Some of Sberbank prefixes are ambiguous

According to http://bins.pro/search?action=searchbins&bins=54690&bank=&country= bin 54690is ambiguous (546900 is HOIUPANK bank). I found all sberbank bins by this search request http://bins.pro/search?action=searchbins&bins=&bank=SBERBANK&country=RU - except 5 first bins all others are sberbank. And from here we can find all 5 and 6-digit bins for sberbank. I'm ready to make pull request which will fix present ambiguous bins and add all known from this database.

What about not banks cards?

Like Payoneer, Revolut, ePayments.

I could to add few Payoneer and Revolut numbers but it's not Banks right?

Bank Additions

Hi there,

Two British additions here...
TSB (FYI, Lloyds TSB have split in to two separate banks)
476367
476368

Barclaycard
492910

Sort prefixes

We should sort prefixes in build script. It will increase readability and allow to faster check, that prefix is already in database.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.