craigpaul/moneris-api

此包已被废弃且不再维护。未建议替代包。

一种更简单的方式使用(真正糟糕的)Moneris eSELECTplus API。

v0.8.1 2020-05-05 15:29 UTC

This package is auto-updated.

Last update: 2020-11-22 18:35:33 UTC


README

Latest Version on Packagist Software License Build Status Total Downloads

需求

PHP 5.6 及以上

Composer

要开始使用,请通过 Composer 包管理器安装此包

composer require craigpaul/moneris-api

实例化

创建一个新的 Moneris 实例非常简单直接。

use CraigPaul\Moneris\Moneris;

...

$id = 'store1';
$token = 'yesguy';

// optional
$params = [  
  'environment' => Moneris::ENV_TESTING, // default: Moneris::ENV_LIVE
  'avs' => true, // default: false
  'cvd' => true, // default: false
  'cof' => true, // default: false
];

$gateway = (new Moneris($id, $token, $params))->connect();
use CraigPaul\Moneris\Moneris;

...

$id = 'store1';
$token = 'yesguy';

// optional
$params = [  
  'environment' => Moneris::ENV_TESTING, // default: Moneris::ENV_LIVE
  'avs' => true, // default: false
  'cvd' => true, // default: false
  'cof' => true, // default: false
];

$gateway = Moneris::create($id, $token, $params);

注意:请注意,Moneris 商店 ID 和 API 令牌总是需要传递给 Moneris 构造函数或静态 create 方法。

交易

一旦实例化网关(见上方实例化),进行购买、预授权卡、作废交易等操作都非常简单。

购买

$params = [
    'order_id' => uniqid('1234-56789', true),
    'amount' => '1.00',
    'credit_card' => '4242424242424242',
    'expiry_month' => '12',
    'expiry_year' => '20',
];

$response = $gateway->purchase($params);

预授权

$params = [
    'order_id' => uniqid('1234-56789', true),
    'amount' => '1.00',
    'credit_card' => '4242424242424242',
    'expiry_month' => '12',
    'expiry_year' => '20',
];

$response = $gateway->preauth($params);

捕获(预授权完成)

$params = [
    'order_id' => uniqid('1234-56789', true),
    'amount' => '1.00',
    'credit_card' => '4242424242424242',
    'expiry_month' => '12',
    'expiry_year' => '20',
];

$response = $gateway->preauth($params);

$response = $gateway->capture($response->transaction);

作废(购买纠正)

$params = [
    'order_id' => uniqid('1234-56789', true),
    'amount' => '1.00',
    'credit_card' => '4242424242424242',
    'expiry_month' => '12',
    'expiry_year' => '20',
];

$response = $gateway->purchase($params);

$response = $gateway->void($response->transaction);

退款

$params = [
    'order_id' => uniqid('1234-56789', true),
    'amount' => '1.00',
    'credit_card' => '4242424242424242',
    'expiry_month' => '12',
    'expiry_year' => '20',
];

$response = $gateway->purchase($params);

$response = $gateway->refund($response->transaction);

卡验证

$params = [
    'order_id' => uniqid('1234-56789', true),
    'amount' => '1.00',
    'credit_card' => '4242424242424242',
    'expiry_month' => '12',
    'expiry_year' => '20',
];

$response = $gateway->verify($params);

CVD 和 AVS

为了利用 Moneris 提供的卡验证数字和/或地址验证服务,您需要在实例化时通知 Moneris(如上方实例化所示)。

在执行 CVD 加密购买、预授权或卡验证时,您需要将以下参数传递给您正在使用的 Gateway 方法。

$params = [
    // `cvd` needs to be included in your transaction parameters.
    'cvd' => '111',
    'order_id' => uniqid('1234-56789', true),
    'amount' => '1.00',
    'credit_card' => $this->visa,
    'expdate' => '2012',
];

$response = $gateway->verify($params); // could be purchase, preauth, etc.

在执行 AVS 加密购买、预授权或卡验证时,您需要将以下参数传递给您正在使用的 Gateway 方法。

$params = [
    // `avs_*` keys need to be included in your transaction parameters.
    'avs_street_number' => '123',
    'avs_street_name' => 'Fake Street',
    'avs_zipcode' => 'X0X0X0',
    'order_id' => uniqid('1234-56789', true),
    'amount' => '1.00',
    'credit_card' => $this->visa,
    'expdate' => '2012',
];

