coatesap/credit-card-validator

一个简单的PHP类,用于验证信用卡/借记卡信息

v2.0 2014-12-02 09:26 UTC

This package is auto-updated.

Last update: 2024-08-29 03:52:50 UTC


README

一个简单的PHP类,用于准备和验证信用卡/借记卡信息。通常在将信息传递给支付网关处理之前进行。

示例用法

require '../vendor/autoload.php';

$cardDetails = array(
    'number' =>'4929000000006',
    'expiryYear' => 2013,
    'expiryMonth' => 5,
    'code' => '123'
);

$card = new Coatesap\Payment\Card();
$card->populate($cardDetails);

if (!$card->isValid($message)) {
    // show error message (set by reference)
    echo 'There is a problem with your card details: ' . $message;
} else {
    // get the prepped, validated card data as an array
    $cardData = $card->toArray();
    // send $cardData to payment gateway
}

安装

可以通过Composer安装信用卡类。要安装,只需将其添加到您的composer.json文件中

{
    "require": {
        "coatesap/credit-card-validator": "~2.0"
    }
}

数据准备

此类会对您的卡数据进行一些简单的准备。这包括从以下内容中移除非数字字符,包括空格:

  • 卡号
  • CVC/CV2值
  • 卡有效期

验证检查

此类还会检查:

  • 卡尚未过期
  • 已提供有效的CVC/CV2安全码
  • 卡号通过Luhn校验