New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@qiwi/card-info

Package Overview
Dependencies
Maintainers
4
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@qiwi/card-info

Library for getting card info by its PAN

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
4
Created
Source

card-info

js-standard-style buildStatus coverage dependencyStatus devDependencyStatus Code Climate

Complex utility for getting card info by its PAN. Supported providers:

  • preservice (dumb checks on client-side)
  • Binlist
  • Braintree
  • Freebinchecker
  • <CustomService>
Glossary
Install
    npm i @qiwi/card-info
    yarn add @qiwi/card-info
Usage examples
    import BinlistnetService from '@qiwi/card-info/service/binlistnet'
    const service = new BinlistnetService({...})

    service.getPaymentSystem('4111111111111111')    // Promise<'Visa'>
    service.getPaymentSystem('1234')                // Promise<null>
Promise and transport customization

By default card-info uses native Promise and fetch. You may replace them with any compatible api. For example, Bluebird and Axios

    import cardInfo from '@qiwi/card-info'
    import bluebird from 'bluebird'
    import axios from 'axios'
    
    cardInfo.Promise = bluebird
    cardInfo.transport = axios // or any polyfill, pull-fetch-iso, etc.
Service configuration

Each service implementation has own supported opts list, but there is a common part:

OptionTypeDefaultDescription
skipErrorbooltruemeans, that any fetch exception would be converted to null response
urlstringnullendpoint url
transportObjectnulloptional extras, merged to fetch arg.
For example, {retries: [{delay: 100},{delay: 2000}}
Service composition
    import {composer} from '@qiwi/card-info'
    import {PreService, BinlistnetService} from '@qiwi/card-info/service'
    
    const preService = new PreService()
    const binlistnetService = new BinlistnetService()
    const composed = compose(preService, binlistnetService)
    
    composed.getPaymentSystem('5321 4012 3456 7890')  // 'Mastercard'
    composed.getCardInfo('5321 4012 3456 7890')       // if preService returns null, the request would be processed with binlist.net backend
Braintree
    import {BraintreeService} from '@qiwi/card-info/service'
    const service = new BraintreeService({...})

    service.getPaymentSystem('6759649826438453')    // Promise<'Maestro'>
    service.getPaymentSystem('1234')                // Promise<null>

Braintree's credit-card-type lib is exposed as static property of the class, so you're able to use its API. For example, add custom definitions:

    BraintreeService.creditCardType.addCard({
        niceType: 'Foo',
        type: 'foo',
        prefixPattern: /^(12345)$/,
        exactPattern: /^(12345)\d*$/,
        gaps: [4, 8, 12],
        lengths: [16],
        code: {
            name: 'CVV',
            size: 3
        }
    })
    const service = new BraintreeService()
    
    service.getPaymentSystem('1234567890123456')    // Promise<'FOO'>
CustomService

Composer supports any impl of IService, so you're let to create your own class.

    import AbstractService from '@qiwi/card-info/service/abstract'

    class CustomService extends AbstractService implements IService {
        getPaymentSystem(pan: string): Promise<?IPaymentSystem> {
            // ...
        }
        getCardInfo(pan: string): Promise<?ICardInfo> {
            // ...
        }
    }
What's PreService

It's client-side implementation of service. The mostly used paysystems and bins are hardcoded for performance purposes.

Alternatives

Keywords

FAQs

Package last updated on 15 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc