diff --git a/.travis.yml b/.travis.yml index 3a421e625..5efc2b8ae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,8 @@ php: - 5.4 - 5.5 - 5.6 - - hhvm + - 7.0 + - 7.1 - nightly before_script: - composer install \ No newline at end of file diff --git a/composer.json b/composer.json index a310aeef8..43a03c320 100644 --- a/composer.json +++ b/composer.json @@ -11,6 +11,7 @@ }, "require-dev": { "phpunit/phpunit": "~4", + "satooshi/php-coveralls": "~1.0.1", "squizlabs/php_codesniffer": "~2.3" }, "autoload": { diff --git a/src/Adyen/AdyenException.php b/src/Adyen/AdyenException.php index 0b3ed6d8b..d476125fd 100644 --- a/src/Adyen/AdyenException.php +++ b/src/Adyen/AdyenException.php @@ -7,8 +7,39 @@ class AdyenException extends Exception { -//"status": 403, -//"errorCode": "901", -//"message": "Invalid Merchant Account", -//"errorType": "security" + protected $_status; + protected $_errorType; + + /** + * AdyenException constructor. + * @param string $message + * @param int $code + * @param Exception|null $previous + * @param null $status + * @param null $errorType + */ + public function __construct($message = "", $code = 0, Exception $previous = null, $status = null, $errorType = null) + { + $this->_status = $status; + $this->_errorType = $errorType; + parent::__construct($message, $code, $previous); + } + + /** + * Get status + * + * @return null + */ + public function getStatus() + { + return $this->_status; + } + + /** + * Get Adyen Error type + */ + public function getErrorType() + { + return $this->_errorType; + } } diff --git a/src/Adyen/Client.php b/src/Adyen/Client.php index 70ee65093..5a73f3a8b 100644 --- a/src/Adyen/Client.php +++ b/src/Adyen/Client.php @@ -8,13 +8,13 @@ class Client { - const LIB_VERSION = "1.2.0"; + const LIB_VERSION = "1.3.0"; const USER_AGENT_SUFFIX = "adyen-php-api-library/"; const ENDPOINT_TEST = "https://pal-test.adyen.com"; const ENDPOINT_LIVE = "https://pal-live.adyen.com"; const ENPOINT_TEST_DIRECTORY_LOOKUP = "https://test.adyen.com/hpp/directory.shtml"; const ENPOINT_LIVE_DIRECTORY_LOOKUP = "https://live.adyen.com/hpp/directory.shtml"; - const API_VERSION = "v18"; + const API_VERSION = "v25"; /** * @var Adyen_Config $config diff --git a/src/Adyen/ConnectionException.php b/src/Adyen/ConnectionException.php new file mode 100644 index 000000000..5d24bf5b7 --- /dev/null +++ b/src/Adyen/ConnectionException.php @@ -0,0 +1,10 @@ +error($msg); - throw new \Adyen\AdyenException($msg); + throw new \Adyen\ConnectionException($msg); } /** @@ -217,13 +217,13 @@ private function handleCurlError($url, $errno, $message, $logger) * @param $logger * @throws \Adyen\AdyenException */ - private function handleResultError($result, $logger) + protected function handleResultError($result, $logger) { $decodeResult = json_decode($result, true); if(isset($decodeResult['message']) && isset($decodeResult['errorCode'])) { $logger->error($decodeResult['errorCode'] . ': ' . $decodeResult['message']); - throw new \Adyen\AdyenException($decodeResult['message'], $decodeResult['errorCode']); + throw new \Adyen\AdyenException($decodeResult['message'], $decodeResult['errorCode'], null, $decodeResult['status'], $decodeResult['errorType']); } $logger->error($result); throw new \Adyen\AdyenException($result); diff --git a/src/Adyen/Service/Payout.php b/src/Adyen/Service/Payout.php index fc54291b1..244aef39d 100644 --- a/src/Adyen/Service/Payout.php +++ b/src/Adyen/Service/Payout.php @@ -13,6 +13,7 @@ class Payout extends \Adyen\Service protected $_declineThirdParty; protected $_storeDetailsAndSubmitThirdParty; protected $_submitThirdParty; + protected $_storeDetail; public function __construct(\Adyen\Client $client) { @@ -26,7 +27,7 @@ public function __construct(\Adyen\Client $client) $this->_declineThirdParty = new \Adyen\Service\ResourceModel\Payout\ThirdParty\DeclineThirdParty($this); $this->_storeDetailsAndSubmitThirdParty = new \Adyen\Service\ResourceModel\Payout\ThirdParty\StoreDetailsAndSubmitThirdParty($this); $this->_submitThirdParty = new \Adyen\Service\ResourceModel\Payout\ThirdParty\SubmitThirdParty($this); - + $this->_storeDetail = new \Adyen\Service\ResourceModel\Payout\ThirdParty\StoreDetail($this); } public function confirm($params) { @@ -61,7 +62,10 @@ public function submitThirdParty($params) { $result = $this->_submitThirdParty->request($params); return $result; } - + public function storeDetail($params) { + $result = $this->_storeDetail->request($params); + return $result; + } } diff --git a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetail.php b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetail.php new file mode 100644 index 000000000..1fd60b92d --- /dev/null +++ b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetail.php @@ -0,0 +1,22 @@ +_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/storeDetail'; + parent::__construct($service, $this->_endpoint, $this->_requiredFields); + } + +} \ No newline at end of file diff --git a/tests/ExceptionTest.php b/tests/ExceptionTest.php index ca40f5c20..bac76c6a3 100644 --- a/tests/ExceptionTest.php +++ b/tests/ExceptionTest.php @@ -116,7 +116,7 @@ public function testExceptionMissingUsernamePassword() } // check if exception is correct - $this->assertEquals('Adyen\AdyenException', get_class($e)); + $this->assertEquals('Adyen\ConnectionException', get_class($e)); $this->assertEquals("Probably your Web Service username and/or password is incorrect\n(Network error [errno 0]: )", $e->getMessage()); $this->assertEquals('0', $e->getCode()); } diff --git a/tests/PayoutThirdPartyTest.php b/tests/PayoutThirdPartyTest.php index d80e86fe8..7a15fb856 100644 --- a/tests/PayoutThirdPartyTest.php +++ b/tests/PayoutThirdPartyTest.php @@ -134,6 +134,47 @@ public function testStoreDetailAndSubmitPayoutThirdPartyInvalidIban() $this->assertEquals('Adyen\AdyenException', get_class($e)); $this->assertEquals('Invalid iban', $e->getMessage()); } + + public function testStoreDetailsBankSuccess() + { + // initialize client + $client = $this->createPayoutClient(); + + // initialize service + $service = new Service\Payout($client); + + $json = '{ + "bank": { + "iban": "FR14 2004 1010 0505 0001 3M02 606", + "ownerName": "John Smith", + "countryCode": "FR" + }, + "recurring": { + "contract": "PAYOUT" + }, + "shopperEmail": "john.smith@test.com", + "shopperReference": "johnsmithuniqueid", + "merchantAccount": "' . $this->_merchantAccount .'" + }'; + + $params = json_decode($json, true); + + try { + $result = $service->storeDetail($params); + } catch (\Exception $e) { + $this->validateApiPermission($e); + } + + // must exists + $this->assertTrue(isset($result['resultCode'])); + + // Assert + $this->assertEquals('Success', $result['resultCode']); + + // return the result so this can be used in other test cases + return $result; + + } public function testStoreDetailAndSubmitPayoutThirdPartySuccess() {