diff --git a/composer.json b/composer.json index 674c1b73..8ef0af3a 100644 --- a/composer.json +++ b/composer.json @@ -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" diff --git a/lib/net/authorize/util/HttpClient.php b/lib/net/authorize/util/HttpClient.php index 6ef783ba..247d6a7c 100644 --- a/lib/net/authorize/util/HttpClient.php +++ b/lib/net/authorize/util/HttpClient.php @@ -1,8 +1,6 @@ _log_file = AUTHORIZENET_LOG_FILE; + $this->_log_file = (defined('AUTHORIZENET_LOG_FILE') ? AUTHORIZENET_LOG_FILE : false); date_default_timezone_set('UTC'); } @@ -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); @@ -118,4 +115,4 @@ private function now() { return date( DATE_RFC2822); } -} \ No newline at end of file +} diff --git a/tests/AuthorizeNetARB_Test.php b/tests/AuthorizeNetARB_Test.php index 6f8a0c4b..df875bca 100644 --- a/tests/AuthorizeNetARB_Test.php +++ b/tests/AuthorizeNetARB_Test.php @@ -1,5 +1,8 @@ assertEquals($response->getRefId(), $refId); $this->assertEquals($response->getResultCode(), "Ok"); } -} \ No newline at end of file +} diff --git a/tests/Controller_Test.php b/tests/Controller_Test.php index 200b5b39..ee417438 100644 --- a/tests/Controller_Test.php +++ b/tests/Controller_Test.php @@ -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); @@ -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"); @@ -64,4 +65,4 @@ protected function validateRequest() { //empty } -} \ No newline at end of file +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 97795092..2d2ee688 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -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 ); } +*/ diff --git a/tests/net/authorize/api/controller/CreateTransactionControllerTest.php b/tests/net/authorize/api/controller/CreateTransactionControllerTest.php index d12c7a85..9b592350 100644 --- a/tests/net/authorize/api/controller/CreateTransactionControllerTest.php +++ b/tests/net/authorize/api/controller/CreateTransactionControllerTest.php @@ -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 { @@ -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); @@ -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. @@ -132,4 +131,4 @@ private function setValidAmount( $number) } const MaxTransactionAmount = 10000; //214747; -} \ No newline at end of file +} diff --git a/tests/net/authorize/api/controller/LogoutControllerTest.php b/tests/net/authorize/api/controller/LogoutControllerTest.php new file mode 100644 index 00000000..4fa26519 --- /dev/null +++ b/tests/net/authorize/api/controller/LogoutControllerTest.php @@ -0,0 +1,43 @@ +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()); + } + } +}