$response = $gateway->verify($params); // could be purchase, preauth, etc.

注意:在执行 AVS 或 CVD 加密交易时,即使 AVS 或 CVD 失败,您仍需要作废该交易(该死的 Moneris!)。有两种简单的方法可以解决这个问题。

首先验证卡片。使用这种方法,有一个额外的注意事项(让我再重复一遍……该死的 Moneris!)。您的验证交易和购买交易必须有不同的 order_id 参数。一个解决方案可能是将特定前缀添加到验证订单 ID 的前面。

$response = $gateway->verify($params);

if ($response->successful && !$response->failedAvs && !$response->failedCvd) {
    $response = $gateway->purchase($params);
    
    if ($response->successful) {
        $receipt = $response->receipt();
    } else {
        $errors = $response->errors;
    }
}

作废交易。

$response = $gateway->purchase($params);

if ($response->successful && ($response->failedAvs || $response->failedCvd)) {
    $errors = $response->errors;
    $response = $gateway->void($response->transaction);
} elseif (!$response->successful) {
    $errors = $response->errors;
} else {
    $receipt = $response->receipt();
}

文件凭证

文件凭证是 Visa 新要求的组成部分,用于传递交易中的 CVD/CVV2 数据。

$params = [
    'order_id' => uniqid('1234-56789', true),
    'amount' => '1.00',
    'data_key' => $key,
    'payment_indicator' => 'U',
    'payment_information' => '2',
    'issuer_id' => $issuer_id // this is optional
];

$response = $vault->purchase($params); // could be purchase, preauth, etc.

保险库

Moneris 保险库允许您在 Moneris 服务器上创建和维护信用卡资料,而不是在自己的服务器上。要访问保险库,您需要拥有实例化的 Gateway(见上方实例化)。

$vault = $gateway->cards();

添加卡片

注意:信用卡的过期日期以YYMM格式传递,这是Moneris接受的格式。

use CraigPaul\Moneris\CreditCard;

...

$card = CreditCard::create('4242424242424242', '2012');

$response = $vault->add($card);

更新卡片

