Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge from 'Develop' #30

Merged
merged 23 commits into from
Aug 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
123fd86
Add storeDetail resource and a test for bank account
Dec 28, 2016
3007a30
Merge pull request #19 from polo2ro/develop
rikterbeek Jan 2, 2017
79b922c
add coveralls
rikterbeek Mar 10, 2017
33fbd5d
add coveralls config file
rikterbeek Mar 10, 2017
e9807a3
removed deprecated src_dir
rikterbeek Mar 10, 2017
d3e100e
use new coveralls implementation
rikterbeek Mar 10, 2017
062d025
coveralls fix
rikterbeek Mar 10, 2017
9168a5c
revert
rikterbeek Mar 10, 2017
d4b7a9c
Update to v25
rikterbeek Apr 14, 2017
79ab1eb
Made error handlers protected instead of private
May 3, 2017
4112c8d
Also testing php 7.0 and 7.1
May 3, 2017
6c2c4e2
Merge pull request #24 from ivodvb/curl-client-internals-protected
rikterbeek May 4, 2017
538f1e5
Merge pull request #25 from ivodvb/php70-71-travis-support
rikterbeek May 4, 2017
24d1500
#27 use unique Exception for CURL errors. Changed AdyenException to C…
rikterbeek Jun 26, 2017
42a821d
change distribution to trusty to support HHVM tests
rikterbeek Jun 27, 2017
2203a3f
change distribution to trusty to support HHVM tests
rikterbeek Jun 27, 2017
49f1c89
fix php version in matrix
rikterbeek Jun 27, 2017
2737a21
change distribution to trusty to support HHVM tests
rikterbeek Jun 27, 2017
b7017c6
remove hhvm from automatic build because of limitation travis-ci plat…
rikterbeek Jul 3, 2017
e7b42bf
#29 Add status and ErrorType into the AdyenException
rikterbeek Jul 3, 2017
bda49db
Merge pull request #28 from Adyen/develop-rik
rikterbeek Jul 3, 2017
95f6faf
update version to 1.3.0
rikterbeek Aug 7, 2017
1542f8e
Merge pull request #31 from Adyen/develop-rik
rikterbeek Aug 7, 2017
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
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