ebanc/ebanc-php

为eBanc API提供的PHP绑定

dev-master 2017-11-21 06:09 UTC

This package is auto-updated.

Last update: 2024-09-23 03:26:42 UTC


README

为eBanc API提供的PHP绑定

安装

当使用eBanc API的PHP绑定时,在您的项目中使用有两种主要方式。第一种方式是直接下载Ebanc.php文件并在项目中引入。另一种方式是通过composer。

Composer

您可以通过在composer.json文件中包含以下信息将此添加到您的项目中

"require": {
    "ebanc/ebanc-php": "dev-master"
}

用法

初始化

您可以使用以下方式初始化API客户端

require_once('Ebanc.php');

$apiKey    = '123456789';
$gatewayId = 'a01';
$ebanc = new Ebanc($apiKey, $gatewayId);

客户

获取此账户所有客户的列表

$customers = $ebanc->getCustomers();

获取特定客户的详细信息

$uuid = '03ae8670-27d3-0132-54de-1040f38cff7c';
$customer = $ebanc->getCustomer($uuid);

//if we found a customer
if($customer){
  echo 'Found '.$customer['first_name'].' '.$customer['last_name']
}else{
  //this usually means that the customer was not found
  echo $ebanc->getError();
}

创建客户并获取uuid

$firstName     = 'Steve';
$lastName      = 'Bobs';
$routingNumber = '123456789';
$accountNumber = '123456';

$customer = $ebanc->createCustomer($firstName, $lastName, $routingNumber, $accountNumber);

if($customer){
  echo 'Created customer '.$customer['first_name'].' '.$customer['last_name'].' with the UUID of '.$customer['uuid'];
}else{
  echo $ebanc->getError();
}

更新客户

$uuid          = '03ae8670-27d3-0132-54de-1040f38cff7c';
$firstName     = 'Steve';
$lastName      = 'Bobs';
$routingNumber = '123456789';
$accountNumber = '123456';

$customer = $ebanc.updateCustomer($uuid, $firstName, $lastName, $routingNumber, $accountNumber);

//The Routing Number and Account Number are optional params you can change just a customer's name
//Example: $customer = $ebanc.updateCustomer($uuid, $firstName, $lastName);

if($customer){
  echo 'Updated customer '.$customer['first_name'].' '.$customer['last_name'].' with the UUID of '.$customer['uuid'];
}else{
  echo $ebanc->getError();
}

交易

获取此账户最后50笔交易的列表

$transactions = $ebanc->getTransactions();
echo 'Found '.count($transactions).' Transactions';

获取特定交易的最新信息

$uuid = '03ae8670-27d3-0132-54de-1040f38cff7c';
$transaction = $ebanc->getTransaction($transaction_uuid);

if($transaction){
  echo 'Transaction for '.$transaction['amount'].' with the UUID of '.$transaction['uuid'].' was found';
}else{
  echo $ebanc->getError();
}
创建交易

在创建交易时,您可以选择传递所有客户详细信息,或者只需传递已创建客户的uuid。有时只传递所有详细信息是有意义的。这通常是在单一交易的情况下。其他时候,存储客户详细信息并在服务器上仅存储那个uuid以在支付时传递可能更有意义。当您将拥有回头客或需要设置某种类型的计划,但又不想在服务器上存储敏感信息时,这是一种很好的方法。

通过传递所有详细信息创建交易。

$firstName     = 'Steve';
$lastName      = 'Bobs';
$routingNumber = '123456789';
$accountNumber = '123456';
$amount        = '150.92';

$transaction = $ebanc->createTransaction($firstName, $lastName, $routingNumber, $accountNumber, $amount);

if($transaction){
  echo 'Transaction for '.$transaction['amount'].' with the UUID of '.$transaction['uuid'].' was created';
}else{
  echo $ebanc->getError();
}
类型、类别和备注

交易类型可以是借方或贷方。如果您不传递交易类型,则默认为借方。

类别和备注可以一起使用或单独使用,以帮助您在以后进行报告。类别有助于将交易类型分组在一起(例如:“在线订单”和“店内订单”)。备注有助于描述特定交易(例如:在您的电子商务或POS系统中输入订单编号,以将该交易与正确的订单联系起来)。

通过传递所有详细信息以及可选的类别和/或备注创建交易。

$firstName     = 'Steve';
$lastName      = 'Bobs';
$routingNumber = '123456789';
$accountNumber = '123456';
$amount        = '150.92';
$type          = 'debit';
$category      = 'Online Orders';
$memo          = 'Order# 1234';

$transaction = $ebanc->createTransaction($firstName, $lastName, $routingNumber, $accountNumber, $amount, $type, $category, $memo);

if($transaction){
  echo 'Transaction for '.$transaction['amount'].' with the UUID of '.$transaction['uuid'].' was created';
}else{
  echo $ebanc->getError();
}
客户UUID

通过传递客户UUID创建交易。

$uuid   = '03ae8670-27d3-0132-54de-1040f38cff7c';
$amount = '51.50';

$transaction = $ebanc->createTransactionForCustomer($uuid, $amount);

if($transaction){
  echo 'Transaction for '.$transaction['amount'].' with the UUID of '.$transaction['uuid'].' was created';
}else{
  echo $ebanc->getError();
}

通过传递客户UUID以及可选的类型、类别和/或备注创建交易。

$uuid     = '03ae8670-27d3-0132-54de-1040f38cff7c';
$amount   = '51.50';
$type     = 'debit';
$category = 'Online Orders';
$memo     = 'Order# 1234';

$transaction = $ebanc->createTransactionForCustomer($uuid, $amount, $type, $category, $memo);

if($transaction){
  echo 'Transaction for '.$transaction['amount'].' with the UUID of '.$transaction['uuid'].' was created';
}else{
  echo $ebanc->getError();
}