tarlanpayments/gw-client

用于与 Tarlan Payments 网关 v3.0 交互的库

1.5.0 2019-07-17 07:58 UTC

This package is not auto-updated.

Last update: 2024-09-29 04:49:41 UTC


README

此库提供向 Tarlan Payments 网关 API v3 发送请求的能力。

安装

使用以下命令安装最新版本

$ composer require tarlanpayments/gw-client

基本用法

在表单内部

在网关端保留卡片输入表单,客户端必须被重定向到网关。

<?php

use TarlanPayments\Gateway\Gateway;

$gw = new Gateway();

// Setup gateway authorization credentials
$gw->auth()
    ->setAccountGUID("3383e58e-9cde-4ffa-85cf-81cd25b2423e")
    ->setSecretKey('super-secret-key');

// Create transaction object
$sms = $gw->createSms();

// Set required fields
$sms->money()
    ->setAmount(100)
    ->setCurrency('USD');

$sms->customer()
    ->setEmail("email@domain.com")
    ->setPhone("2445224657");

$sms->order()
    ->setMerchantTransactionID('A-345S')
    ->setDescription('Order #A-345S payment');

// Process payment via gateway inside form
$sms->insideForm();

// Build transaction object to request
$smsRequest = $sms->build();

// Process transaction to gateway
$response = $gw->process($smsRequest);

服务器到服务器

在商家端保留卡片输入表单并通过 API 处理。

<?php

use TarlanPayments\Gateway\Gateway;

$gw = new Gateway();

// Setup gatewayl authorization credentials
$gw->auth()
    ->setAccountGUID("3383e58e-9cde-4ffa-85cf-81cd25b2423e")
    ->setSecretKey('super-secret-key');

// Create transaction object
$sms = $gw->createSms();

// Set required fields
$sms->paymentMethod()
    ->setPAN('4295550031781065')
    ->setExpire('06/18')
    ->setCVV('683')
    ->setCardHolderName('John Doe');
$sms->money()
    ->setAmount(100)
    ->setCurrency('USD');

// Build transaction object to request
$smsRequest = $sms->build();

// Process transaction to gateway
$response = $gw->process($smsRequest);

文档

README 提供了关于库用法的介绍。

操作

操作可以通过 $gw->create<operation name>() 方法访问。

可用操作

  • 交易
    • CANCEL
    • DMS CHARGE
    • DMS HOLD
    • MOTO DMS
    • MOTO SMS
    • INIT RECURRENT DMS
    • RECURRENT DMS
    • INIT RECURRENT SMS
    • RECURRENT SMS
    • REFUND
    • REVERSAL
    • SMS
    • Credit
    • P2P
    • B2P
  • 信息
    • HISTORY
    • RECURRENTS
    • REFUNDS
    • RESULT
    • STATUS
  • 验证
    • 3-D Secure 注册
    • 完整卡片验证
  • 令牌化
    • 创建支付数据令牌

与库一起工作的模式可以描述如下

<?php

use TarlanPayments\Gateway\Gateway;

$gw = new Gateway();

// first, you need to setup authorization.
// you can change authorization data in runtime.
// Thus, following operations will work under
// new authorization.
$gw->auth()
    ->setAccountGUID("3383e58e-9cde-4ffa-85cf-81cd25b2423e")
    ->setSecretKey('super-secret-key');

$operation = $gw->createOPERATION();

// here you setup your request through public methods
// that expose you blocks of information, that you can fill for the
// operation of your choice.

// build() will prepare `Request` object that `$gw` will use
// for the request.
$operationRequest = $operation->build();

// process() will perform provided request to the gateway
// `$response` will have response data (headers, body).
$response = $gw->process($operationRequest);

卡片验证

<?php

use TarlanPayments\Gateway\DataSets\Command;

// create a payment to init card verification process
$message->command()->setCardVerificationMode(Command::CARD_VERIFICATION_MODE_INIT);

// complete card verification
$operation = $gw->createCardVerification();
$operation->data()->setGatewayTransactionID($initialResponseGatewayTransactionId);
$operationRequest = $operation->build();
$response = $gw->process($request);

// send a payment with flag to accept only verified cards
$message->command()->setCardVerificationMode(Command::CARD_VERIFICATION_MODE_VERIFY);

支付数据令牌化

<?php

use TarlanPayments\Gateway\DataSets\Command;

// option 1: create a payment with flag to save payment data
$message->command()->setPaymentMethodDataSource(Command::DATA_SOURCE_SAVE_TO_GATEWAY);

// option 2: send "create token" request with payment data
$operation = $gw->createToken();
$operation->paymentMethod()
    ->setPAN('<card number>')
    ->setExpire('<card expiry>')
    ->setCardHolderName('<cardholder name>');
$operation->money()
    ->setCurrency('<desired currency>');
$operationRequest = $operation->build();
$response = $gw->process($request);

// send a payment in "token usage" mode with flag to load payment data by token
$message->useToken();
$message->command()
    ->setPaymentMethodDataSource(Command::DATA_SOURCE_USE_GATEWAY_SAVED_CARDHOLDER_INITIATED)
    ->setPaymentMethodDataToken('<initial gateway-transaction-id>');

自定义

如果您需要访问不同的 API URL,可以通过以下方式通过 Gateway 构造函数设置

<?php

use TarlanPayments\Gateway\Gateway;

$gw = new Gateway('https://customurl.com');

此外,您可以根据需要自定义客户端。默认情况下,使用 Http\Client\Client 类。它使用 cURL 作为后端。它实现了 HttpClientInterface。您可以创建自己的(或配置默认)并将其设置到网关。

<?php

use TarlanPayments\Gateway\Gateway;

$httpClient = new MyClient(); // implements HttpClientInterface

$gw = new Gateway();
$gw->setHttpClient($httpClient);

// use it!
// ...

异常

库可以抛出的主要异常是 GatewayException。以下异常是 GatewayException 的子类

  • RequestException - 如果请求失败,将抛出。
  • ValidatorException - 如果请求中缺少某些数据,将抛出。

关于

需求

  • 此库与 PHP 7.0 或更高版本兼容。

提交错误和功能请求

错误和功能请求在 GitHub 上跟踪。

许可证

此库根据 MIT 许可证授权 - 有关详细信息,请参阅 LICENSE 文件。