jlorente/laravel-credit-cards
Composer 安装命令:
composer require jlorente/laravel-credit-cards
包简介
Laravel >=5.6 integration for the PHP Credit Cards package that allows to perform operations on debit and credit cards like format, validate brand, number and Luhn algorithm.
关键字:
README 文档
README
Laravel >=5.6 integration for the PHP Credit Cards package that allows to perform operations on debit and credit cards like format, validate brand, number and Luhn algorithm.
It validates popular brands like Visa, Mastercard, American Express, etc.
Installation
The preferred way to install this extension is through composer.
With Composer installed, you can then install the extension using the following commands:
$ php composer.phar require jlorente/laravel-credit-cards
or add
... "require": { "jlorente/laravel-credit-cards": "*" }
to the require section of your composer.json file.
Configuration
- Register the ServiceProvider in your config/app.php service provider list.
config/app.php
return [ //other stuff 'providers' => [ //other stuff \Jlorente\Laravel\CreditCards\CreditCardsServiceProvider::class, ]; ];
- Add the following facade to the $aliases section.
config/app.php
return [ //other stuff 'aliases' => [ //other stuff 'CreditCardValidator' => \Jlorente\Laravel\CreditCards\Facades\CreditCardValidator::class, ]; ];
- Publish the package configuration file.
$ php artisan vendor:publish --provider='Jlorente\Laravel\CreditCards\CreditCardsServiceProvider'
- If you want to limit the available credit card types in your system, you can use the credit_cards.php configuration file to specify them.
config/credit_cards.php
<?php use Jlorente\CreditCards\CreditCardValidator; return [ 'allowed_cards' => [ CreditCardValidator::TYPE_VISA, CreditCardValidator::TYPE_MASTERCARD, CreditCardValidator::TYPE_AMERICAN_EXPRESS, ], ];
or in the env configuration by adding a string with array elements separeted by coma.
.env
//other configurations
CREDIT_CARDS_ALLOWED_CARDS="visa,mastercard,unionpay"
Usage
CreditCardValidator Facade
You can access a singleton of the CreditCardValidator class through the facade.
CreditCardValidator::isVisa($cardNumber); CreditCardValidator::isMastercard($cardNumber); $creditCardConfiguration = CreditCardValidator::getType($cardNumber);
To see a complete list of available methods of the package see the PHP Credit Cards documentation.
CreditCardRule
A rule to be use in the laravel validation flow is included in the package.
You can add the rule by using its string form:
class Request { public function rules() { return [ 'card' => 'credit_card' ]; } }
or the class form:
class Request { public function rules() { return [ 'card' => CreditCardRule::make() ]; } }
Validating security code format
If you provide an integer value as first argument of the rule, the format of the security code (CVC, CVV, etc.) will be validated.
class Request { public function rules() { return [ 'card' => 'credit_card:651' ]; } }
or
class Request { public function rules() { return [ 'card' => CreditCardRule::make(null, '651') ]; } }
Validating the credit card types
You can also provide a list separed by comas of the accepted credit card types. Remember that credit card types should be a subset of the configured system available types.
public function rules() { return [ 'card' => 'credit_card:' implode(',', [CreditCardValidator::TYPE_VISA, CreditCardValidator::TYPE_MASTERCARD]), ]; }
or
class Request { public function rules() { return [ 'card' => CreditCardRule::make([ CreditCardValidator::TYPE_VISA, CreditCardValidator::TYPE_MASTERCARD, CreditCardValidator::TYPE_AMERICAN_EXPRESS, ]), ]; } }
You can also combine credit cards types with security code validation:
class Request { public function rules() { return [ 'card' => 'credit_card:651,' . implode(',', [CreditCardValidator::TYPE_VISA, CreditCardValidator::TYPE_MASTERCARD]), ]; } }
or
class Request { public function rules() { return [ 'card' => CreditCardRule::make( [ CreditCardValidator::TYPE_VISA, CreditCardValidator::TYPE_MASTERCARD, CreditCardValidator::TYPE_AMERICAN_EXPRESS, ], '651', ), ]; } }
License
Copyright © 2020 José Lorente Martín jose.lorente.martin@gmail.com.
Licensed under the BSD 3-Clause License. See LICENSE.txt for details.
jlorente/laravel-credit-cards 适用场景与选型建议
jlorente/laravel-credit-cards 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 37.69k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2020 年 09 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「laravel」 「card」 「validate」 「debit」 「cards」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jlorente/laravel-credit-cards 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jlorente/laravel-credit-cards 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jlorente/laravel-credit-cards 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Settings Card for Laravel Nova.
A tool for scraping URL resources (oEmbed, OpenGraph, Twitter cards, JSON-LD)
A Laravel Nova Card to show Fathom Analytics stats.
This Laravel Nova package allows you to detach filters from the filter dropdown
Asaas.com PHP API v3 Wrapper
Laravel credit card validator 2 from rap2hpoutre
统计信息
- 总下载量: 37.69k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 8
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2020-09-26