GithubHelp home page GithubHelp logo

anthrax3 / banks-db Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mungell/banks-db

0.0 1.0 0.0 359 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%

banks-db's Introduction

Banks DB

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.

banks-db usage example

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

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);
}

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

achkasov avatar ai avatar aminoser avatar amio avatar aran112000 avatar bbsody avatar drugoi avatar dylanlacey avatar emilianox avatar fnnzzz avatar grigorii-zander avatar hz-labs avatar itmilos avatar keksike avatar lamo2k123 avatar linda-rian avatar luchanso avatar lukegb avatar madyankin avatar maraisr avatar maslor avatar oguzzkilic avatar olegman avatar praffn avatar rowno avatar sashaegorov avatar sea-unicorn avatar suxxes avatar vladdenisov avatar zhurbin avatar

Watchers

 avatar

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.