danielebarbaro/laravel-credit-card-validator

laravel-credit-card-validator is a package to validate a credit card number.

0.1.2 2021-10-07 08:44 UTC

This package is not auto-updated.

Last update: 2024-12-13 00:27:18 UTC


README

Latest Version on Packagist Build Status Total Downloads

laravel-credit-card-validator is a package to validate credit card number usign Luhn Algo .

Installation

You can install the package via composer:

composer require danielebarbaro/laravel-credit-card-validator

The package will automatically register itself.

Usage

use Danielebarbaro\LaravelCreditCardValidator\Facades\CreditCardValidatorFacade as CreditCardValidator;

// Check Credit Card 
CreditCardValidator::validate('4579880200630196');

Validation

The package registers a new validation rule.

credit_card_number

use Illuminate\Http\Request;

class Controller {

    public function foo(Request $request) 
    {
        $request->validate([
            'field' => ['credit_card_number'],
        ]);
    }
}

Alternatively, you can also use the Rule directly.

use Illuminate\Http\Request;
use Danielebarbaro\LaravelCreditCardValidator\Rules;

class Controller {

    public function foo(Request $request) 
    {
        $request->validate([
            'field' => [ new Rules\CreditCardNumber() ],
        ]);
    }
}

Translations

Just add and customize validation strings in resources/lang/en/validation.php

    ...
    'credit_card_number' => 'The :attribute must be a valid Credit Card number',
    ...

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email barbaro.daniele@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.