Giter Site home page Giter Site logo

credit-card-php's Introduction

Credit Card helpers in PHP

This is a simple package to create and validate credit card numbers.

Installation via Composer

In your project

To use this package in your project, add it to your composer.json

"require": {
    "rplansky/credit-card": "dev-master"
}

Global Installation

This kind of installation is useful to use ccgenerator and ccvalidator commands globally on command line

$ composer global require "rplansky/credit-card=*@dev"

Usage

In code

Validate Numbers

This validator uses the Luhn Algorithm

$validator = new Plansky\CreditCard\Validator();
$validator->isValid('57234651187928922');
// true

Generate Random Numbers

Totally random
$generator = new Plansky\CreditCard\Generator();
$generator->single();
// 99119662018492824
Prefix

You can generate a random number using a brand prefix.

$generator = new Plansky\CreditCard\Generator();
$generator->single(301); // Generates a DINERS number
// 30192056094873699
Length

Some brands have different number length.

$generator = new Plansky\CreditCard\Generator();
$generator->single(347, 15); // Generates an AMEX number
// 3479966030620031

Generating Lots

Using same parameters of generate method, except for the first parameter that is the amount of numbers that you want to generate, you can generate a lot of numbers at once

$generator = new Plansky\CreditCard\Generator();
$generator->lot(10, 347, 15); // Generates 10 AMEX numbers
// array(
//   0 => '3479132843454361',
//   1 => '3479587605801416',
//   2 => '3479861510504500',
//   3 => '3479130090772634',
//   4 => '3479427298826638',
//   5 => '3479894458677616',
//   6 => '3479713475691154',
//   7 => '3479468840371814',
//   8 => '3479219690811825',
//   9 => '3479326005723791'
// )

In command line

ccgenerator

You can use same parameters of Generator::lot() method, plus, separator parameter to render your output

$ ccgenerator --amount=3 --prefix=347 --length=15 --separator=" "
# 347544073859505 347615533406853 347845409364916

ccvalidator

You can pass numbers separated by spaces to validate more than one number at once.

$ ccvalidator 347544073859505 347615533406852 347845409364916
# 347544073859505 | valid
# 347615533406852 | invalid
# 347845409364916 | valid

credit-card-php's People

Contributors

rplansky 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.