npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

generate-payment-card

v1.0.8

Published

This package generates valid payment card (credit, debit or otherwise) numbers.

Downloads

360

Readme

Generate payment card

This package generates a valid payment card number. A payment card can either be a credit, debit or otherwise.

npm version Coverage Status Node.js CI

🚀 Getting started

Install the package from npm.

npm install generate-payment-card.

🧰 Basic usage

var generatePaymentCard = require('generate-payment-card')
var payment_card_details = generatePaymentCard.generate({
    "card_brand": "american express",
    "user_digits": {
        "status": true,
        "digits": 2345678991,
        "position": "endswith"
    }
})

console.log(payment_card_details)
/* outputs: 
{
    "valid_card_number": "374692345678991"
    "cvv": 591
    "expiry_date": Fri Apr 24 2026 17:44:00 GMT+0100 (West Africa Standard Time)
    "balance: 0
    "issuer": "AMERICAN EXPRESS"
    "card_brand": "american express"
}
*/

P.S: If testing with the exact values used above, output for some of the properties may differ slightly due to time difference and randomization used in creation some of the values.

Request payload

The generate function takes in one argument which is an object. This can contain a couple of properties including a card_brand (string), user_digits (object) and issuer (string).

The only required property is user_digits. This allows the user to specify a sequence of strictly ten digits which they want to be a part of the payment card number. They can also specify where they want this sequence to be placed by setting position to startswith, contains, or endswith. The user_digits value consists of three properties:

  • status: which shows if the user will be specifying their own sequence of digits. This key's property can either be true, false, yes, or no. If set to false, and no other property is provided, a visa payment card will be created and the other fields will have default values. Also, if it is set to false, every other property in the user_digits object will be disregarded.
  • digits: This is the sequence of 10 digits that the user provides.
  • position: This indicates where the user wants the digits to be placed in the the generated card numbers. If the value is startswith and the user also passes a card_brand value, the digits will be prioritised over the value.

Response payload

Once a payment card number has been generated successfully, it returns an object consisting of the following:

  • valid_card_number: This is the valid card number created.
  • cvv: This is the card verification value usually found at the back of a payment card. Here, it is generated randomly.
  • expiry_date: The user can pass their prefered length of years between 1 and 5 after which the card should expire. The default value is 5.
  • balance: The user can also pass their prefered balance amount between ten thousand and five million. The default value is 0.
  • issuer: This is the specific organization that the card was generated from.
  • card_brand: This refers to the brand of the payment card. Currently, this package is only able to generate Mastercard, Visa, American Express and Discover cards.

Sample requests

  1. Sending a payload without specifying card_brand:
{
    "user_digits": {
        "status": true,
        "digits": 2345678991,
        "position": "endswith"
    }
}

Output:

{
    "valid_card_number": "4381392345678991"
    "cvv": 604
    "expiry_date": Fri Apr 24 2026 16:31:11 GMT+0100 (West Africa Standard Time)
    "balance": 0
    "issuer": "UNICREDIT BANK SERBIA JSC BELGRAD"
    "card_brand": "visa"
}

If no card brand is passed, the default is Visa.

  1. Sending a payload with card_brand:
{
    "user_digits": {
        "status": true,
        "digits": 2345678991,
        "position": "endswith"
    }
}

Output:

{
    "valid_card_number": "6011322345678991",
    "cvv": 993,
    "expiry_date": Fri Apr 24 2026 17:58:01 GMT+0100 (West Africa Standard Time),
    "balance": 0,
    "issuer": "BANK OF AMERICA",
    "card_brand": "discover"
}

Error messages

Each key in the object parameter goes through a joi validator before a payment card number can be created. Errors could also arise due to other limitations.

Sample invalid request

  1. The database being used in this package is limited so there is a limit to the number of issuers supported.
{
    "card_brand": "mastercard",
    "user_digits": {
        "status": true,
        "digits": 3745678991,
        "position": "startswith"
    },
    "issuer": "access bank"
};

Outputs: Error: This card brand is not available for this company or company does not exist in our database.

  1. Expiry date higher than 5 years
{
    "card_brand": "american express",
    "user_digits": {
        "status": true,
        "digits": 2345678991,
        "position": "endswith"
    },
    "expires_in": 10
}

Outputs: Error: ValidationError: Expiry year must be between 1 and 5.

  1. Balance higher than 5million
{
    "card_brand": "visa",
    "user_digits": {
        "status": true,
        "digits": 3745678991,
        "position": "contains"
    },
    "issuer": "bank of america",
    "balance": 200000000,
};

Outputs: Error: ValidationError: Balance must be between 10000 and 5000000.

  1. Card brand not Visa, Mastercard, American Express or Discover.
{
    "card_brand": "Maestro",
    "user_digits": {
        "status": true,
        "digits": 3745678991,
        "position": "contains"
    },
    "issuer": "bank of america",
    "balance": 2000,
};

Outputs: Error: ValidationError: card brand is not currently supported. [available: 'visa', 'mastercard', 'discover', 'american express'].