为了维护您的信用卡资料,Moneris将发送一个唯一的密钥回资料,这将允许您在自己的数据库中跟踪。您可以在收到收据后检索密钥(见下文

$card = CreditCard::create('4242424242424242', '2012');

$response = $vault->add($card);
$key = $response->receipt()->read('key');

$card->expiry = '2112';

$response = $vault->update($key, $card);

删除卡片

$card = CreditCard::create('4242424242424242', '2012');

$response = $vault->add($card);
$key = $response->receipt()->read('key');

$response = $vault->delete($key);

附加客户

为了将您的客户信息与保险库中存储的信用卡同步,我们可以将一个基本的Customer对象附加到CreditCard

添加卡片

use CraigPaul\Moneris\Customer;

...

$params = [
    'id' => uniqid('customer-', true),
    'email' => 'example@email.com',
    'phone' => '555-555-5555',
    'note' => 'Customer note',
];

$customer = Customer::create($params);
$card = CreditCard::create('4242424242424242', '2012');
$card = $card->attach($customer);

$response = $vault->add($card);

更新卡片和客户

use CraigPaul\Moneris\Customer;

...

$params = [
    'id' => uniqid('customer-', true),
    'email' => 'example@email.com',
    'phone' => '555-555-5555',
    'note' => 'Customer note',
];

$customer = Customer::create($params);
$card = CreditCard::create('4242424242424242', '2012');
$card = $card->attach($customer);

$response = $vault->add($card);
$key = $response->receipt()->read('key');

$card->customer->email = 'example2@email.com';

$response = $vault->update($key, $card);

令牌化前一笔交易

用于根据前一笔交易创建信用卡资料。

$params = [
    'order_id' => uniqid('1234-56789', true),
    'amount' => '1.00',
    'credit_card' => '4242424242424242',
    'expiry_month' => '12',
    'expiry_year' => '20',
];

$response = $gateway->purchase($params);

$response = $vault->tokenize($response->transaction);

窥视保险库

如果您需要查找掩码的信用卡号码,可以窥视保险库。

$card = CreditCard::create('4242424242424242', '2012');

$response = $vault->add($card);
$key = $response->receipt()->read('key');

$response = $vault->peek($key);
$receipt = $response->receipt();

$masked = $receipt->read('data')['masked_pan'];

检索即将到期的卡片

根据Moneris API,此交易在任何给定日历日上最多只能执行2次。

$response = $vault->expiring();

交易

存储在Moneris保险库中的信用卡在购买和预先授权方面有略微不同的流程。其他交易与上面所示完全相同。

保险库购买

$card = CreditCard::create('4242424242424242', '2012');

$response = $vault->add($card);
$key = $response->receipt()->read('key');

$params = [
    'order_id' => uniqid('1234-56789', true),
    'amount' => '1.00',
    'data_key' => $key,
];

$response = $vault->purchase($params); // 

注意:此处使用保险库进行交易,而不是使用基本网关对象。

保险库预先授权

$card = CreditCard::create('4242424242424242', '2012');

$response = $vault->add($card);
$key = $response->receipt()->read('key');

$params = [
    'order_id' => uniqid('1234-56789', true),
    'amount' => '1.00',
    'data_key' => $key,
];

$response = $vault->preauth($params); // 

响应和收据

ResponseReceipt对象使您能够了解API调用的情况。交易处理返回后,Response将得到验证并返回所有相关信息。

响应

Response对象上可用的信息如下

错误

$errors = $response->errors;

在您的交易过程中可能发生的任何错误将以以下格式返回给您。以这种格式返回是为了允许您通过利用每个错误中的唯一titlefield键在自己的应用程序中处理任何翻译逻辑。

// The following example would be returned when you forget to set the `order_id` on your transaction. 

$errors = [
    [
        'field' => 'order_id',
        'code' => self::PARAMETER_NOT_SET, // 2
        'title' => 'not_set'
    ],
];

状态

$status = $response->status;

状态将返回与返回的错误匹配的状态码。以下是一个可能返回的状态示例。

ERROR                    = -23;
INVALID_TRANSACTION_DATA = 0;

FAILED_ATTEMPT            = -1;
CREATE_TRANSACTION_RECORD = -2;
GLOBAL_ERROR_RECEIPT      = -3;

SYSTEM_UNAVAILABLE    = -14;
CARD_EXPIRED          = -15;
INVALID_CARD          = -16;
INSUFFICIENT_FUNDS    = -17;
PREAUTH_FULL          = -18;
DUPLICATE_TRANSACTION = -19;
DECLINED              = -20;
NOT_AUTHORIZED        = -21;
INVALID_EXPIRY_DATE   = -22;

CVD               = -4;
CVD_NO_MATCH      = -5;
CVD_NOT_PROCESSED = -6;
CVD_MISSING       = -7;
CVD_NOT_SUPPORTED = -8;

AVS             = -9;
AVS_POSTAL_CODE = -10;
AVS_ADDRESS     = -11;
AVS_NO_MATCH    = -12;
AVS_TIMEOUT     = -13;

POST_FRAUD = -22;

成功

$success = $response->successful

成功的属性只是简单地告知您您的交易是否已成功处理。

收据

收据对象是您已提交的任何与交易相关的信息的记录。一旦您收到响应,请参阅以下内容以检索您的收据。

$response = $gateway->purchase($params);

$receipt = $response->receipt();

根据交易类型的不同,您在收据上将有不同的项目可供阅读。

$amount = $receipt->read('amount');

有关可读收据项目的完整列表,请参阅以下内容。

amount - The amount of the transaction. (string)
authorization - The authorization code for the transaction. (string)
avs_result - The avs result code for the transaction. (string)
card - The card type used for the transaction. (string)
code - The response code for the transaction. (string)
complete - Whether the transaction had completed correctly or not. (boolean)
cvd_result - The cvd result code.  (string)
data - The data related to the customer and card for the transaction. (array)
date - The date of the transaction. (string)
id - The Moneris id of the receipt. (string)
iso - The ISO code for the transaction. (string)
key - The data key used for vault transactions. (string)
message - Any relevant message provided for the transaction. (string)
reference - The reference number for the transaction. (string)
time - The time of the transaction. (string)
transaction - The Moneris id of the transaction. (string)
type - The transaction type. (string)

变更日志

有关最近变更的更多信息,请参阅变更日志

贡献

有关详细信息,请参阅贡献指南

致谢

许可证

Moneris API 是开源软件,许可协议为MIT 许可证