alfallouji/php_optimal_netbanx

Optimal Netbanx Restful服务的面向对象PHP客户端

0.0.8 2015-04-30 09:59 UTC

This package is not auto-updated.

Last update: 2024-09-14 16:24:15 UTC


README

Build Status

PHP-Optimal-Netbanx

这是一个针对Optimal Netbanx Restful服务的面向对象PHP客户端。

作者及联系方式

Al-Fallouji Bashar - bashar@alfallouji.com

文档和下载

最新版本可在以下github地址获取: - http://github.com/alfallouji/PHP-Optimal-Netbanx

许可证

本代码在GNU LGPL许可证下发布

请勿更改文件头。

本库是免费软件;您可以在自由软件基金会发布的GNU Lesser General Public License的条款下重新分发和/或修改它;许可证版本2,或(根据您的选择)任何较新版本。

本库的发布是希望其对您有用,但没有任何保证;甚至没有关于适销性或针对特定目的的适用性的暗示保证。

有关详细信息,请参阅GNU Lesser General Public License。

如何设置

您可以使用composer来使用此库。

{
    "require": {
		"alfallouji/php_optimal_netbanx": "*"
    }
}

您可以使用composer生成autoload映射文件。

composer dumpautoload

如何开始

此PHP客户端与Netbanx服务(卡支付)一起工作。

为了使用此库,您需要Optimal Payment账户。

您可以在以下网址创建测试账户: https://developer.optimalpayments.com/en/

配置

为了使用NETBANX REST API,NETBANX必须首先在他们的系统中为您设置并为您提供API密钥。您的API密钥看起来像这样

  • 密钥ID – MerchantXYZ
  • 密钥密码 – B-tst1-0-51ed39e4-312d02345d3f123120881dff9bb4020a89e8ac44cdfdcecd702151182fdc952272661d290ab2e5849e31bb03deede7
  • 账户ID - 12345678

它们可在以下网址获取: https://developer.optimalpayments.com/en/my-account/

请注意,在Optimal我的账户页面,API密钥包含密钥ID和密钥密码。其格式如下

API_KEY_ID:API_KEY_PASSWORD

示例

例如,您可以在tests/Functional文件夹中查看示例。

/**
 * Helper function for test
 * 
 * @param boolean $v Value to assert
 *
 * @return void
 */
function assertTest($v) 
{
    if ($v)
    {
        echo "\t[OK]" . PHP_EOL;
    }
    else
    {
        echo "\t[FAILED]" . PHP_EOL;
        exit(-1);
    }
}

$auth = new \Optimal\Netbanx\Model\Authorization();
$auth->merchantRefNum = 'refNum_' . uniqid();
$auth->amount = 10000 + rand(200, 3000);
$auth->settleWithAuth = false;
$card = new \Optimal\Netbanx\Model\Card();
$card->cardNum = '4530910000012345';
$card->type = 'VI';
$card->lastDigits = '2345';
$expiry = new \Optimal\Netbanx\Model\CardExpiry();
$expiry->month = 11;
$expiry->year = 2019;
$card->cardExpiry = $expiry;
$auth->card = $card;
$billingDetails = new \Optimal\Netbanx\Model\BillingDetails();
$billingDetails->street = '511 rue abelard';
$billingDetails->zip = 'H3E 1B6';
$billingDetails->city = 'Verdun';
$billingDetails->country = 'CA';
$auth->billingDetails = $billingDetails;
$httpClient = new \Optimal\Netbanx\Client\Http($config['apiKey'], $config['apiPassword'], $config['accountId'], 'staging');
$service = new \Optimal\Netbanx\Service\Authorization($httpClient);

// Test 1 - create auth
echo PHP_EOL . 'Testing Authorization creation for ' . $auth->amount;
$result = $service->create($auth);
$id = isset($result['result']['id']) ? $result['result']['id'] : null;
assertTest($id);

// Test 2 - get auth
echo PHP_EOL . 'Testing Authorization get for ' . $id;
$result = $service->get($id);
$getId = isset($result['result']['id']) ? $result['result']['id'] : null;
assertTest($getId && $getId == $id);

// Test 3 - partial reverse of auth
$authReversal = new \Optimal\Netbanx\Model\AuthorizationReversal();
$authReversal->id = $getId;
$authReversal->amount = rand(500, 1000);
$authReversal->merchantRefNum = 'Reverse_for_' . $auth->merchantRefNum;
echo PHP_EOL . 'Testing Authorization reverse for an amount of ' . $authReversal->amount;
$result = $service->reverse($getId, $authReversal);
assertTest(isset($result['result']['status']) && $result['result']['status'] == 'COMPLETED');

// Test 4 - settle authorization
echo PHP_EOL . 'Testing Authorization settlement';
$result = $service->settle($id, array('merchantRefNum' => $auth->merchantRefNum));
assertTest($result['code'] == 200 && isset($result['result']['id']));```