ragboyjr/go-to-billing-client

Go To Billing REST 客户端

v0.1.5 2017-08-11 00:45 UTC

This package is auto-updated.

Last update: 2024-09-18 18:03:18 UTC


README

简单的 PHP 客户端,用于与 Go To Billing API 交互。

安装

使用 composer 在 ragboyjr/go-to-billing-client 下安装

用法

<?php

use Ragboyjr\GoToBilling;

$client = new GoToBilling\GuzzleGoToBillingApiClient(
    new GoToBilling\Config($user, $pin, $debug = $true)
);

$merchant = new GoToBilling\Model\Merchant('127.0.0.1');
$customer = new GoToBilling\Model\Customer('0');
$customer->first_name = "RJ";
$customer->last_name = "Garcia";
$ach = new GoToBilling\Model\ACHTransaction('DH', '1', '1.00', GoToBilling\Model\ACHPaymentType::WEB);
$ach->ach_account = '000123456789';
$ach->ach_route = '110000000';
$ach->ach_account_type = GoToBilling\Model\ACHAccountType::PERSONAL_CHECKING;
$ach->ach_verification = true;

$resp = $client->transact(new GoToBilling\Model\Request($merchant, $customer, $ach));
var_dump($resp->getBody());

这将输出类似以下内容

array(7) {
  ["status"]=>
  string(1) "R"
  ["order_number"]=>
  string(29) "238665-20170408-58e982c1d0607"
  ["term_code"]=>
  string(1) "0"
  ["tran_amount"]=>
  string(4) "1.00"
  ["tran_date"]=>
  string(8) "20170408"
  ["tran_time"]=>
  string(6) "193929"
  ["invoice_id"]=>
  string(1) "1"
}

模型对象反映了 GoToBilling 文档中的请求字段。您可以通过查看源代码来了解支持的请求类型。

交易响应

交易响应还有一些辅助方法来从响应中获取数据。以下是一个使用相同客户端和商家详情进行 CC 认证和捕获的示例。

<?php

$cc = CCTransaction::createWithCard(
    TransactionType::AUTHORIZE_CAPTURE,
    uniqid(),
    '123.40',
    new Card('370000000000002', '0521', '999')
);

$resp = $client->transact(new Request($merchant, $customer, $cc));

$resp->getTicketId(); // return the ticket id
$resp->getStatus(); // return the transaction status
$resp->isApproved(); // check if status is approved
$resp->isReceived(); // check if status is received
$resp->isDeclined(); // check if status is declined
$resp->isCancelled(); // check if status is cancelled
$resp->isTimeout(); // check if status is timeout

Soap Api

您还可以使用 GoToBillingSoapApiClient 利用 soap api。

<?php

use Ragboyjr\GoToBilling;

$client = GoToBilling\GoToBillingSoapApiClient::createFromConfig(
    new GoToBilling\Config($user, $pin, $debug = $true)
);
$client->getAccounts();
$client->getTransactions([
    'po_number' => '1234'
]);
// return the inner soap client
$soap = $client->getSoapClient();

SoapApiClient 将将所有调用转发到内部 php SoapClient 类。但是,它将 Ragboyjr\GoToBilling\Model\Soap\MerchantAuth 实例作为第一个参数注入,这样您就不必为每个调用都这样做。

Pimple 服务提供者

您还可以使用 Pimple 服务提供者来创建服务。

<?php

use Ragboyjr\GoToBilling;

// you can use these env vars to configure the GoToBilling\Config entity or just extend it in pimple.
putenv('GO_TO_BILLING_MERCHANT_ID={id}');
putenv('GO_TO_BILLING_MERCHANT_PIN={pin}');
putenv('GO_TO_BILLING_DEBUG=1');

$pimple->register(new GoToBilling\Provider\Pimple\GoToBillingServiceProvider(), [
    'ragboyjr.go_to_billing.soap_options' => [
        // any SoapClient options can go here
    ]
]);
$rest_api = $pimple[GoToBilling\GoToBillingApi::class];
$soap_api = $pimple[GoToBilling\GoToBillingSoapApi::class];

Laravel 服务提供者

<?php

use Ragboyjr\GoToBilling\Provider\Laravel\GoToBillingServiceProvider;

// in your app service provider
$this->app->register(GoToBillingServiceProvider::class);
// configure soap options
$this->app['config']->set('go_to_billing.soap_options', [
    // soap options go here
]);

// then you can use the following services
$rest_api = app('Ragboyjr\GoToBilling\GoToBillingApi');
$soap_api = app('Ragboyjr\GoToBilling\GoToBillingSoapApi');