Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
"ext-curl": "*",
"ext-json": "*",
"ext-simplexml": "*",
"ext-xmlwriter": "*"
"ext-xmlwriter": "*",
"jms/serializer": "*"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"phpmd/phpmd": "~2.0",
"goetas/xsd2php":"2.*@dev",
"goetas/xsd-reader":"2.*@dev",
"jms/serializer": "xsd2php-dev as 0.18.0"
"goetas/xsd-reader":"2.*@dev"
},
"suggest": {
"phpdocumentor/phpdocumentor": "For generating API documentation"
Expand Down
9 changes: 3 additions & 6 deletions lib/net/authorize/util/HttpClient.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php
namespace net\authorize\util;

//use \net\authorize\api\constants\ANetEnvironment;

/**
* A class to send a request to the XML API.
*
Expand All @@ -11,7 +9,6 @@
*/
class HttpClient
{
//const URL = "https://apitest.authorize.net/xml/v1/request.api";
private $_Url = "";

public $VERIFY_PEER = true; // attempt trust validation of SSL certificates when establishing secure connections.
Expand All @@ -23,7 +20,7 @@ class HttpClient
*/
public function __construct()
{
$this->_log_file = AUTHORIZENET_LOG_FILE;
$this->_log_file = (defined('AUTHORIZENET_LOG_FILE') ? AUTHORIZENET_LOG_FILE : false);
date_default_timezone_set('UTC');
}

Expand Down Expand Up @@ -79,7 +76,7 @@ public function _sendRequest($xmlRequest)
file_put_contents($this->_log_file, sprintf("\n%s:Request to AnetApi: \n%s", $this->now(), $xmlRequest), FILE_APPEND);

if ($this->VERIFY_PEER) {
curl_setopt($curl_request, CURLOPT_CAINFO, dirname(dirname(__FILE__)) . '../../../ssl/cert.pem');//..\..\..\ssl\cert.pem
curl_setopt($curl_request, CURLOPT_CAINFO, dirname(dirname(__FILE__)) . '/../../ssl/cert.pem');
} else {
if ($this->_log_file) {
file_put_contents($this->_log_file, "\nInvalid SSL option for the request", FILE_APPEND);
Expand Down Expand Up @@ -118,4 +115,4 @@ private function now()
{
return date( DATE_RFC2822);
}
}
}
5 changes: 4 additions & 1 deletion tests/AuthorizeNetARB_Test.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

//include if tests/bootstrap.php is not loaded automatically
//require_once __DIR__ . '/bootstrap.php';

class AuthorizeNetARB_Test extends PHPUnit_Framework_TestCase
{

Expand Down Expand Up @@ -223,4 +226,4 @@ public function testGetSubscriptionList()
$this->assertEquals($response->getRefId(), $refId);
$this->assertEquals($response->getResultCode(), "Ok");
}
}
}
11 changes: 6 additions & 5 deletions tests/Controller_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
use \net\authorize\api\controller\base\ApiOperationBase;

require_once __DIR__ . '/../autoload.php';
require_once "../phpunit_config.php";
//include if tests/bootstrap.php is not loaded automatically
//require_once __DIR__ . '/bootstrap.php';

class Controller_Test extends PHPUnit_Framework_TestCase
{
public function testARBGetSubscriptionList()
{
$name = AUTHORIZENET_API_LOGIN_ID;
$transactionKey = AUTHORIZENET_TRANSACTION_KEY;
$name = (defined('AUTHORIZENET_API_LOGIN_ID') && ''!=AUTHORIZENET_API_LOGIN_ID) ? AUTHORIZENET_API_LOGIN_ID : getenv("api_login_id");
$transactionKey = (defined('AUTHORIZENET_TRANSACTION_KEY') && ''!=AUTHORIZENET_TRANSACTION_KEY) ? AUTHORIZENET_TRANSACTION_KEY : getenv("transaction_key");

$merchantAuthentication = new net\authorize\api\contract\v1\MerchantAuthenticationType();
$merchantAuthentication->setName($name);
Expand All @@ -35,7 +36,7 @@ public function testARBGetSubscriptionList()

//$controller = new ApiOperationBase($request, 'net\authorize\api\contract\v1\ARBGetSubscriptionListResponse');
$controller = new TestController( $request);
$response = $controller->executeWithApiResponse();
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);

// Handle the response.
$this->assertNotNull($response, "null response");
Expand Down Expand Up @@ -64,4 +65,4 @@ protected function validateRequest()
{
//empty
}
}
}
57 changes: 39 additions & 18 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,52 @@
* Bootstraps the AuthorizeNet PHP SDK test suite
*/

// Clear logfile
file_put_contents(AUTHORIZENET_LOG_FILE, "");
//properties set in file take precedence over environment
//default the value to use
$global_api_login_id = (defined('AUTHORIZENET_API_LOGIN_ID') && ''!=AUTHORIZENET_API_LOGIN_ID) ? AUTHORIZENET_API_LOGIN_ID : getenv("api_login_id");
$global_transaction_key = (defined('AUTHORIZENET_TRANSACTION_KEY') && ''!=AUTHORIZENET_TRANSACTION_KEY) ? AUTHORIZENET_TRANSACTION_KEY : getenv("transaction_key");
if (!defined('AUTHORIZENET_LOG_FILE'))
{
define( "AUTHORIZENET_LOG_FILE", "./authorize-net.log");
}

// Append to log file
date_default_timezone_set('UTC'); //necessary for the following date to set timezone
file_put_contents(AUTHORIZENET_LOG_FILE, sprintf("Logging Started: %s\n", date( DATE_RFC2822)), FILE_APPEND);

