定制 selay/php-credit-card-validator 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

selay/php-credit-card-validator

最新稳定版本:4.0

Composer 安装命令:

composer require selay/php-credit-card-validator

包简介

Validates popular debit and credit cards' numbers against regular expressions and Luhn algorithm. Also validates the CVC and the expiration date.

README 文档

README

Validates popular debit and credit cards numbers against regular expressions and Luhn algorithm. Also validates the CVC and the expiration date.

Since original project seems to be abandoned, this fork is made to support other existing repos with compatible namespaces such as rap2hpoutre/laravel-credit-card-validator which also appears to be abondoned. I forked it to selay/laravel-credit-card-validator

Requirements

PHP 7.0+.

Require the package in composer.json

"require": {
    "selay/php-credit-card-validator": "4.*"
},

Usage

Validate a card number knowing the type:

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

Output:

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

Validate a card number against several types:

$card = CreditCard::validCreditCard('5500005555555559', [CreditCard::TYPE_VISA, CreditCard::TYPE_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', CreditCard::TYPE_VISA);
var_dump($validCvc);

Output:

bool(true)

Validate the expiration date

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

Output:

bool(false)

Tests

Execute the following command to run the unit tests:

vendor/bin/phpunit

统计信息

  • 总下载量: 9.28k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 105
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-06-01