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
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 via composer
composer require r4kib/validate-credit-card
Add Service Provider to config/app.php
in providers
section
R4kib\ValidateCreditCard\ServiceProvider::class,
$card = CreditCard::validCreditCard('5500005555555559', 'mastercard');
print_r($card);
Output:
Array
(
[valid] => 1
[number] => 5500005555555559
[type] => mastercard
)
$card = CreditCard::validCreditCard('371449635398431');
print_r($card);
Output:
Array
(
[valid] => 1
[number] => 371449635398431
[type] => amex
)
$validCvc = CreditCard::validCvc('234', 'visa');
var_dump($validCvc);
Output:
bool(true)
$validDate = CreditCard::validDate('2013', '07'); // past date
var_dump($validDate);
Output:
bool(false)
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',
]);
Execute the following command to run the unit tests:vendor/bin/phpunit