// validate existence of available extensions
if (!function_exists('simplexml_load_file'))
{
$errorMessage = 'The AuthorizeNet SDK requires the SimpleXML PHP extension.';
throw new RuntimeException( $errorMessage );
}

if (!function_exists('simplexml_load_file')) {
throw new RuntimeException(
'The AuthorizeNet SDK requires the SimpleXML PHP extension.'
);
if (!function_exists('curl_init'))
{
$errorMessage = 'The AuthorizeNet SDK requires the cURL PHP extension.';
throw new RuntimeException( $errorMessage );
}

if (!function_exists('curl_init')) {
throw new RuntimeException(
'The AuthorizeNet SDK requires the cURL PHP extension.'
);
// validate existence of credentials
if (null == $global_api_login_id || "" == $global_api_login_id)
{
$errorMessage = "Property 'AUTHORIZENET_API_LOGIN_ID' not found. Define the property value or set the environment 'api_login_id'";
throw new RuntimeException( $errorMessage );
}

if (AUTHORIZENET_API_LOGIN_ID == "") {
throw new RuntimeException(
'Copy /phpunit.xml.dist to /phpunit.xml and enter your merchant credentials'
. ' before running the tests.'
);
if (null == $global_transaction_key || "" == $global_transaction_key)
{
$errorMessage = "Property 'AUTHORIZENET_TRANSACTION_KEY' not found. Define the property value or set the environment 'transaction_key'";
throw new RuntimeException( $errorMessage );
}

ini_set('error_reporting', E_ALL);

$loader = require 'vendor/autoload.php';
if (!isset($loader)) {
throw new RuntimeException('vendor/autoload.php could not be found.');
/*
$loader = require '../vendor/autoload.php';
if (!isset($loader))
{
$errorMessage = 'vendor/autoload.php could not be found.';
throw new RuntimeException( $errorMessage );
}
*/
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@

use \net\authorize\api\controller\CreateTransactionController;

//use net\authorize\api\contract\v1\

require_once __DIR__ . '/../../../../../autoload.php';
require_once __DIR__ . '/../../../../../phpunit_config.php';
//include if tests/bootstrap.php is not loaded automatically
//require_once __DIR__ . '/../../../../bootstrap.php';

class CreateTransactionControllerTest extends \PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -81,8 +80,8 @@ public function __construct()

public function testCreateTransactionCreditCard()
{
$name = AUTHORIZENET_API_LOGIN_ID;
$transactionKey = AUTHORIZENET_TRANSACTION_KEY;
$name = (defined('AUTHORIZENET_API_LOGIN_ID') && ''!=AUTHORIZENET_API_LOGIN_ID) ? AUTHORIZENET_API_LOGIN_ID : getenv("api_login_id");
$transactionKey = (defined('AUTHORIZENET_TRANSACTION_KEY') && ''!=AUTHORIZENET_TRANSACTION_KEY) ? AUTHORIZENET_TRANSACTION_KEY : getenv("transaction_key");
$merchantAuthentication = new MerchantAuthenticationType();
$merchantAuthentication->setName($name);
$merchantAuthentication->setTransactionKey($transactionKey);
Expand All @@ -104,7 +103,7 @@ public function testCreateTransactionCreditCard()
$request->setTransactionRequest( $transactionRequestType);

$controller = new CreateTransactionController($request);
$controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::CUSTOM);
$controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
$response = $controller->getApiResponse();

// Handle the response.
Expand Down Expand Up @@ -132,4 +131,4 @@ private function setValidAmount( $number)
}

const MaxTransactionAmount = 10000; //214747;
}
}
43 changes: 43 additions & 0 deletions tests/net/authorize/api/controller/LogoutControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
namespace net\authorize\api\controller\test;

use net\authorize\api\contract\v1\LogoutRequest;
use net\authorize\api\contract\v1\MerchantAuthenticationType;
use \net\authorize\api\controller\LogoutController;

require_once __DIR__ . '/../../../../../autoload.php';
//include if tests/bootstrap.php is not loaded automatically
//require_once __DIR__ . '/../../../../bootstrap.php';

class LogoutControllerTest extends \PHPUnit_Framework_TestCase
{
public function testLogout()
{
$name = (defined('AUTHORIZENET_API_LOGIN_ID') && ''!=AUTHORIZENET_API_LOGIN_ID) ? AUTHORIZENET_API_LOGIN_ID : getenv("api_login_id");
$transactionKey = (defined('AUTHORIZENET_TRANSACTION_KEY') && ''!=AUTHORIZENET_TRANSACTION_KEY) ? AUTHORIZENET_TRANSACTION_KEY : getenv("transaction_key");
$merchantAuthentication = new MerchantAuthenticationType();
$merchantAuthentication->setName($name);
$merchantAuthentication->setTransactionKey($transactionKey);

$refId = 'ref' . time();

$request = new LogoutRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setRefId( $refId);

$controller = new LogoutController($request);
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
// Handle the response.
$this->assertNotNull($response, "null response");
$this->assertNotNull($response->getMessages());

$this->assertEquals("Ok", $response->getMessages()->getResultCode());
$this->assertEquals($response->getRefId(), $refId);
$this->assertTrue(0 < count($response->getMessages()));
foreach ($response->getMessages() as $message)
{
$this->assertEquals("I00001", $message->getCode());
$this->assertEquals("Successful.", $response->getText());
}
}
}