larium/credit-card
Composer 安装命令:
composer require larium/credit-card
包简介
Credit card as value object.
README 文档
README
Credit card as Value Object
Installation
You can install this library using Composer
Information about how to install composer you can find here
Command line
In root directory of your project run through a console:
$ composer require "larium/credit-card":"@stable"
Composer.json
Include require line in your composer.json file
{
"require": {
"larium/credit-card": "@stable"
}
}
and run from console in the root directory of your project:
$ composer update
After this you must require autoload file from composer.
<?php require_once 'vendor/autoload.php';
Usage
Creating a credit card object
<?php use Larium\CreditCard\CreditCard; use Larium\CreditCard\CreditCardValidator; require_once 'vendor/autoload.php'; $data = array( 'holderName'=> 'John Doe', 'month' => 1, 'year' => date('Y') + 1, 'brand' => CreditCard::VISA, 'number' => '4532875311640795', 'cvv' => '123', ); $card = new CreditCard($data); echo $card->getBrand(); # visa //Auto uppercase holder name. echo $card->getHolderName(); # JOHN DOE $card = $card->withNumber('5284911033259148'); echo $card->getBrand(); # master
Adding a token in credit card object
<?php use Larium\CreditCard\CreditCard; use Larium\CreditCard\CreditCardValidator; use Larium\CreditCard\Token; require_once 'vendor/autoload.php'; $data = array( 'holderName' => 'John Doe', 'month' => 1, 'year' => date('Y') + 1, 'brand' => CreditCard::VISA, 'number' => '4532875311640795', 'cvv' => '123', ); $card = new CreditCard($data); # ... use credit card to obtain a token reference from a remote payment gateway. $token = new Token('0123456789'); $card = $card->withToken($token); # Now, credit card will use token for future payments # and will mask any sensitive data as number and cvv. echo $card->getCvv(); # null echo $card->getNumber(); # XXXX-XXXX-XXXX-0795 echo $card->getToken(); # 0123456789
In some cases we need to use a temporary token to fulfil a payment. Many payment gateways support a limited time token, which represents a card or a payment method.
<?php use Larium\CreditCard\Token; require_once 'vendor/autoload.php'; $token = new Token('0123456789', new DateTime('15 minutes')); $token->isExpired() # false $token = new Token('0123456789', new DateTime('15 minutes ago')); $token->isExpired() # true
Validating a credit card
use Larium\CreditCard\CreditCard; use Larium\CreditCard\CreditCardValidator; require_once 'vendor/autoload.php'; $data = array( 'holderName'=> 'John Doe', 'month' => 1, 'year' => date('Y') + 1, 'brand' => CreditCard::VISA, 'number' => '4532875311640795', 'cvv' => '123', ); $card = new CreditCard($data); $validator = new CreditCardValidator(); $errors = $validator->validate($card); $valid = count($errors) === 0; # true $card = $card->withNumber('1'); $error = $validator->validate($card); print_r($errors); /* Array ( [number] => not a valid number [brand] => not valid card type ) */
Validating a token of a credit card
<?php use Larium\CreditCard\CreditCard; use Larium\CreditCard\CreditCardValidator; use Larium\CreditCard\Token; require_once 'vendor/autoload.php'; $card = new CreditCard(); $token = new Token('0123456789'); $card = $card->withToken($token); $validator = new CreditCardValidator(CreditCardValidator::CONTEXT_TOKEN); $errors = $validator->validate($card); $valid = count($errors) === 0; # true $token = new Token('0123456789', new DateTime('15 minutes ago')); $card = $card->withToken($token); $validator->setContext(CreditCardValidator::CONTEXT_TOKEN); $validator->validate($card); $validator->getErrors(); /* Array ( [token] => token has been expired ) */
larium/credit-card 适用场景与选型建议
larium/credit-card 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 661 次下载、GitHub Stars 达 7, 最近一次更新时间为 2015 年 09 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「payments」 「merchant」 「credit card」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 larium/credit-card 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 larium/credit-card 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 larium/credit-card 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Payyo Gateway for the Omnipay payment processing library
This Extension integrates a credit check and more made by the LEONEX Risk Management Platform into your order process. Extensive configuration and evaluation options is provided in the Platform
Integration with Cielo gateway.
PaySimple driver for the Omnipay payment processing library
Yandex.Kassa driver for Omnipay payment processing library
Dealing with payments through the Egyptian payment gateway PayMob
统计信息
- 总下载量: 661
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 18
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-09-05