Skip to content

Commit

Permalink
Merge pull request #30 from Adyen/develop
Browse files Browse the repository at this point in the history
Merge from 'Develop'
  • Loading branch information
rikterbeek authored Aug 7, 2017
2 parents 78cadcb + 1542f8e commit 22df6a5
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ php:
- 5.4
- 5.5
- 5.6
- hhvm
- 7.0
- 7.1
- nightly
before_script:
- composer install
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"require-dev": {
"phpunit/phpunit": "~4",
"satooshi/php-coveralls": "~1.0.1",
"squizlabs/php_codesniffer": "~2.3"
},
"autoload": {
Expand Down
39 changes: 35 additions & 4 deletions src/Adyen/AdyenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
4 changes: 2 additions & 2 deletions src/Adyen/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/Adyen/ConnectionException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Adyen;

use Exception;

class ConnectionException extends Exception
{

}
8 changes: 4 additions & 4 deletions src/Adyen/HttpClient/CurlClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public function requestPost(\Adyen\Service $service, $requestUrl, $params)
* @param $logger
* @throws \Adyen\AdyenException
*/
private function handleCurlError($url, $errno, $message, $logger)
protected function handleCurlError($url, $errno, $message, $logger)
{
switch ($errno) {
case CURLE_OK:
Expand All @@ -207,7 +207,7 @@ private function handleCurlError($url, $errno, $message, $logger)
}
$msg .= "\n(Network error [errno $errno]: $message)";
$logger->error($msg);
throw new \Adyen\AdyenException($msg);
throw new \Adyen\ConnectionException($msg);
}

/**
Expand All @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions src/Adyen/Service/Payout.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Payout extends \Adyen\Service
protected $_declineThirdParty;
protected $_storeDetailsAndSubmitThirdParty;
protected $_submitThirdParty;
protected $_storeDetail;

public function __construct(\Adyen\Client $client)
{
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}


}
22 changes: 22 additions & 0 deletions src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Adyen\Service\ResourceModel\Payout\ThirdParty;

class StoreDetail extends \Adyen\Service\AbstractResource
{
protected $_requiredFields = array(
'merchantAccount',
'recurring.contract',
'shopperEmail',
'shopperReference'
);

protected $_endpoint;

public function __construct($service)
{
$this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/storeDetail';
parent::__construct($service, $this->_endpoint, $this->_requiredFields);
}

}
2 changes: 1 addition & 1 deletion tests/ExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
41 changes: 41 additions & 0 deletions tests/PayoutThirdPartyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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": "[email protected]",
"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()
{
Expand Down

0 comments on commit 22df6a5

Please sign in to comment.