LaravelPackages.net
Acme Inc.
Toggle sidebar
malith124/validate-credit-card

PHP and Laravel credit card validator

3
0
1.0
About malith124/validate-credit-card

malith124/validate-credit-card is a Laravel package for php and laravel credit card validator. It currently has 0 GitHub stars and 3 downloads on Packagist (latest version 1.0). Install it with composer require malith124/validate-credit-card. Discover more Laravel packages by malith124 or browse all Laravel packages to compare alternatives.

Last updated

PHP Validate Credit Card

Packagist Software License

Validates popular debit and credit cards numbers against regular expressions and Luhn algorithm. Also validates the CVC and the expiration date. Comes with minimal validation rules for Laravel

Disclaimer

All the codes here come form 2 repository-

  • https://github.com/rap2hpoutre/laravel-credit-card-validator/
  • https://github.com/inacho/php-credit-card-validator/

They should meet you requirements. I had to make this package to solve some very specific requirements.

Install

Install via composer

composer require r4kib/validate-credit-card

Add Service Provider to config/app.php in providers section

R4kib\ValidateCreditCard\ServiceProvider::class,

PHP Usage

Validate a card number knowing the type:

$card = CreditCard::validCreditCard('5500005555555559', 'mastercard');
print_r($card);

Output:

Array
(
    [valid] => 1
    [number] => 5500005555555559
    [type] => mastercard
)

Validate a card number and return the type:

$card = CreditCard::validCreditCard('371449635398431');
print_r($card);

Output:

Array
(
    [valid] => 1
    [number] => 371449635398431
    [type] => amex
)

Validate the CVC

$validCvc = CreditCard::validCvc('234', 'visa');
var_dump($validCvc);

Output:

bool(true)

Validate the expiration date

$validDate = CreditCard::validDate('2013', '07'); // past date
var_dump($validDate);

Output:

bool(false)

Laravel Usage

Add this to your validation rules:

// Add this in your controller method
$this->validate($request, [
    'credit-card-number' => 'required|ccn',
    'credit-card-date' => 'required|ccd',
    'credit-validation-code' => 'required|cvc',
]);

Tests

Execute the following command to run the unit tests:vendor/bin/phpunit

Comments