diff --git a/composer.json b/composer.json index 94234cc..426f9e6 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "zipmoney/merchantapi-php", - "version": "1.0.8", + "version": "1.0.9", "description": "", "keywords": [ "zipmoney", @@ -28,7 +28,7 @@ }, "require-dev": { "squizlabs/php_codesniffer": "~2.6", - "friendsofphp/php-cs-fixer": "~1.12" + "phpunit/phpunit": "^5.0" }, "autoload": { "psr-4": { diff --git a/lib/ApiClient.php b/lib/ApiClient.php index 7cbf121..4b5cb92 100644 --- a/lib/ApiClient.php +++ b/lib/ApiClient.php @@ -261,7 +261,7 @@ public function callApi($resourcePath, $method, $queryParams, $postData, $header } throw new ApiException( - "[".$response_info['http_code']."] Error connecting to the API ($url)", + $this->generateErrorMessage(json_decode($http_body)), $response_info['http_code'], $http_header, $data @@ -344,4 +344,25 @@ protected function httpParseHeaders($raw_headers) return $headers; } + + protected function generateErrorMessage($response) + { + $errorMessage = 'An error occurred while processing payment'; + + if (isset($response->error)) { + if (isset($response->error->message)) { + $errorMessage = (string) $response->error->message; + } + + if (isset($response->error->details)) { + $errorMessage = ''; + + foreach ($response->error->details as $detail) { + $errorMessage .= $detail->message; + } + } + } + + return $errorMessage; + } } diff --git a/lib/Configuration.php b/lib/Configuration.php index 5f1530b..84f435f 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -84,8 +84,8 @@ class Configuration * @var array */ protected $supportedEnvironments = array( - "sandbox" => array("host" => "https://api.sandbox.zipmoney.com.au/merchant/v1"), - "production" => array("host" => 'https://api.zipmoney.com.au/merchant/v1') + "sandbox" => array("host" => "https://global-api.sand.au.edge.zip.co/merchant"), + "production" => array("host" => 'https://global-api.prod.au.edge.zip.co/merchant') ); /** @@ -101,16 +101,16 @@ class Configuration * @var string */ protected $curlTimeout = 0; - + /** - * Number of retries allowed if the first one fails. + * Number of retries allowed if the first one fails. * * @var string */ protected $curlNumRetries = 3; /** - * Number of retries allowed if the first one fails. + * Number of retries allowed if the first one fails. * * @var string */ @@ -135,7 +135,7 @@ class Configuration * * @var bool */ - protected $debug = false; + protected $debug = false; /** * Debug file location (log to STDOUT by default) @@ -510,7 +510,7 @@ public function setRetryInterval($retryInterval) $this->retryInterval = $retryInterval; return $this; } - + /** * Gets the Retry Interval Value * @@ -664,14 +664,14 @@ public function getEnvironment() /** * Sets the environment * - * @param bool $environment + * @param bool $environment * * @return Configuration */ public function setEnvironment($environment) - { + { $this->environment = $environment; - + $host = $this->supportedEnvironments['production']['host']; if(in_array($environment,array_keys($this->supportedEnvironments))){ @@ -843,14 +843,14 @@ public function setApiVersion($version) public function setDefaultHeaders() { $user_agent_array = array(); - + if( $platform = $this->getPlatform() ){ $user_agent_array[] = $platform; } $default_user_agent = "merchantapi-php"; - + if( $package_version = $this->getPackageVersion() ){ $user_agent_array[] = $default_user_agent."/".$package_version; } else { @@ -870,12 +870,12 @@ public function setDefaultHeaders() * @return string */ public function getPackageVersion() - { + { $package_config = file_get_contents(dirname(__FILE__)."./../composer.json"); - if($package_config){ - $package_config_object = json_decode($package_config); - if(is_object($package_config_object) && isset($package_config_object->version)){ + if ($package_config) { + $package_config_object = json_decode($package_config); + if (is_object($package_config_object) && isset($package_config_object->version)) { return $package_config_object->version; } } diff --git a/lib/Model/Charge.php b/lib/Model/Charge.php index e0cad31..a2f3201 100644 --- a/lib/Model/Charge.php +++ b/lib/Model/Charge.php @@ -18,15 +18,15 @@ class Charge implements ArrayAccess const DISCRIMINATOR = 'subclass'; /** - * The original name of the model. - * @var string - */ + * The original name of the model. + * @var string + */ protected static $swaggerModelName = 'Charge'; /** - * Array of property to type mappings. Used for (de)serialization - * @var string[] - */ + * Array of property to type mappings. Used for (de)serialization + * @var string[] + */ protected static $zipTypes = array( 'id' => 'string', 'reference' => 'string', @@ -38,7 +38,8 @@ class Charge implements ArrayAccess 'created_date' => '\DateTime', 'order' => '\zipMoney\Model\ChargeOrder', 'metadata' => 'object', - 'receipt_number' => 'string' + 'receipt_number' => 'string', + 'product' => 'string', ); public static function zipTypes() @@ -61,7 +62,8 @@ public static function zipTypes() 'created_date' => 'created_date', 'order' => 'order', 'metadata' => 'metadata', - 'receipt_number' => 'receipt_number' + 'receipt_number' => 'receipt_number', + 'product' => 'product', ); @@ -80,7 +82,8 @@ public static function zipTypes() 'created_date' => 'setCreatedDate', 'order' => 'setOrder', 'metadata' => 'setMetadata', - 'receipt_number' => 'setReceiptNumber' + 'receipt_number' => 'setReceiptNumber', + 'product' => 'setProduct', ); @@ -99,7 +102,8 @@ public static function zipTypes() 'created_date' => 'getCreatedDate', 'order' => 'getOrder', 'metadata' => 'getMetadata', - 'receipt_number' => 'getReceiptNumber' + 'receipt_number' => 'getReceiptNumber', + 'product' => 'getProduct', ); public static function attributeMap() @@ -122,9 +126,9 @@ public static function getters() const STATE_CANCELLED = 'cancelled'; const STATE_DECLINED = 'declined'; const STATE_REFUNDED = 'refunded'; - - + + /** * Gets allowable values of the enum * @return string[] @@ -139,7 +143,7 @@ public function getStateAllowableValues() self::STATE_REFUNDED, ); } - + /** * Associative array for storing property values @@ -164,6 +168,7 @@ public function __construct(array $data = null) $this->container['order'] = isset($data['order']) ? $data['order'] : null; $this->container['metadata'] = isset($data['metadata']) ? $data['metadata'] : null; $this->container['receipt_number'] = isset($data['receipt_number']) ? $data['receipt_number'] : null; + $this->container['product'] = isset($data['product']) ? $data['product'] : null; } /** @@ -187,9 +192,12 @@ public function listInvalidProperties() if ($this->container['state'] === null) { $invalid_properties[] = "'state' can't be null"; } - $allowed_values = array("authorised", "captured", "cancelled", "refunded", "declined"); + + $allowed_values = $this->getStateAllowableValues(); if (!in_array($this->container['state'], $allowed_values)) { - $invalid_properties[] = "invalid value for 'state', must be one of 'authorised', 'captured', 'cancelled', 'refunded', 'declined'."; + $invalid_properties[] + = "invalid value for 'state', + must be one of '".implode("','",$allowed_values)."'."; } if ($this->container['captured_amount'] === null) { @@ -236,7 +244,7 @@ public function valid() if ($this->container['state'] === null) { return false; } - $allowed_values = array("authorised", "captured", "cancelled", "refunded", "declined"); + $allowed_values = $this->getStateAllowableValues(); if (!in_array($this->container['state'], $allowed_values)) { return false; } @@ -362,9 +370,12 @@ public function getState() */ public function setState($state) { - $allowed_values = array('authorised', 'captured', 'cancelled', 'refunded', 'declined'); + $allowed_values = $this->getStateAllowableValues(); if ((!in_array($state, $allowed_values))) { - throw new \InvalidArgumentException("Invalid value for 'state', must be one of 'authorised', 'captured', 'cancelled', 'refunded', 'declined'"); + throw new \InvalidArgumentException( + "Invalid value for 'state', + must be one of '".implode("','",$allowed_values)."'." + ); } $this->container['state'] = $state; @@ -506,6 +517,26 @@ public function setReceiptNumber($receipt_number) return $this; } + /** + * Sets product + * @param string $product + * @return $this + */ + public function setProduct($product) + { + $this->container['product'] = $product; + + return $this; + } + + /** + * Gets product + * @return string + */ + public function getProduct() + { + return $this->container['product']; + } /** * Returns true if offset exists. False otherwise. * @param integer $offset Offset diff --git a/lib/Model/CreateChargeRequest.php b/lib/Model/CreateChargeRequest.php index 7112c5c..7073164 100644 --- a/lib/Model/CreateChargeRequest.php +++ b/lib/Model/CreateChargeRequest.php @@ -101,23 +101,6 @@ public static function getters() return self::$getters; } - const CURRENCY_AUD = 'AUD'; - const CURRENCY_NZD = 'NZD'; - - - - /** - * Gets allowable values of the enum - * @return string[] - */ - public function getCurrencyAllowableValues() - { - return array( - self::CURRENCY_AUD, - self::CURRENCY_NZD, - ); - } - /** * Associative array for storing property values @@ -158,9 +141,9 @@ public function listInvalidProperties() if ($this->container['currency'] === null) { $invalid_properties[] = "'currency' can't be null"; } - $allowed_values = array("AUD", "NZD"); - if (!in_array($this->container['currency'], $allowed_values)) { - $invalid_properties[] = "invalid value for 'currency', must be one of 'AUD', 'NZD'."; + $allowed_values = currencyUtil::isValidCurrency($this->container['currency']); + if (!$allowed_values['valid']) { + $invalid_properties[] = $allowed_values['message']; } return $invalid_properties; @@ -184,8 +167,8 @@ public function valid() if ($this->container['currency'] === null) { return false; } - $allowed_values = array("AUD", "NZD"); - if (!in_array($this->container['currency'], $allowed_values)) { + $allowed_values = currencyUtil::isValidCurrency($this->container['currency']); + if (!$allowed_values['valid']) { return false; } return true; @@ -271,9 +254,9 @@ public function getCurrency() */ public function setCurrency($currency) { - $allowed_values = array('AUD', 'NZD'); - if ((!in_array($currency, $allowed_values))) { - throw new \InvalidArgumentException("Invalid value for 'currency', must be one of 'AUD', 'NZD'"); + $allowed_values = currencyUtil::isValidCurrency($currency); + if (!$allowed_values['valid']) { + throw new \InvalidArgumentException($allowed_values['message']); } $this->container['currency'] = $currency; diff --git a/lib/Model/CurrencyUtil.php b/lib/Model/CurrencyUtil.php new file mode 100644 index 0000000..ae4cdc1 --- /dev/null +++ b/lib/Model/CurrencyUtil.php @@ -0,0 +1,63 @@ + + */ + +namespace zipMoney\Model; + +class CurrencyUtil +{ + // allowed currency codes + const CURRENCY_AUD = 'AUD'; + const CURRENCY_NZD = 'NZD'; + const CURRENCY_GBP = 'GBP'; + const CURRENCY_USD = 'USD'; + const CURRENCY_ZAR = 'ZAR'; + const CURRENCY_CAD = 'CAD'; + + /** + * Gets allowable values of the enum + * @return string[] + */ + private static function getAllowedCurrencyList() + { + return array( + self::CURRENCY_AUD, + self::CURRENCY_NZD, + self::CURRENCY_USD, + self::CURRENCY_GBP, + self::CURRENCY_ZAR, + self::CURRENCY_CAD, + ); + } + + public static function isValidCurrency($currency) + { + $result = array( + 'valid' => true, + 'message' => '', + ); + $allowed_values = self::getAllowedCurrencyList(); + if (!in_array($currency, $allowed_values)) { + $result['valid'] = false; + $result['message'] = "invalid value for 'currency', must be one of '".implode("','",$allowed_values)."'."; + } + return $result; + } + + public static function getAvailableRegions() + { + return array( + 'au' => 'Australia', + 'nz' => 'New Zealand', + 'us' => 'United States', + 'uk' => 'United Kingdom', + 'za' => 'South Africa', + 'ca' => 'Canada', + ); + } +} diff --git a/lib/Model/Metadata.php b/lib/Model/Metadata.php index e5577dc..40796b0 100644 --- a/lib/Model/Metadata.php +++ b/lib/Model/Metadata.php @@ -8,7 +8,6 @@ * @link https://github.com/zipMoney/merchantapi-php */ - namespace zipMoney\Model; use \ArrayAccess; @@ -28,7 +27,7 @@ class Metadata implements ArrayAccess * @var string[] */ protected static $zipTypes = array( - + ); public static function zipTypes() @@ -41,25 +40,23 @@ public static function zipTypes() * @var string[] */ protected static $attributeMap = array( - - ); + ); /** * Array of attributes to setter functions (for deserialization of responses) * @var string[] */ protected static $setters = array( - - ); + ); /** * Array of attributes to getter functions (for serialization of requests) * @var string[] */ protected static $getters = array( - + ); public static function attributeMap() @@ -77,10 +74,6 @@ public static function getters() return self::$getters; } - - - - /** * Associative array for storing property values * @var mixed[] @@ -93,6 +86,9 @@ public static function getters() */ public function __construct(array $data = null) { + if (is_array($data) && $data) { + $this->set($data); + } } /** @@ -164,6 +160,33 @@ public function offsetUnset($offset) unset($this->container[$offset]); } + public function set($array) + { + foreach ($array as $key => $value) { + if (!property_exists($this, $key)) { + $this->setData($key, $value); + } + } + } + + public function setData($key, $value) + { + $this->container[$key] = $value; + $propertyName = str_replace('_', '', ucwords($key, '_')); + self::$zipTypes[$key] = 'string'; + self::$attributeMap[$key] = $propertyName; + self::$getters[$key] = 'get'.$propertyName; + } + + /** + * Gets + * @return string + */ + public function get($key) + { + return $this->container[$key]; + } + /** * Gets the string presentation of the object * @return string @@ -177,5 +200,3 @@ public function __toString() return json_encode(\zipMoney\ObjectSerializer::sanitizeForSerialization($this)); } } - - diff --git a/lib/Model/SettlementTransactions.php b/lib/Model/SettlementTransactions.php index e09f678..9fe0670 100644 --- a/lib/Model/SettlementTransactions.php +++ b/lib/Model/SettlementTransactions.php @@ -18,15 +18,15 @@ class SettlementTransactions implements ArrayAccess const DISCRIMINATOR = 'subclass'; /** - * The original name of the model. - * @var string - */ + * The original name of the model. + * @var string + */ protected static $swaggerModelName = 'settlement_transactions'; /** - * Array of property to type mappings. Used for (de)serialization - * @var string[] - */ + * Array of property to type mappings. Used for (de)serialization + * @var string[] + */ protected static $zipTypes = array( 'id' => 'string', 'charge_id' => 'string', @@ -85,9 +85,9 @@ public static function getters() return self::$getters; } - - + + /** * Associative array for storing property values @@ -174,7 +174,7 @@ public function setChargeId($charge_id) } /** - * Gets + * Gets * @return string */ public function get() @@ -183,13 +183,13 @@ public function get() } /** - * Sets + * Sets * @param string $ * @return $this */ - public function set($) + public function set($val) { - $this->container[''] = $; + $this->container[''] = $val; return $this; } diff --git a/lib/Model/ShopperStatistics.php b/lib/Model/ShopperStatistics.php index 06e8cdc..0970e63 100644 --- a/lib/Model/ShopperStatistics.php +++ b/lib/Model/ShopperStatistics.php @@ -117,26 +117,11 @@ public static function getters() return self::$getters; } - const CURRENCY_AUD = 'AUD'; - const CURRENCY_NZD = 'NZD'; const FRAUD_CHECK_RESULT_PASS = 'pass'; const FRAUD_CHECK_RESULT_FAIL = 'fail'; const FRAUD_CHECK_RESULT_UNKNOWN = 'unknown'; - - - /** - * Gets allowable values of the enum - * @return string[] - */ - public function getCurrencyAllowableValues() - { - return array( - self::CURRENCY_AUD, - self::CURRENCY_NZD, - ); - } - + /** * Gets allowable values of the enum * @return string[] @@ -149,7 +134,7 @@ public function getFraudCheckResultAllowableValues() self::FRAUD_CHECK_RESULT_UNKNOWN, ); } - + /** * Associative array for storing property values @@ -185,9 +170,9 @@ public function listInvalidProperties() { $invalid_properties = array(); - $allowed_values = array("AUD", "NZD"); - if (!in_array($this->container['currency'], $allowed_values)) { - $invalid_properties[] = "invalid value for 'currency', must be one of 'AUD', 'NZD'."; + $allowed_values = currencyUtil::isValidCurrency($this->container['currency']); + if (!$allowed_values['valid']) { + $invalid_properties[] = $allowed_values['message']; } $allowed_values = array("pass", "fail", "unknown"); @@ -207,8 +192,8 @@ public function listInvalidProperties() public function valid() { - $allowed_values = array("AUD", "NZD"); - if (!in_array($this->container['currency'], $allowed_values)) { + $allowed_values = currencyUtil::isValidCurrency($this->container['currency']); + if (!$allowed_values['valid']) { return false; } $allowed_values = array("pass", "fail", "unknown"); @@ -382,9 +367,9 @@ public function getCurrency() */ public function setCurrency($currency) { - $allowed_values = array('AUD', 'NZD'); - if (!is_null($currency) && (!in_array($currency, $allowed_values))) { - throw new \InvalidArgumentException("Invalid value for 'currency', must be one of 'AUD', 'NZD'"); + $allowed_values = currencyUtil::isValidCurrency($currency); + if (!is_null($currency) && (!$allowed_values['valid'])) { + throw new \InvalidArgumentException($allowed_values['message']); } $this->container['currency'] = $currency; diff --git a/lib/ObjectSerializer.php b/lib/ObjectSerializer.php index 23ab908..05348a7 100644 --- a/lib/ObjectSerializer.php +++ b/lib/ObjectSerializer.php @@ -39,15 +39,18 @@ public static function sanitizeForSerialization($data) $data[$property] = self::sanitizeForSerialization($value); } return $data; - } elseif (is_object($data)) { + } elseif (is_object($data)) { $attr = $data::attributeMap(); $values = array(); foreach (array_keys($data::zipTypes()) as $property) { $getterArr = $data::getters(); $getter = $getterArr[$property]; - if ($data->$getter() !== null) { + if(method_exists(get_class($data), $getter) && $data->$getter() !== null){ $values[$attr[$property]] = self::sanitizeForSerialization($data->$getter()); } + if(method_exists(get_class($data), 'get') && $data->get($property) !== null){ + $values[$attr[$property]] = self::sanitizeForSerialization($data->get($property)); + } } return (object)$values; } else { diff --git a/test/Api/ChargesApiTest.php b/test/Api/ChargesApiTest.php index e4f5d8d..2b82cdb 100644 --- a/test/Api/ChargesApiTest.php +++ b/test/Api/ChargesApiTest.php @@ -8,31 +8,26 @@ * @link https://github.com/zipMoney/merchantapi-php */ - namespace zipMoney; use \zipMoney\Api\ChargesApi; use \zipMoney\Api\CheckoutsApi; +use \zipMoney\Setup; class ChargesApiTest extends Setup { - /** * Setup before running any test cases */ public static function setUpBeforeClass() { - } - - /** * Clean up after running each test case */ public function tearDown() { - } /** @@ -40,7 +35,6 @@ public function tearDown() */ public static function tearDownAfterClass() { - } /** @@ -48,10 +42,10 @@ public static function tearDownAfterClass() * * Cancel a charge. * @expectedException \zipMoney\ApiException - * @expectedExceptionMessage [404] Error connecting to the API (https://api.sandbox.zipmoney.com.au/merchant/v1/charges/1/cancel) + * @expectedExceptionMessage An error occurred while processing payment */ public function testChargesCancel() - { + { $chargesApi = new ChargesApi; $response = $chargesApi->chargesCancel(1); } @@ -59,23 +53,23 @@ public function testChargesCancel() /** * Test case for chargesCapture * - * Capture a charge. + * Capture a charge. * @expectedException \zipMoney\ApiException - * @expectedExceptionMessage [404] Error connecting to the API (https://api.sandbox.zipmoney.com.au/merchant/v1/charges/1/capture) + * @expectedExceptionMessage An error occurred while processing payment */ public function testChargesCapture() - { - $chargesApi = new ChargesApi; + { + $chargesApi = new ChargesApi; $req = $this->_payloadHelper->getCapturePayload(); - $response = $chargesApi->chargesCapture(1,$req); + $response = $chargesApi->chargesCapture(1, $req); } /** * Test case for chargesCreate * - * Create a charge. + * Create a charge. * @expectedException \zipMoney\ApiException - * @expectedExceptionMessage [400] Error connecting to the API (https://api.sandbox.zipmoney.com.au/merchant/v1/charges) + * @expectedExceptionMessage An error occurred while processing payment */ public function testChargesCreate() @@ -87,18 +81,17 @@ public function testChargesCreate() $checkout = $checkoutsApi->checkoutsCreate($req); $this->_payloadHelper->setCheckoutId($checkout->getId()); - + $chargeReq = $this->_payloadHelper->getChargePayload(); $response = $chargesApi->chargesCreate($chargeReq); } - /** * Test case for chargesCreateRaisesException * * Create a charge. * @expectedException \zipMoney\ApiException - * @expectedExceptionMessage [400] Error connecting to the API (https://api.sandbox.zipmoney.com.au/merchant/v1/charges) + * @expectedExceptionMessage An error occurred while processing payment */ public function testChargesCreateRaisesException() { @@ -115,7 +108,6 @@ public function testChargesCreateRaisesException() */ public function testChargesList() { - } /** @@ -126,7 +118,5 @@ public function testChargesList() */ public function testChargesRetrieve() { - } - } diff --git a/test/Api/CheckoutsApiTest.php b/test/Api/CheckoutsApiTest.php index 2075ed9..d479858 100644 --- a/test/Api/CheckoutsApiTest.php +++ b/test/Api/CheckoutsApiTest.php @@ -10,27 +10,22 @@ namespace zipMoney; - use \zipMoney\Api\CheckoutsApi; class CheckoutsApiTest extends Setup -{ - +{ /** * Setup before running any test cases */ public static function setUpBeforeClass() - { - + { } - /** * Clean up after running each test case */ public function tearDown() { - } /** @@ -38,7 +33,6 @@ public function tearDown() */ public static function tearDownAfterClass() { - } /** @@ -48,18 +42,17 @@ public static function tearDownAfterClass() * */ public function testCheckoutsCreate() - { - try{ + { + try { $checkoutsApi = new CheckoutsApi; $req = $this->_payloadHelper->getCheckoutPayload(); $checkout = $checkoutsApi->checkoutsCreate($req); $this->assertNotNull($checkout->getId()); $this->assertNotNull($checkout->getUri()); - } catch(ApiException $e){ - print_r($e->getResponseBody()); + } catch (ApiException $e) { + $this->assertSame('An error occurred while processing payment', $e->getMessage()); } - } /** @@ -70,7 +63,5 @@ public function testCheckoutsCreate() */ public function testCheckoutsGet() { - } - } diff --git a/test/Api/RefundsApiTest.php b/test/Api/RefundsApiTest.php index 9b61101..853cf4e 100644 --- a/test/Api/RefundsApiTest.php +++ b/test/Api/RefundsApiTest.php @@ -11,7 +11,6 @@ namespace zipMoney; - use \zipMoney\Api\RefundsApi; class RefundsApiTest extends Setup @@ -22,16 +21,14 @@ class RefundsApiTest extends Setup */ public static function setUpBeforeClass() { - } - + /** * Clean up after running each test case */ public function tearDown() { - } /** @@ -39,7 +36,6 @@ public function tearDown() */ public static function tearDownAfterClass() { - } /** @@ -47,12 +43,12 @@ public static function tearDownAfterClass() * * Create a refund. * @expectedException \zipMoney\ApiException - * @expectedExceptionMessage [402] Error connecting to the API (https://api.sandbox.zipmoney.com.au/merchant/v1/refunds) + * @expectedExceptionMessage An error occurred while processing payment */ public function testRefundsCreate() { - $refundsApi = new RefundsApi; - $this->_payloadHelper->setChargeId(1); + $refundsApi = new RefundsApi; + $this->_payloadHelper->setChargeId(1); $req = $this->_payloadHelper->getRefundPayload(); $response = $refundsApi->refundsCreate($req); } @@ -65,7 +61,6 @@ public function testRefundsCreate() */ public function testRefundsList() { - } /** @@ -76,7 +71,5 @@ public function testRefundsList() */ public function testRefundsRetrieve() { - } - } diff --git a/test/ConfigurationTest.php b/test/ConfigurationTest.php index 85101ca..bb8c9a9 100644 --- a/test/ConfigurationTest.php +++ b/test/ConfigurationTest.php @@ -1,4 +1,5 @@ setPlatform("Magento/1.0.0"); - $this->assertEquals($config->getPlatform(),"Magento/1.0.0"); + $config = Configuration::getDefaultConfiguration(); + $config->setPlatform("Magento/1.0.0"); + $this->assertEquals($config->getPlatform(), "Magento/1.0.0"); } public function testEnvironment() { - $config = Configuration::getDefaultConfiguration(); - - $config->setEnvironment("sandbox"); - $this->assertEquals($config->getEnvironment(),"sandbox"); - $this->assertEquals($config->getHost(),"https://api.sandbox.zipmoney.com.au/merchant/v1"); + $config = Configuration::getDefaultConfiguration(); - $config->setEnvironment("production"); - $this->assertEquals($config->getEnvironment(),"production"); - $this->assertEquals($config->getHost(),"https://api.zipmoney.com.au/merchant/v1"); + $config->setEnvironment("sandbox"); + $this->assertEquals($config->getEnvironment(), "sandbox"); + $this->assertEquals($config->getHost(), "https://global-api.sand.au.edge.zip.co/merchant"); + $config->setEnvironment("production"); + $this->assertEquals($config->getEnvironment(), "production"); + $this->assertEquals($config->getHost(), "https://global-api.prod.au.edge.zip.co/merchant"); } public function testApiHeaders() { - $config = Configuration::getDefaultConfiguration(); - - $config->setPlatform("Magento/1.0.0") - ->setDefaultHeaders("sandbox"); + $config = Configuration::getDefaultConfiguration(); - $this->assertEquals($config->getUserAgent(),"Magento/1.0.0 merchantapi-php/1.0.6"); - $this->assertEquals($config->getDefaultHeaders(),array("Zip-Version"=>"2017-03-01")); + $config->setPlatform("Magento/1.0.0") + ->setDefaultHeaders("sandbox"); + $packageJson = file_get_contents(dirname(__FILE__)."./../composer.json"); + $data = json_decode($packageJson); + $version = $data->version; + $this->assertEquals($config->getUserAgent(), "Magento/1.0.0 merchantapi-php/" . $version); + $this->assertEquals($config->getDefaultHeaders(), array("Zip-Version" => "2017-03-01")); } public function testPackageVersion() - { + { $config = Configuration::getDefaultConfiguration(); - $this->assertEquals($config->getPackageVersion(),"1.0.6"); + $packageJson = file_get_contents(dirname(__FILE__)."./../composer.json"); + $data = json_decode($packageJson); + $this->assertEquals($config->getPackageVersion(), $data->version); } - } diff --git a/test/Setup.php b/test/Setup.php index 0feff61..48b59ce 100644 --- a/test/Setup.php +++ b/test/Setup.php @@ -1,4 +1,5 @@ _payloadHelper = new Payload; - /** - * Setup before running each test case - */ - public function setUp() - { - $this->_payloadHelper = new Payload; - - $auth = parse_ini_file("auth.ini"); - - Configuration::getDefaultConfiguration()->setApiKey('Authorization', "Bearer {$auth['private_key']}"); - Configuration::getDefaultConfiguration()->setEnvironment("sandbox"); + $auth = parse_ini_file("auth.ini"); - } -} \ No newline at end of file + Configuration::getDefaultConfiguration()->setApiKey('Authorization', "Bearer {$auth['private_key']}"); + Configuration::getDefaultConfiguration()->setEnvironment("sandbox"); + Configuration::getDefaultConfiguration()->setSSLVerification(false); + } +} diff --git a/test/auth.ini b/test/auth.ini new file mode 100644 index 0000000..d22e0f5 --- /dev/null +++ b/test/auth.ini @@ -0,0 +1 @@ +private_key='***** your sandbox key *****'