PHP code example of alfallouji / php_optimal_netbanx
1. Go to this page and download the library: Download alfallouji/php_optimal_netbanx library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
alfallouji / php_optimal_netbanx example snippets
{
"allouji/php_optimal_netbanx": "*"
}
}
/**
* 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']));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.