From 0905507ee2fa746f84a63d58663afe204d735a20 Mon Sep 17 00:00:00 2001 From: attilak Date: Wed, 10 Oct 2018 11:53:54 +0200 Subject: [PATCH 01/10] - Adding filterParameters in the resources where you can define if there is any parameter in the request which you don't want to send towards the specified API endpoint - PHP Doc blocks added - Unit tests added --- src/Adyen/Client.php | 12 +- src/Adyen/Service/AbstractResource.php | 127 +++++++++- .../ResourceModel/Checkout/PaymentMethods.php | 22 +- .../ResourceModel/Checkout/PaymentSession.php | 23 +- .../ResourceModel/Checkout/Payments.php | 22 +- .../Checkout/PaymentsDetails.php | 22 +- .../ResourceModel/Checkout/PaymentsResult.php | 22 +- .../CheckoutUtility/OriginKeys.php | 22 +- .../DirectoryLookup/Directory.php | 24 +- .../Modification/AdjustAuthorisation.php | 23 +- .../ResourceModel/Modification/Cancel.php | 29 ++- .../Modification/CancelOrRefund.php | 23 +- .../ResourceModel/Modification/Capture.php | 23 +- .../ResourceModel/Modification/Refund.php | 23 +- .../ResourceModel/Payment/Authorise.php | 23 +- .../ResourceModel/Payment/Authorise3D.php | 23 +- .../Payment/TerminalCloudAPI.php | 24 +- .../Service/ResourceModel/Payout/Confirm.php | 23 +- .../Service/ResourceModel/Payout/Decline.php | 23 +- .../Payout/StoreDetailsAndSubmit.php | 23 +- .../Service/ResourceModel/Payout/Submit.php | 23 +- .../Payout/ThirdParty/ConfirmThirdParty.php | 23 +- .../Payout/ThirdParty/DeclineThirdParty.php | 25 +- .../Payout/ThirdParty/StoreDetail.php | 23 +- .../StoreDetailsAndSubmitThirdParty.php | 23 +- .../Payout/ThirdParty/SubmitThirdParty.php | 23 +- .../ResourceModel/Recurring/Disable.php | 27 +- .../Recurring/ListRecurringDetails.php | 27 +- tests/TestCase.php | 36 +++ tests/Unit/AbstractResourceTest.php | 238 ++++++++++++++++++ 30 files changed, 919 insertions(+), 105 deletions(-) create mode 100644 tests/Unit/AbstractResourceTest.php diff --git a/src/Adyen/Client.php b/src/Adyen/Client.php index 4075af53a..8f06e08cf 100644 --- a/src/Adyen/Client.php +++ b/src/Adyen/Client.php @@ -9,6 +9,7 @@ class Client { const LIB_VERSION = "1.5.1"; + const LIB_NAME = "adyen-php-api-library"; const USER_AGENT_SUFFIX = "adyen-php-api-library/"; const ENDPOINT_TEST = "https://pal-test.adyen.com"; const ENDPOINT_LIVE = "https://pal-live.adyen.com"; @@ -93,7 +94,7 @@ public function setXApiKey($xApiKey) * Set environment to connect to test or live platform of Adyen * For live please specify the unique identifier. * - * @param $environment test + * @param string $environment * @param null $liveEndpointUrlPrefix Provide the unique live url prefix from the "API URLs and Response" menu in the Adyen Customer Area * @throws AdyenException */ @@ -179,6 +180,15 @@ public function setTimeout($value) $this->_config->set('timeout', $value); } + /** + * Get the library name + * + * @return string + */ + public function getLibraryName() + { + return self::LIB_NAME; + } /** * Get the library version diff --git a/src/Adyen/Service/AbstractResource.php b/src/Adyen/Service/AbstractResource.php index 9c67a01ac..5c416e8b3 100644 --- a/src/Adyen/Service/AbstractResource.php +++ b/src/Adyen/Service/AbstractResource.php @@ -2,41 +2,78 @@ namespace Adyen\Service; +use Adyen\AdyenException; + class AbstractResource { - + /** + * @var \Adyen\Service + */ protected $_service; + + /** + * @var string + */ protected $_endpoint; - public function __construct(\Adyen\Service $service, $endpoint) + /** + * @var array + */ + protected $paramsToFilter; + + /** + * AbstractResource constructor. + * + * @param \Adyen\Service $service + * @param $endpoint + * @param array $paramsToFilter + */ + public function __construct(\Adyen\Service $service, $endpoint, $paramsToFilter = array()) { $this->_service = $service; $this->_endpoint = $endpoint; + $this->paramsToFilter = $paramsToFilter; } - /** - * Do the request to the Http Client - * - * @param $params - * @return mixed - */ + /** + * Do the request to the Http Client + * + * @param $params + * @return mixed + * @throws \Adyen\AdyenException + */ public function request($params) { // convert to PHP Array if type is inputType is json if($this->_service->getClient()->getConfig()->getInputType() == 'json') { $params = json_decode($params, true); + if ($params === null && json_last_error() !== JSON_ERROR_NONE) { + $msg = 'The parameters in the request expect valid JSON but JSON error code found: ' . json_last_error(); + $this->_service->getClient()->getLogger()->error($msg); + throw new \Adyen\AdyenException($msg); + } } - // check if merchantAccount is setup in client and request is missing merchantAccount then add it - if(!isset($params['merchantAccount']) && $this->_service->getClient()->getConfig()->getMerchantAccount()) { - $params['merchantAccount'] = $this->_service->getClient()->getConfig()->getMerchantAccount(); - } + if (!is_array($params)) { + $msg = 'The parameter is not valid array'; + $this->_service->getClient()->getLogger()->error($msg); + throw new \Adyen\AdyenException($msg); + } + + $params = $this->addDefaultParametersToRequest($params); + + $params = $this->filterParams($params); $curlClient = $this->_service->getClient()->getHttpClient(); return $curlClient->requestJson($this->_service, $this->_endpoint, $params); } + /** + * @param $params + * @return mixed + * @throws \Adyen\AdyenException + */ public function requestPost($params) { // check if paramenters has a value @@ -50,4 +87,68 @@ public function requestPost($params) return $curlClient->requestPost($this->_service, $this->_endpoint, $params); } -} \ No newline at end of file + /** + * Fill expected but missing parameters with default data + * + * @param $params + * @return mixed + */ + private function addDefaultParametersToRequest($params) + { + // check if merchantAccount is setup in client and request is missing merchantAccount then add it + if(!isset($params['merchantAccount']) && $this->_service->getClient()->getConfig()->getMerchantAccount()) { + $params['merchantAccount'] = $this->_service->getClient()->getConfig()->getMerchantAccount(); + } + + // check if applicationInfo is set and has the adyenLibrary in it + if (!isset($params['applicationInfo']['adyenLibrary'])) { + $params['applicationInfo']['adyenLibrary']['name'] = $this->_service->getClient()->getLibraryName(); + $params['applicationInfo']['adyenLibrary']['version'] = $this->_service->getClient()->getLibraryVersion(); + } + + return $params; + } + + /** + * All the parameters that can be found in the _paramsToFilter array will be filtered out for the specific endpoint + * You can add multilevel filtering by defining associative arrays in the property + * If left empty no filtering is going to take place so all the parameters will be sent unfiltered towards the API + * + * @param array $params + * @return array $params + */ + private function filterParams($params) + { + if (empty($this->paramsToFilter)) { + return $params; + } + + return $this->iterateThroughArrayAndCheckParamsRecursive($params, $this->paramsToFilter); + } + + /** + * Recursive helper for the filterParams function filtering out always the specific level's parameters + * + * @param $params + * @param $paramsToFilter + * @return array + */ + private function iterateThroughArrayAndCheckParamsRecursive($params, $paramsToFilter) + { + foreach ($paramsToFilter as $key => $value) { + if (is_array($value)){ + if ($value) { + if (isset($params[$key])) { + $params[$key] = $this->iterateThroughArrayAndCheckParamsRecursive($params[$key], $value); + } + } + } else { + if (isset($params[$value])) { + unset($params[$value]); + } + } + } + + return $params; + } +} diff --git a/src/Adyen/Service/ResourceModel/Checkout/PaymentMethods.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentMethods.php index 6e0b8933a..b5575a966 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/PaymentMethods.php +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentMethods.php @@ -4,12 +4,28 @@ class PaymentMethods extends \Adyen\Service\AbstractCheckoutResource { - protected $_endpoint; + /** + * @var string + */ + protected $_endpoint; + /** + * Add parameters that you want to filter out from the params in the request + * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * + * @var array + */ + protected $paramsToFilter = array(); + + /** + * PaymentMethods constructor. + * + * @param \Adyen\Service $service + * @throws \Adyen\AdyenException + */ public function __construct($service) { $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutVersion() . '/paymentMethods'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->paramsToFilter); } - } diff --git a/src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php index 0de8c8885..006c436f7 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php @@ -4,11 +4,28 @@ class PaymentSession extends \Adyen\Service\AbstractCheckoutResource { - protected $_endpoint; + /** + * @var string + */ + protected $_endpoint; + /** + * Add parameters that you want to filter out from the params in the request + * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * + * @var array + */ + protected $paramsToFilter = array(); + + /** + * PaymentSession constructor. + * + * @param \Adyen\Service $service + * @throws \Adyen\AdyenException + */ public function __construct($service) { $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutVersion() . '/paymentSession'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->paramsToFilter); } -} \ No newline at end of file +} diff --git a/src/Adyen/Service/ResourceModel/Checkout/Payments.php b/src/Adyen/Service/ResourceModel/Checkout/Payments.php index b23713b3b..f36114c7e 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/Payments.php +++ b/src/Adyen/Service/ResourceModel/Checkout/Payments.php @@ -4,12 +4,28 @@ class Payments extends \Adyen\Service\AbstractCheckoutResource { + /** + * @var string + */ + protected $_endpoint; - protected $_endpoint; + /** + * Add parameters that you want to filter out from the params in the request + * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * + * @var array + */ + protected $paramsToFilter = array(); + /** + * Payments constructor. + * + * @param \Adyen\Service $service + * @throws \Adyen\AdyenException + */ public function __construct($service) { $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutVersion() . '/payments'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->paramsToFilter); } -} \ No newline at end of file +} diff --git a/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php index 97354a50b..09cbb8f54 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php @@ -4,12 +4,28 @@ class PaymentsDetails extends \Adyen\Service\AbstractCheckoutResource { - protected $_endpoint; + /** + * @var string + */ + protected $_endpoint; + /** + * Add parameters that you want to filter out from the params in the request + * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * + * @var array + */ + protected $paramsToFilter = array(); + + /** + * PaymentsDetails constructor. + * + * @param \Adyen\Service $service + * @throws \Adyen\AdyenException + */ public function __construct($service) { $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutVersion() . '/payments/details'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->paramsToFilter); } - } diff --git a/src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php index 04af85399..0c87948a2 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php @@ -4,12 +4,28 @@ class PaymentsResult extends \Adyen\Service\AbstractCheckoutResource { - protected $_endpoint; + /** + * @var string + */ + protected $_endpoint; + /** + * Add parameters that you want to filter out from the params in the request + * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * + * @var array + */ + protected $paramsToFilter = array(); + + /** + * PaymentsResult constructor. + * + * @param \Adyen\Service $service + * @throws \Adyen\AdyenException + */ public function __construct($service) { $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutVersion() . '/payments/result'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->paramsToFilter); } - } diff --git a/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php b/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php index 571244e82..0b8bdb823 100644 --- a/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php +++ b/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php @@ -4,12 +4,30 @@ class OriginKeys extends \Adyen\Service\AbstractCheckoutResource { + /** + * @var string + */ protected $_endpoint; + /** + * Add parameters that you want to filter out from the params in the request + * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * + * @var array + */ + protected $paramsToFilter = array( + "applicationInfo" + ); + + /** + * OriginKeys constructor. + * + * @param \Adyen\Sercvice $service + * @throws \Adyen\AdyenException + */ public function __construct($service) { $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutUtilityVersion() . '/originKeys'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->paramsToFilter); } - } diff --git a/src/Adyen/Service/ResourceModel/DirectoryLookup/Directory.php b/src/Adyen/Service/ResourceModel/DirectoryLookup/Directory.php index b139b2cf0..f8a852998 100644 --- a/src/Adyen/Service/ResourceModel/DirectoryLookup/Directory.php +++ b/src/Adyen/Service/ResourceModel/DirectoryLookup/Directory.php @@ -2,17 +2,33 @@ //https://test.adyen.com/hpp/directory.shtml - namespace Adyen\Service\ResourceModel\DirectoryLookup; class Directory extends \Adyen\Service\AbstractResource { + /** + * @var + */ protected $_endpoint; + /** + * Add parameters that you want to filter out from the params in the request + * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * + * @var array + */ + protected $paramsToFilter = array( + "applicationInfo" + ); + + /** + * Directory constructor. + * + * @param \Adyen\Service $service + */ public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpointDirectorylookup'); - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->paramsToFilter); } - -} \ No newline at end of file +} diff --git a/src/Adyen/Service/ResourceModel/Modification/AdjustAuthorisation.php b/src/Adyen/Service/ResourceModel/Modification/AdjustAuthorisation.php index 372595153..28f2b93e4 100644 --- a/src/Adyen/Service/ResourceModel/Modification/AdjustAuthorisation.php +++ b/src/Adyen/Service/ResourceModel/Modification/AdjustAuthorisation.php @@ -4,12 +4,27 @@ class AdjustAuthorisation extends \Adyen\Service\AbstractResource { - protected $_endpoint; + /** + * @var string + */ + protected $_endpoint; + /** + * Add parameters that you want to filter out from the params in the request + * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * + * @var array + */ + protected $paramsToFilter = array(); + + /** + * AdjustAuthorisation constructor. + * + * @param \Adyen\Service $service + */ public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint').'/pal/servlet/Payment/'.$service->getClient()->getApiVersion().'/adjustAuthorisation'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->paramsToFilter); } - -} \ No newline at end of file +} diff --git a/src/Adyen/Service/ResourceModel/Modification/Cancel.php b/src/Adyen/Service/ResourceModel/Modification/Cancel.php index 735444319..ac2bc77b1 100644 --- a/src/Adyen/Service/ResourceModel/Modification/Cancel.php +++ b/src/Adyen/Service/ResourceModel/Modification/Cancel.php @@ -4,12 +4,27 @@ class Cancel extends \Adyen\Service\AbstractResource { - protected $_endpoint; + /** + * @var string + */ + protected $_endpoint; - public function __construct($service) - { - $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payment/' . $service->getClient()->getApiVersion() . '/cancel'; - parent::__construct($service, $this->_endpoint); - } + /** + * Add parameters that you want to filter out from the params in the request + * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * + * @var array + */ + protected $paramsToFilter = array(); -} \ No newline at end of file + /** + * Cancel constructor. + * + * @param \Adyen\Service $service + */ + public function __construct($service) + { + $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payment/' . $service->getClient()->getApiVersion() . '/cancel'; + parent::__construct($service, $this->_endpoint, $this->paramsToFilter); + } +} diff --git a/src/Adyen/Service/ResourceModel/Modification/CancelOrRefund.php b/src/Adyen/Service/ResourceModel/Modification/CancelOrRefund.php index cf4c550b2..92f6d3b2a 100644 --- a/src/Adyen/Service/ResourceModel/Modification/CancelOrRefund.php +++ b/src/Adyen/Service/ResourceModel/Modification/CancelOrRefund.php @@ -4,12 +4,27 @@ class CancelOrRefund extends \Adyen\Service\AbstractResource { - protected $_endpoint; + /** + * @var string + */ + protected $_endpoint; + /** + * Add parameters that you want to filter out from the params in the request + * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * + * @var array + */ + protected $paramsToFilter = array(); + + /** + * CancelOrRefund constructor. + * + * @param \Adyen\Service $service + */ public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payment/'. $service->getClient()->getApiVersion() . '/cancelOrRefund'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->paramsToFilter); } - -} \ No newline at end of file +} diff --git a/src/Adyen/Service/ResourceModel/Modification/Capture.php b/src/Adyen/Service/ResourceModel/Modification/Capture.php index 5287d8906..8988520ea 100644 --- a/src/Adyen/Service/ResourceModel/Modification/Capture.php +++ b/src/Adyen/Service/ResourceModel/Modification/Capture.php @@ -4,12 +4,27 @@ class Capture extends \Adyen\Service\AbstractResource { - protected $_endpoint; + /** + * @var string + */ + protected $_endpoint; + /** + * Add parameters that you want to filter out from the params in the request + * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * + * @var array + */ + protected $paramsToFilter = array(); + + /** + * Capture constructor. + * + * @param \Adyen\Service $service + */ public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payment/' . $service->getClient()->getApiVersion() . '/capture'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->paramsToFilter); } - -} \ No newline at end of file +} diff --git a/src/Adyen/Service/ResourceModel/Modification/Refund.php b/src/Adyen/Service/ResourceModel/Modification/Refund.php index 95e91de85..ac6775dda 100644 --- a/src/Adyen/Service/ResourceModel/Modification/Refund.php +++ b/src/Adyen/Service/ResourceModel/Modification/Refund.php @@ -4,12 +4,27 @@ class Refund extends \Adyen\Service\AbstractResource { - protected $_endpoint; + /** + * @var string + */ + protected $_endpoint; + /** + * Add parameters that you want to filter out from the params in the request + * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * + * @var array + */ + protected $paramsToFilter = array(); + + /** + * Refund constructor. + * + * @param \Adyen\Service $service + */ public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payment/' . $service->getClient()->getApiVersion() . '/refund'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->paramsToFilter); } - -} \ No newline at end of file +} diff --git a/src/Adyen/Service/ResourceModel/Payment/Authorise.php b/src/Adyen/Service/ResourceModel/Payment/Authorise.php index 09d649eac..95f840780 100644 --- a/src/Adyen/Service/ResourceModel/Payment/Authorise.php +++ b/src/Adyen/Service/ResourceModel/Payment/Authorise.php @@ -4,12 +4,27 @@ class Authorise extends \Adyen\Service\AbstractResource { - protected $_endpoint; + /** + * @var string + */ + protected $_endpoint; + /** + * Add parameters that you want to filter out from the params in the request + * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * + * @var array + */ + protected $paramsToFilter = array(); + + /** + * Authorise constructor. + * + * @param \Adyen\Service $service + */ public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payment/' . $service->getClient()->getApiVersion() . '/authorise'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->paramsToFilter); } - -} \ No newline at end of file +} diff --git a/src/Adyen/Service/ResourceModel/Payment/Authorise3D.php b/src/Adyen/Service/ResourceModel/Payment/Authorise3D.php index 52d9fd103..74ca5b42b 100644 --- a/src/Adyen/Service/ResourceModel/Payment/Authorise3D.php +++ b/src/Adyen/Service/ResourceModel/Payment/Authorise3D.php @@ -4,12 +4,27 @@ class Authorise3D extends \Adyen\Service\AbstractResource { - protected $_endpoint; + /** + * @var string + */ + protected $_endpoint; + /** + * Add parameters that you want to filter out from the params in the request + * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * + * @var array + */ + protected $paramsToFilter = array(); + + /** + * Authorise3D constructor. + * + * @param \Adyen\Service $service + */ public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payment/' . $service->getClient()->getApiVersion() . '/authorise3d'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->paramsToFilter); } - -} \ No newline at end of file +} diff --git a/src/Adyen/Service/ResourceModel/Payment/TerminalCloudAPI.php b/src/Adyen/Service/ResourceModel/Payment/TerminalCloudAPI.php index 90b6095f9..9aac3625b 100644 --- a/src/Adyen/Service/ResourceModel/Payment/TerminalCloudAPI.php +++ b/src/Adyen/Service/ResourceModel/Payment/TerminalCloudAPI.php @@ -4,8 +4,25 @@ class TerminalCloudAPI extends \Adyen\Service\AbstractResource { - protected $_endpoint; + /** + * @var string + */ + protected $_endpoint; + /** + * Add parameters that you want to filter out from the params in the request + * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * + * @var array + */ + protected $paramsToFilter = array(); + + /** + * TerminalCloudAPI constructor. + * + * @param \Adyen\Service $service + * @param bool $asynchronous + */ public function __construct($service, $asynchronous) { if ($asynchronous) { @@ -13,7 +30,6 @@ public function __construct($service, $asynchronous) } else { $this->_endpoint = $service->getClient()->getConfig()->get('endpointTerminalCloud') . '/sync'; } - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->paramsToFilter); } - -} \ No newline at end of file +} diff --git a/src/Adyen/Service/ResourceModel/Payout/Confirm.php b/src/Adyen/Service/ResourceModel/Payout/Confirm.php index 6e3a87aad..07331797b 100644 --- a/src/Adyen/Service/ResourceModel/Payout/Confirm.php +++ b/src/Adyen/Service/ResourceModel/Payout/Confirm.php @@ -4,12 +4,29 @@ class Confirm extends \Adyen\Service\AbstractResource { + /** + * @var string + */ protected $_endpoint; + /** + * Add parameters that you want to filter out from the params in the request + * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * + * @var array + */ + protected $paramsToFilter = array( + "applicationInfo" + ); + + /** + * Confirm constructor. + * + * @param \Adyen\Service $service + */ public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/confirm'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->paramsToFilter); } - -} \ No newline at end of file +} diff --git a/src/Adyen/Service/ResourceModel/Payout/Decline.php b/src/Adyen/Service/ResourceModel/Payout/Decline.php index 1ed095d25..9e6985d15 100644 --- a/src/Adyen/Service/ResourceModel/Payout/Decline.php +++ b/src/Adyen/Service/ResourceModel/Payout/Decline.php @@ -4,12 +4,29 @@ class Decline extends \Adyen\Service\AbstractResource { + /** + * @var string + */ protected $_endpoint; + /** + * Add parameters that you want to filter out from the params in the request + * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * + * @var array + */ + protected $paramsToFilter = array( + "applicationInfo" + ); + + /** + * Decline constructor. + * + * @param \Adyen\Service $service + */ public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/decline'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->paramsToFilter); } - -} \ No newline at end of file +} diff --git a/src/Adyen/Service/ResourceModel/Payout/StoreDetailsAndSubmit.php b/src/Adyen/Service/ResourceModel/Payout/StoreDetailsAndSubmit.php index 7d2dcbc30..813c516f1 100644 --- a/src/Adyen/Service/ResourceModel/Payout/StoreDetailsAndSubmit.php +++ b/src/Adyen/Service/ResourceModel/Payout/StoreDetailsAndSubmit.php @@ -4,12 +4,29 @@ class StoreDetailsAndSubmit extends \Adyen\Service\AbstractResource { + /** + * @var string + */ protected $_endpoint; + /** + * Add parameters that you want to filter out from the params in the request + * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * + * @var array + */ + protected $paramsToFilter = array( + "applicationInfo" + ); + + /** + * StoreDetailsAndSubmit constructor. + * + * @param \Adyen\Service $service + */ public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/storeDetailAndSubmit'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->paramsToFilter); } - -} \ No newline at end of file +} diff --git a/src/Adyen/Service/ResourceModel/Payout/Submit.php b/src/Adyen/Service/ResourceModel/Payout/Submit.php index 0d1268292..97b3ef907 100644 --- a/src/Adyen/Service/ResourceModel/Payout/Submit.php +++ b/src/Adyen/Service/ResourceModel/Payout/Submit.php @@ -4,12 +4,29 @@ class Submit extends \Adyen\Service\AbstractResource { + /** + * @var string + */ protected $_endpoint; + /** + * Add parameters that you want to filter out from the params in the request + * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * + * @var array + */ + protected $paramsToFilter = array( + "applicationInfo" + ); + + /** + * Submit constructor. + * + * @param \Adyen\Service $service + */ public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/submit'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->paramsToFilter); } - -} \ No newline at end of file +} diff --git a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/ConfirmThirdParty.php b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/ConfirmThirdParty.php index 37e19251b..3b1b43f50 100644 --- a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/ConfirmThirdParty.php +++ b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/ConfirmThirdParty.php @@ -4,12 +4,29 @@ class ConfirmThirdParty extends \Adyen\Service\AbstractResource { + /** + * @var string + */ protected $_endpoint; + /** + * Add parameters that you want to filter out from the params in the request + * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * + * @var array + */ + protected $paramsToFilter = array( + "applicationInfo" + ); + + /** + * ConfirmThirdParty constructor. + * + * @param \Adyen\Service $service + */ public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/confirmThirdParty'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->paramsToFilter); } - -} \ No newline at end of file +} diff --git a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/DeclineThirdParty.php b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/DeclineThirdParty.php index 07f681c02..0bcf8d941 100644 --- a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/DeclineThirdParty.php +++ b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/DeclineThirdParty.php @@ -2,14 +2,33 @@ namespace Adyen\Service\ResourceModel\Payout\ThirdParty; +use Adyen\Service; + class DeclineThirdParty extends \Adyen\Service\AbstractResource { + /** + * @var string + */ protected $_endpoint; + /** + * Add parameters that you want to filter out from the params in the request + * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * + * @var array + */ + protected $paramsToFilter = array( + "applicationInfo" + ); + + /** + * DeclineThirdParty constructor. + * + * @param \Adyen|Service $service + */ public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/declineThirdParty'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->paramsToFilter); } - -} \ No newline at end of file +} diff --git a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetail.php b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetail.php index aced34bb4..05537ebfe 100644 --- a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetail.php +++ b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetail.php @@ -4,12 +4,29 @@ class StoreDetail extends \Adyen\Service\AbstractResource { + /** + * @var string + */ protected $_endpoint; + /** + * Add parameters that you want to filter out from the params in the request + * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * + * @var array + */ + protected $paramsToFilter = array( + "applicationInfo" + ); + + /** + * StoreDetail constructor. + * + * @param \Adyen\Service $service + */ public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/storeDetail'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->paramsToFilter); } - -} \ No newline at end of file +} diff --git a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetailsAndSubmitThirdParty.php b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetailsAndSubmitThirdParty.php index f7cb4f86f..4ad0588ae 100644 --- a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetailsAndSubmitThirdParty.php +++ b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetailsAndSubmitThirdParty.php @@ -4,12 +4,29 @@ class StoreDetailsAndSubmitThirdParty extends \Adyen\Service\AbstractResource { + /** + * @var string + */ protected $_endpoint; + /** + * Add parameters that you want to filter out from the params in the request + * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * + * @var array + */ + protected $paramsToFilter = array( + "applicationInfo" + ); + + /** + * StoreDetailsAndSubmitThirdParty constructor. + * + * @param \Adyen\Service $service + */ public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/storeDetailAndSubmitThirdParty'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->paramsToFilter); } - -} \ No newline at end of file +} diff --git a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/SubmitThirdParty.php b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/SubmitThirdParty.php index a49d5dcc2..acf77f702 100644 --- a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/SubmitThirdParty.php +++ b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/SubmitThirdParty.php @@ -4,12 +4,29 @@ class SubmitThirdParty extends \Adyen\Service\AbstractResource { + /** + * @var string + */ protected $_endpoint; + /** + * Add parameters that you want to filter out from the params in the request + * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * + * @var array + */ + protected $paramsToFilter = array( + "applicationInfo" + ); + + /** + * SubmitThirdParty constructor. + * + * @param \Adyen\Service $service + */ public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/submitThirdParty'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->paramsToFilter); } - -} \ No newline at end of file +} diff --git a/src/Adyen/Service/ResourceModel/Recurring/Disable.php b/src/Adyen/Service/ResourceModel/Recurring/Disable.php index 3d86256c6..0d826782b 100644 --- a/src/Adyen/Service/ResourceModel/Recurring/Disable.php +++ b/src/Adyen/Service/ResourceModel/Recurring/Disable.php @@ -4,10 +4,29 @@ class Disable extends \Adyen\Service\AbstractResource { + /** + * @var string + */ + protected $endpoint; + + /** + * Add parameters that you want to filter out from the params in the request + * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * + * @var array + */ + protected $paramsToFilter = array( + "applicationInfo" + ); + + /** + * Disable constructor. + * + * @param \Adyen\Service $service + */ public function __construct($service) { - $endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Recurring/' . $service->getClient()->getApiRecurringVersion() . '/disable'; - parent::__construct($service, $endpoint); + $this->endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Recurring/' . $service->getClient()->getApiRecurringVersion() . '/disable'; + parent::__construct($service, $this->endpoint, $this->paramsToFilter); } - -} \ No newline at end of file +} diff --git a/src/Adyen/Service/ResourceModel/Recurring/ListRecurringDetails.php b/src/Adyen/Service/ResourceModel/Recurring/ListRecurringDetails.php index 0b2d1910a..c7fd2a398 100644 --- a/src/Adyen/Service/ResourceModel/Recurring/ListRecurringDetails.php +++ b/src/Adyen/Service/ResourceModel/Recurring/ListRecurringDetails.php @@ -4,10 +4,29 @@ class ListRecurringDetails extends \Adyen\Service\AbstractResource { + /** + * @var string + */ + protected $endpoint; + + /** + * Add parameters that you want to filter out from the params in the request + * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * + * @var array + */ + protected $paramsToFilter = array( + "applicationInfo" + ); + + /** + * ListRecurringDetails constructor. + * + * @param \Adyen\Service $service + */ public function __construct($service) { - $endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Recurring/' . $service->getClient()->getApiRecurringVersion() . '/listRecurringDetails'; - parent::__construct($service, $endpoint); + $this->endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Recurring/' . $service->getClient()->getApiRecurringVersion() . '/listRecurringDetails'; + parent::__construct($service, $this->endpoint, $this->paramsToFilter); } - -} \ No newline at end of file +} diff --git a/tests/TestCase.php b/tests/TestCase.php index ccfc194d6..680fd16c8 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -56,6 +56,24 @@ protected function createClient() } } + /** + * Mock client object without configuring the config/test.ini + * + * @return \Adyen\Client + */ + protected function createClientWithoutTestIni() + { + try { + $client = new \Adyen\Client(); + $client->setApplicationName("My Test Application"); + $client->setEnvironment(\Adyen\Environment::TEST); + } catch (\Adyen\AdyenException $exception) { + $this->_skipTest($exception->getMessage()); + } + + return $client; + } + /** * Mock client for payout * @@ -241,4 +259,22 @@ public function validateApiPermission($e) } } + /** + * Get reflection class method set to public to make it testable + * + * @param string $class full path + * @param string $name + * @return mixed + */ + protected function getMethod($class, $name) { + try { + $class = new \ReflectionClass($class); + } catch (\ReflectionException $exception) { + $this->_skipTest($exception->getMessage()); + } + + $method = $class->getMethod($name); + $method->setAccessible(true); + return $method; + } } diff --git a/tests/Unit/AbstractResourceTest.php b/tests/Unit/AbstractResourceTest.php new file mode 100644 index 000000000..a38ce4bde --- /dev/null +++ b/tests/Unit/AbstractResourceTest.php @@ -0,0 +1,238 @@ +mockedClient = $this->createClientWithoutTestIni(); + } + + /** + * In case of empty $paramsToFilter array the function should not filter the $params array + * + * @author attilak + * @covers \Adyen\Service\AbstractResource::filterParams + */ + public function testFilterParamsNoFilter() + { + $paramsToFilter = array(); + + $params = array( + "topLevelKey" => array( + "secondLevelKey" => array( + "thirdLevelKey" + ), + "secondLevelKey2" + ), + "topLevelKey2" + ); + + $expectedParamsAfterFilter = array( + "topLevelKey" => array( + "secondLevelKey" => array( + "thirdLevelKey" + ), + "secondLevelKey2" + ), + "topLevelKey2" + ); + + // Mock abstract class with mocked client and $paramsToFilter parameters + $mockedClass = $this->getMockForAbstractClass($this->className, array((new \Adyen\Service($this->mockedClient)), "", $paramsToFilter)); + + // Get private method as testable public method + $method = $this->getMethod($this->className, "filterParams"); + + // Test against function + $result = $method->invokeArgs($mockedClass, array($params)); + $this->assertSame($expectedParamsAfterFilter, $result); + } + + /** + * Test top level filtering + * The test supposed to filter out only the keys (and optionally their values) if they are present in the $paramsToFilter + * variable + * + * @author attilak + * @covers \Adyen\Service\AbstractResource::filterParams + */ + public function testFilterParamsFilterTopLevel() + { + $paramsToFilter = array( + "topLevelKey2" + ); + + $params = array( + "topLevelKey" => array( + "secondLevelKey" => array( + "thirdLevelKey" => 'text', + "thirdLevelKey2" => 'text2' + ), + "secondLevelKey2" => 'text2' + ), + "topLevelKey2" => 'text2' + ); + + $expectedParamsAfterFilter = array( + "topLevelKey" => array( + "secondLevelKey" => array( + "thirdLevelKey" => 'text', + "thirdLevelKey2" => 'text2' + ), + "secondLevelKey2" => 'text2' + ) + ); + + // Mock abstract class with mocked client and paramsToSend parameters + $mockedClass = $this->getMockForAbstractClass($this->className, array((new \Adyen\Service($this->mockedClient)), "", $paramsToFilter)); + + // Get private method as testable public method + $method = $this->getMethod($this->className, "filterParams"); + + // Test against function + $result = $method->invokeArgs($mockedClass, array($params)); + $this->assertSame($expectedParamsAfterFilter, $result); + } + + /** + * Test multilevel filtering + * The test supposed to filter out only the keys (and optionally their values) if they are present in the $paramsToFilter + * variable + * + * @author attilak + * @covers \Adyen\Service\AbstractResource::filterParams + */ + public function testFilterParamsFilterMultiLevel() + { + $paramsToFilter = array( + "topLevelKey" => array( + "secondLevelKey" => array( + "thirdLevelKey2" + ) + ) + ); + + $params = array( + "topLevelKey" => array( + "secondLevelKey" => array( + "thirdLevelKey" => 'text', + "thirdLevelKey2" => 'text2' + ), + "secondLevelKey2" => 'text2' + ), + "topLevelKey2" => 'text2' + ); + + $expectedParamsAfterFilter = array( + "topLevelKey" => array( + "secondLevelKey" => array( + "thirdLevelKey" => 'text' + ), + "secondLevelKey2" => 'text2' + ), + "topLevelKey2" => 'text2' + ); + + // Mock abstract class with mocked client and paramsToSend parameters + $mockedClass = $this->getMockForAbstractClass($this->className, array((new \Adyen\Service($this->mockedClient)), "", $paramsToFilter)); + + // Get private method as testable public method + $method = $this->getMethod($this->className, "filterParams"); + + // Test against function + $result = $method->invokeArgs($mockedClass, array($params)); + $this->assertSame($expectedParamsAfterFilter, $result); + } + + /** + * The function should not modify the existing parameters to the default ones + * + * @author attilak + * @covers \Adyen\Service\AbstractResource::addDefaultParametersToRequest + */ + public function testAddDefaultParametersToRequestWithExistingKey() + { + $params = array( + "topLevelKey" => array( + "secondLevelKey" => array( + "thirdLevelKey" => 'text' + ), + "secondLevelKey2" => 'text2' + ), + "merchantAccount" => 'already existing param', + "applicationInfo" => array( + "adyenLibrary" => "already existing param" + ) + ); + + $expectedParamsAfterFilter = array( + "topLevelKey" => array( + "secondLevelKey" => array( + "thirdLevelKey" => 'text' + ), + "secondLevelKey2" => 'text2' + ), + "merchantAccount" => 'already existing param', + "applicationInfo" => array( + "adyenLibrary" => "already existing param" + ) + ); + + // Mock abstract class with mocked client and paramsToSend parameters + $mockedClass = $this->getMockForAbstractClass($this->className, array((new \Adyen\Service($this->mockedClient)), "")); + + // Get private method as testable public method + $method = $this->getMethod($this->className, "addDefaultParametersToRequest"); + + // Test against function + $result = $method->invokeArgs($mockedClass, array($params)); + $this->assertSame($expectedParamsAfterFilter, $result); + } + + /** + * The function should add the non existing parameters to the array + * + * @author attilak + * @covers \Adyen\Service\AbstractResource::addDefaultParametersToRequest + */ + public function testAddDefaultParametersToRequestWithNonExistingKey() + { + $params = array( + "topLevelKey" => array( + "secondLevelKey" => array( + "thirdLevelKey" => 'text' + ), + "secondLevelKey2" => 'text2' + ), + "applicationInfo" => array() + ); + + // Mock abstract class with mocked client and paramsToSend parameters + $mockedClass = $this->getMockForAbstractClass($this->className, array((new \Adyen\Service($this->mockedClient)), "")); + + // Get private method as testable public method + $method = $this->getMethod($this->className, "addDefaultParametersToRequest"); + + // Test against function + $result = $method->invokeArgs($mockedClass, array($params)); + + $this->assertArrayHasKey("adyenLibrary", $result["applicationInfo"]); + } +} From 06897b83c773ce16198950ff9b7064f54ab8ca9d Mon Sep 17 00:00:00 2001 From: attilak Date: Wed, 10 Oct 2018 17:54:40 +0200 Subject: [PATCH 02/10] Add boolean check if applicationInfo is necessary ot not in the request If the applicationInfo should be in the request then fill the default data --- src/Adyen/Service/AbstractResource.php | 64 ++--- .../ResourceModel/Checkout/PaymentMethods.php | 9 +- .../ResourceModel/Checkout/PaymentSession.php | 9 +- .../ResourceModel/Checkout/Payments.php | 10 +- .../Checkout/PaymentsDetails.php | 10 +- .../ResourceModel/Checkout/PaymentsResult.php | 10 +- .../CheckoutUtility/OriginKeys.php | 13 +- .../DirectoryLookup/Directory.php | 11 +- .../Modification/AdjustAuthorisation.php | 10 +- .../ResourceModel/Modification/Cancel.php | 10 +- .../Modification/CancelOrRefund.php | 10 +- .../ResourceModel/Modification/Capture.php | 10 +- .../ResourceModel/Modification/Refund.php | 10 +- .../ResourceModel/Payment/Authorise.php | 10 +- .../ResourceModel/Payment/Authorise3D.php | 10 +- .../Payment/TerminalCloudAPI.php | 9 +- .../Service/ResourceModel/Payout/Confirm.php | 11 +- .../Service/ResourceModel/Payout/Decline.php | 11 +- .../Payout/StoreDetailsAndSubmit.php | 11 +- .../Service/ResourceModel/Payout/Submit.php | 11 +- .../Payout/ThirdParty/ConfirmThirdParty.php | 11 +- .../Payout/ThirdParty/DeclineThirdParty.php | 13 +- .../Payout/ThirdParty/StoreDetail.php | 11 +- .../StoreDetailsAndSubmitThirdParty.php | 11 +- .../Payout/ThirdParty/SubmitThirdParty.php | 11 +- .../ResourceModel/Recurring/Disable.php | 11 +- .../Recurring/ListRecurringDetails.php | 11 +- tests/Unit/AbstractResourceTest.php | 238 ------------------ 28 files changed, 94 insertions(+), 482 deletions(-) delete mode 100644 tests/Unit/AbstractResourceTest.php diff --git a/src/Adyen/Service/AbstractResource.php b/src/Adyen/Service/AbstractResource.php index 5c416e8b3..96e59d6f0 100644 --- a/src/Adyen/Service/AbstractResource.php +++ b/src/Adyen/Service/AbstractResource.php @@ -2,8 +2,6 @@ namespace Adyen\Service; -use Adyen\AdyenException; - class AbstractResource { /** @@ -17,22 +15,22 @@ class AbstractResource protected $_endpoint; /** - * @var array + * @var bool */ - protected $paramsToFilter; + protected $removeApplicationInfoFromRequest; /** * AbstractResource constructor. * * @param \Adyen\Service $service * @param $endpoint - * @param array $paramsToFilter + * @param bool $removeApplicationInfoFromRequest */ - public function __construct(\Adyen\Service $service, $endpoint, $paramsToFilter = array()) + public function __construct(\Adyen\Service $service, $endpoint, $removeApplicationInfoFromRequest = false) { $this->_service = $service; $this->_endpoint = $endpoint; - $this->paramsToFilter = $paramsToFilter; + $this->removeApplicationInfoFromRequest = $removeApplicationInfoFromRequest; } /** @@ -63,7 +61,7 @@ public function request($params) $params = $this->addDefaultParametersToRequest($params); - $params = $this->filterParams($params); + $params = $this->handleApplicationInfoInRequest($params); $curlClient = $this->_service->getClient()->getHttpClient(); return $curlClient->requestJson($this->_service, $this->_endpoint, $params); @@ -100,53 +98,27 @@ private function addDefaultParametersToRequest($params) $params['merchantAccount'] = $this->_service->getClient()->getConfig()->getMerchantAccount(); } - // check if applicationInfo is set and has the adyenLibrary in it - if (!isset($params['applicationInfo']['adyenLibrary'])) { - $params['applicationInfo']['adyenLibrary']['name'] = $this->_service->getClient()->getLibraryName(); - $params['applicationInfo']['adyenLibrary']['version'] = $this->_service->getClient()->getLibraryVersion(); - } - return $params; } /** - * All the parameters that can be found in the _paramsToFilter array will be filtered out for the specific endpoint - * You can add multilevel filtering by defining associative arrays in the property - * If left empty no filtering is going to take place so all the parameters will be sent unfiltered towards the API - * - * @param array $params - * @return array $params - */ - private function filterParams($params) - { - if (empty($this->paramsToFilter)) { - return $params; - } - - return $this->iterateThroughArrayAndCheckParamsRecursive($params, $this->paramsToFilter); - } - - /** - * Recursive helper for the filterParams function filtering out always the specific level's parameters + * If removeApplicationInfoFromRequest is true then it removes unnecessary applicationInfo from request + * otherwise sets the default values * * @param $params - * @param $paramsToFilter - * @return array + * @return mixed */ - private function iterateThroughArrayAndCheckParamsRecursive($params, $paramsToFilter) + private function handleApplicationInfoInRequest($params) { - foreach ($paramsToFilter as $key => $value) { - if (is_array($value)){ - if ($value) { - if (isset($params[$key])) { - $params[$key] = $this->iterateThroughArrayAndCheckParamsRecursive($params[$key], $value); - } - } - } else { - if (isset($params[$value])) { - unset($params[$value]); - } + // remove if exists + if ($this->removeApplicationInfoFromRequest) { + if (isset($params['applicationInfo'])) { + unset($params['applicationInfo']); } + } else { + // add/overwrite applicationInfo adyenLibrary even if it's already set + $params['applicationInfo']['adyenLibrary']['name'] = $this->_service->getClient()->getLibraryName(); + $params['applicationInfo']['adyenLibrary']['version'] = $this->_service->getClient()->getLibraryVersion(); } return $params; diff --git a/src/Adyen/Service/ResourceModel/Checkout/PaymentMethods.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentMethods.php index b5575a966..55de358c5 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/PaymentMethods.php +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentMethods.php @@ -10,12 +10,11 @@ class PaymentMethods extends \Adyen\Service\AbstractCheckoutResource protected $_endpoint; /** - * Add parameters that you want to filter out from the params in the request - * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * Remove applicationInfo key from the request parameters * - * @var array + * @var bool */ - protected $paramsToFilter = array(); + protected $removeApplicationInfoFromRequest = true; /** * PaymentMethods constructor. @@ -26,6 +25,6 @@ class PaymentMethods extends \Adyen\Service\AbstractCheckoutResource public function __construct($service) { $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutVersion() . '/paymentMethods'; - parent::__construct($service, $this->_endpoint, $this->paramsToFilter); + parent::__construct($service, $this->_endpoint, $this->removeApplicationInfoFromRequest); } } diff --git a/src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php index 006c436f7..eaeb292f2 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php @@ -10,12 +10,11 @@ class PaymentSession extends \Adyen\Service\AbstractCheckoutResource protected $_endpoint; /** - * Add parameters that you want to filter out from the params in the request - * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * Remove applicationInfo key from the request parameters * - * @var array + * @var bool */ - protected $paramsToFilter = array(); + protected $removeApplicationInfoFromRequest = true; /** * PaymentSession constructor. @@ -26,6 +25,6 @@ class PaymentSession extends \Adyen\Service\AbstractCheckoutResource public function __construct($service) { $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutVersion() . '/paymentSession'; - parent::__construct($service, $this->_endpoint, $this->paramsToFilter); + parent::__construct($service, $this->_endpoint, $this->removeApplicationInfoFromRequest); } } diff --git a/src/Adyen/Service/ResourceModel/Checkout/Payments.php b/src/Adyen/Service/ResourceModel/Checkout/Payments.php index f36114c7e..059a9d693 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/Payments.php +++ b/src/Adyen/Service/ResourceModel/Checkout/Payments.php @@ -9,14 +9,6 @@ class Payments extends \Adyen\Service\AbstractCheckoutResource */ protected $_endpoint; - /** - * Add parameters that you want to filter out from the params in the request - * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block - * - * @var array - */ - protected $paramsToFilter = array(); - /** * Payments constructor. * @@ -26,6 +18,6 @@ class Payments extends \Adyen\Service\AbstractCheckoutResource public function __construct($service) { $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutVersion() . '/payments'; - parent::__construct($service, $this->_endpoint, $this->paramsToFilter); + parent::__construct($service, $this->_endpoint); } } diff --git a/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php index 09cbb8f54..482c24dc5 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php @@ -9,14 +9,6 @@ class PaymentsDetails extends \Adyen\Service\AbstractCheckoutResource */ protected $_endpoint; - /** - * Add parameters that you want to filter out from the params in the request - * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block - * - * @var array - */ - protected $paramsToFilter = array(); - /** * PaymentsDetails constructor. * @@ -26,6 +18,6 @@ class PaymentsDetails extends \Adyen\Service\AbstractCheckoutResource public function __construct($service) { $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutVersion() . '/payments/details'; - parent::__construct($service, $this->_endpoint, $this->paramsToFilter); + parent::__construct($service, $this->_endpoint); } } diff --git a/src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php index 0c87948a2..51cc7c808 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php @@ -9,14 +9,6 @@ class PaymentsResult extends \Adyen\Service\AbstractCheckoutResource */ protected $_endpoint; - /** - * Add parameters that you want to filter out from the params in the request - * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block - * - * @var array - */ - protected $paramsToFilter = array(); - /** * PaymentsResult constructor. * @@ -26,6 +18,6 @@ class PaymentsResult extends \Adyen\Service\AbstractCheckoutResource public function __construct($service) { $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutVersion() . '/payments/result'; - parent::__construct($service, $this->_endpoint, $this->paramsToFilter); + parent::__construct($service, $this->_endpoint); } } diff --git a/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php b/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php index 0b8bdb823..72fedacf5 100644 --- a/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php +++ b/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php @@ -10,24 +10,21 @@ class OriginKeys extends \Adyen\Service\AbstractCheckoutResource protected $_endpoint; /** - * Add parameters that you want to filter out from the params in the request - * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * Remove applicationInfo key from the request parameters * - * @var array + * @var bool */ - protected $paramsToFilter = array( - "applicationInfo" - ); + protected $removeApplicationInfoFromRequest = true; /** * OriginKeys constructor. * - * @param \Adyen\Sercvice $service + * @param \Adyen\Service $service * @throws \Adyen\AdyenException */ public function __construct($service) { $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutUtilityVersion() . '/originKeys'; - parent::__construct($service, $this->_endpoint, $this->paramsToFilter); + parent::__construct($service, $this->_endpoint, $this->removeApplicationInfoFromRequest); } } diff --git a/src/Adyen/Service/ResourceModel/DirectoryLookup/Directory.php b/src/Adyen/Service/ResourceModel/DirectoryLookup/Directory.php index f8a852998..1a03729c2 100644 --- a/src/Adyen/Service/ResourceModel/DirectoryLookup/Directory.php +++ b/src/Adyen/Service/ResourceModel/DirectoryLookup/Directory.php @@ -12,14 +12,11 @@ class Directory extends \Adyen\Service\AbstractResource protected $_endpoint; /** - * Add parameters that you want to filter out from the params in the request - * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * Remove applicationInfo key from the request parameters * - * @var array + * @var bool */ - protected $paramsToFilter = array( - "applicationInfo" - ); + protected $removeApplicationInfoFromRequest = true; /** * Directory constructor. @@ -29,6 +26,6 @@ class Directory extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpointDirectorylookup'); - parent::__construct($service, $this->_endpoint, $this->paramsToFilter); + parent::__construct($service, $this->_endpoint, $this->removeApplicationInfoFromRequest); } } diff --git a/src/Adyen/Service/ResourceModel/Modification/AdjustAuthorisation.php b/src/Adyen/Service/ResourceModel/Modification/AdjustAuthorisation.php index 28f2b93e4..8ab70bf43 100644 --- a/src/Adyen/Service/ResourceModel/Modification/AdjustAuthorisation.php +++ b/src/Adyen/Service/ResourceModel/Modification/AdjustAuthorisation.php @@ -9,14 +9,6 @@ class AdjustAuthorisation extends \Adyen\Service\AbstractResource */ protected $_endpoint; - /** - * Add parameters that you want to filter out from the params in the request - * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block - * - * @var array - */ - protected $paramsToFilter = array(); - /** * AdjustAuthorisation constructor. * @@ -25,6 +17,6 @@ class AdjustAuthorisation extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint').'/pal/servlet/Payment/'.$service->getClient()->getApiVersion().'/adjustAuthorisation'; - parent::__construct($service, $this->_endpoint, $this->paramsToFilter); + parent::__construct($service, $this->_endpoint); } } diff --git a/src/Adyen/Service/ResourceModel/Modification/Cancel.php b/src/Adyen/Service/ResourceModel/Modification/Cancel.php index ac2bc77b1..79fcab0a8 100644 --- a/src/Adyen/Service/ResourceModel/Modification/Cancel.php +++ b/src/Adyen/Service/ResourceModel/Modification/Cancel.php @@ -9,14 +9,6 @@ class Cancel extends \Adyen\Service\AbstractResource */ protected $_endpoint; - /** - * Add parameters that you want to filter out from the params in the request - * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block - * - * @var array - */ - protected $paramsToFilter = array(); - /** * Cancel constructor. * @@ -25,6 +17,6 @@ class Cancel extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payment/' . $service->getClient()->getApiVersion() . '/cancel'; - parent::__construct($service, $this->_endpoint, $this->paramsToFilter); + parent::__construct($service, $this->_endpoint); } } diff --git a/src/Adyen/Service/ResourceModel/Modification/CancelOrRefund.php b/src/Adyen/Service/ResourceModel/Modification/CancelOrRefund.php index 92f6d3b2a..fcb025b91 100644 --- a/src/Adyen/Service/ResourceModel/Modification/CancelOrRefund.php +++ b/src/Adyen/Service/ResourceModel/Modification/CancelOrRefund.php @@ -9,14 +9,6 @@ class CancelOrRefund extends \Adyen\Service\AbstractResource */ protected $_endpoint; - /** - * Add parameters that you want to filter out from the params in the request - * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block - * - * @var array - */ - protected $paramsToFilter = array(); - /** * CancelOrRefund constructor. * @@ -25,6 +17,6 @@ class CancelOrRefund extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payment/'. $service->getClient()->getApiVersion() . '/cancelOrRefund'; - parent::__construct($service, $this->_endpoint, $this->paramsToFilter); + parent::__construct($service, $this->_endpoint); } } diff --git a/src/Adyen/Service/ResourceModel/Modification/Capture.php b/src/Adyen/Service/ResourceModel/Modification/Capture.php index 8988520ea..d02f81397 100644 --- a/src/Adyen/Service/ResourceModel/Modification/Capture.php +++ b/src/Adyen/Service/ResourceModel/Modification/Capture.php @@ -9,14 +9,6 @@ class Capture extends \Adyen\Service\AbstractResource */ protected $_endpoint; - /** - * Add parameters that you want to filter out from the params in the request - * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block - * - * @var array - */ - protected $paramsToFilter = array(); - /** * Capture constructor. * @@ -25,6 +17,6 @@ class Capture extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payment/' . $service->getClient()->getApiVersion() . '/capture'; - parent::__construct($service, $this->_endpoint, $this->paramsToFilter); + parent::__construct($service, $this->_endpoint); } } diff --git a/src/Adyen/Service/ResourceModel/Modification/Refund.php b/src/Adyen/Service/ResourceModel/Modification/Refund.php index ac6775dda..166f274bc 100644 --- a/src/Adyen/Service/ResourceModel/Modification/Refund.php +++ b/src/Adyen/Service/ResourceModel/Modification/Refund.php @@ -9,14 +9,6 @@ class Refund extends \Adyen\Service\AbstractResource */ protected $_endpoint; - /** - * Add parameters that you want to filter out from the params in the request - * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block - * - * @var array - */ - protected $paramsToFilter = array(); - /** * Refund constructor. * @@ -25,6 +17,6 @@ class Refund extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payment/' . $service->getClient()->getApiVersion() . '/refund'; - parent::__construct($service, $this->_endpoint, $this->paramsToFilter); + parent::__construct($service, $this->_endpoint); } } diff --git a/src/Adyen/Service/ResourceModel/Payment/Authorise.php b/src/Adyen/Service/ResourceModel/Payment/Authorise.php index 95f840780..a6d8245e7 100644 --- a/src/Adyen/Service/ResourceModel/Payment/Authorise.php +++ b/src/Adyen/Service/ResourceModel/Payment/Authorise.php @@ -9,14 +9,6 @@ class Authorise extends \Adyen\Service\AbstractResource */ protected $_endpoint; - /** - * Add parameters that you want to filter out from the params in the request - * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block - * - * @var array - */ - protected $paramsToFilter = array(); - /** * Authorise constructor. * @@ -25,6 +17,6 @@ class Authorise extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payment/' . $service->getClient()->getApiVersion() . '/authorise'; - parent::__construct($service, $this->_endpoint, $this->paramsToFilter); + parent::__construct($service, $this->_endpoint); } } diff --git a/src/Adyen/Service/ResourceModel/Payment/Authorise3D.php b/src/Adyen/Service/ResourceModel/Payment/Authorise3D.php index 74ca5b42b..a67752fc1 100644 --- a/src/Adyen/Service/ResourceModel/Payment/Authorise3D.php +++ b/src/Adyen/Service/ResourceModel/Payment/Authorise3D.php @@ -9,14 +9,6 @@ class Authorise3D extends \Adyen\Service\AbstractResource */ protected $_endpoint; - /** - * Add parameters that you want to filter out from the params in the request - * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block - * - * @var array - */ - protected $paramsToFilter = array(); - /** * Authorise3D constructor. * @@ -25,6 +17,6 @@ class Authorise3D extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payment/' . $service->getClient()->getApiVersion() . '/authorise3d'; - parent::__construct($service, $this->_endpoint, $this->paramsToFilter); + parent::__construct($service, $this->_endpoint); } } diff --git a/src/Adyen/Service/ResourceModel/Payment/TerminalCloudAPI.php b/src/Adyen/Service/ResourceModel/Payment/TerminalCloudAPI.php index 9aac3625b..63acfb99f 100644 --- a/src/Adyen/Service/ResourceModel/Payment/TerminalCloudAPI.php +++ b/src/Adyen/Service/ResourceModel/Payment/TerminalCloudAPI.php @@ -10,12 +10,11 @@ class TerminalCloudAPI extends \Adyen\Service\AbstractResource protected $_endpoint; /** - * Add parameters that you want to filter out from the params in the request - * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * Remove applicationInfo key from the request parameters * - * @var array + * @var bool */ - protected $paramsToFilter = array(); + protected $removeApplicationInfoFromRequest = true; /** * TerminalCloudAPI constructor. @@ -30,6 +29,6 @@ public function __construct($service, $asynchronous) } else { $this->_endpoint = $service->getClient()->getConfig()->get('endpointTerminalCloud') . '/sync'; } - parent::__construct($service, $this->_endpoint, $this->paramsToFilter); + parent::__construct($service, $this->_endpoint, $this->removeApplicationInfoFromRequest); } } diff --git a/src/Adyen/Service/ResourceModel/Payout/Confirm.php b/src/Adyen/Service/ResourceModel/Payout/Confirm.php index 07331797b..3f74a01cd 100644 --- a/src/Adyen/Service/ResourceModel/Payout/Confirm.php +++ b/src/Adyen/Service/ResourceModel/Payout/Confirm.php @@ -10,14 +10,11 @@ class Confirm extends \Adyen\Service\AbstractResource protected $_endpoint; /** - * Add parameters that you want to filter out from the params in the request - * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * Remove applicationInfo key from the request parameters * - * @var array + * @var bool */ - protected $paramsToFilter = array( - "applicationInfo" - ); + protected $removeApplicationInfoFromRequest = true; /** * Confirm constructor. @@ -27,6 +24,6 @@ class Confirm extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/confirm'; - parent::__construct($service, $this->_endpoint, $this->paramsToFilter); + parent::__construct($service, $this->_endpoint, $this->removeApplicationInfoFromRequest); } } diff --git a/src/Adyen/Service/ResourceModel/Payout/Decline.php b/src/Adyen/Service/ResourceModel/Payout/Decline.php index 9e6985d15..258a5a78d 100644 --- a/src/Adyen/Service/ResourceModel/Payout/Decline.php +++ b/src/Adyen/Service/ResourceModel/Payout/Decline.php @@ -10,14 +10,11 @@ class Decline extends \Adyen\Service\AbstractResource protected $_endpoint; /** - * Add parameters that you want to filter out from the params in the request - * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * Remove applicationInfo key from the request parameters * - * @var array + * @var bool */ - protected $paramsToFilter = array( - "applicationInfo" - ); + protected $removeApplicationInfoFromRequest = true; /** * Decline constructor. @@ -27,6 +24,6 @@ class Decline extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/decline'; - parent::__construct($service, $this->_endpoint, $this->paramsToFilter); + parent::__construct($service, $this->_endpoint, $this->removeApplicationInfoFromRequest); } } diff --git a/src/Adyen/Service/ResourceModel/Payout/StoreDetailsAndSubmit.php b/src/Adyen/Service/ResourceModel/Payout/StoreDetailsAndSubmit.php index 813c516f1..0171a98b3 100644 --- a/src/Adyen/Service/ResourceModel/Payout/StoreDetailsAndSubmit.php +++ b/src/Adyen/Service/ResourceModel/Payout/StoreDetailsAndSubmit.php @@ -10,14 +10,11 @@ class StoreDetailsAndSubmit extends \Adyen\Service\AbstractResource protected $_endpoint; /** - * Add parameters that you want to filter out from the params in the request - * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * Remove applicationInfo key from the request parameters * - * @var array + * @var bool */ - protected $paramsToFilter = array( - "applicationInfo" - ); + protected $removeApplicationInfoFromRequest = true; /** * StoreDetailsAndSubmit constructor. @@ -27,6 +24,6 @@ class StoreDetailsAndSubmit extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/storeDetailAndSubmit'; - parent::__construct($service, $this->_endpoint, $this->paramsToFilter); + parent::__construct($service, $this->_endpoint, $this->removeApplicationInfoFromRequest); } } diff --git a/src/Adyen/Service/ResourceModel/Payout/Submit.php b/src/Adyen/Service/ResourceModel/Payout/Submit.php index 97b3ef907..22e78ce9c 100644 --- a/src/Adyen/Service/ResourceModel/Payout/Submit.php +++ b/src/Adyen/Service/ResourceModel/Payout/Submit.php @@ -10,14 +10,11 @@ class Submit extends \Adyen\Service\AbstractResource protected $_endpoint; /** - * Add parameters that you want to filter out from the params in the request - * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * Remove applicationInfo key from the request parameters * - * @var array + * @var bool */ - protected $paramsToFilter = array( - "applicationInfo" - ); + protected $removeApplicationInfoFromRequest = true; /** * Submit constructor. @@ -27,6 +24,6 @@ class Submit extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/submit'; - parent::__construct($service, $this->_endpoint, $this->paramsToFilter); + parent::__construct($service, $this->_endpoint, $this->removeApplicationInfoFromRequest); } } diff --git a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/ConfirmThirdParty.php b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/ConfirmThirdParty.php index 3b1b43f50..c62141bd7 100644 --- a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/ConfirmThirdParty.php +++ b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/ConfirmThirdParty.php @@ -10,14 +10,11 @@ class ConfirmThirdParty extends \Adyen\Service\AbstractResource protected $_endpoint; /** - * Add parameters that you want to filter out from the params in the request - * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * Remove applicationInfo key from the request parameters * - * @var array + * @var bool */ - protected $paramsToFilter = array( - "applicationInfo" - ); + protected $removeApplicationInfoFromRequest = true; /** * ConfirmThirdParty constructor. @@ -27,6 +24,6 @@ class ConfirmThirdParty extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/confirmThirdParty'; - parent::__construct($service, $this->_endpoint, $this->paramsToFilter); + parent::__construct($service, $this->_endpoint, $this->removeApplicationInfoFromRequest); } } diff --git a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/DeclineThirdParty.php b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/DeclineThirdParty.php index 0bcf8d941..61478a427 100644 --- a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/DeclineThirdParty.php +++ b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/DeclineThirdParty.php @@ -12,23 +12,20 @@ class DeclineThirdParty extends \Adyen\Service\AbstractResource protected $_endpoint; /** - * Add parameters that you want to filter out from the params in the request - * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * Remove applicationInfo key from the request parameters * - * @var array + * @var bool */ - protected $paramsToFilter = array( - "applicationInfo" - ); + protected $removeApplicationInfoFromRequest = true; /** * DeclineThirdParty constructor. * - * @param \Adyen|Service $service + * @param \Adyen\Service $service */ public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/declineThirdParty'; - parent::__construct($service, $this->_endpoint, $this->paramsToFilter); + parent::__construct($service, $this->_endpoint, $this->removeApplicationInfoFromRequest); } } diff --git a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetail.php b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetail.php index 05537ebfe..d9710c5ca 100644 --- a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetail.php +++ b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetail.php @@ -10,14 +10,11 @@ class StoreDetail extends \Adyen\Service\AbstractResource protected $_endpoint; /** - * Add parameters that you want to filter out from the params in the request - * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * Remove applicationInfo key from the request parameters * - * @var array + * @var bool */ - protected $paramsToFilter = array( - "applicationInfo" - ); + protected $removeApplicationInfoFromRequest = true; /** * StoreDetail constructor. @@ -27,6 +24,6 @@ class StoreDetail extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/storeDetail'; - parent::__construct($service, $this->_endpoint, $this->paramsToFilter); + parent::__construct($service, $this->_endpoint, $this->removeApplicationInfoFromRequest); } } diff --git a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetailsAndSubmitThirdParty.php b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetailsAndSubmitThirdParty.php index 4ad0588ae..e2f92941f 100644 --- a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetailsAndSubmitThirdParty.php +++ b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetailsAndSubmitThirdParty.php @@ -10,14 +10,11 @@ class StoreDetailsAndSubmitThirdParty extends \Adyen\Service\AbstractResource protected $_endpoint; /** - * Add parameters that you want to filter out from the params in the request - * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * Remove applicationInfo key from the request parameters * - * @var array + * @var bool */ - protected $paramsToFilter = array( - "applicationInfo" - ); + protected $removeApplicationInfoFromRequest = true; /** * StoreDetailsAndSubmitThirdParty constructor. @@ -27,6 +24,6 @@ class StoreDetailsAndSubmitThirdParty extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/storeDetailAndSubmitThirdParty'; - parent::__construct($service, $this->_endpoint, $this->paramsToFilter); + parent::__construct($service, $this->_endpoint, $this->removeApplicationInfoFromRequest); } } diff --git a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/SubmitThirdParty.php b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/SubmitThirdParty.php index acf77f702..174c80210 100644 --- a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/SubmitThirdParty.php +++ b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/SubmitThirdParty.php @@ -10,14 +10,11 @@ class SubmitThirdParty extends \Adyen\Service\AbstractResource protected $_endpoint; /** - * Add parameters that you want to filter out from the params in the request - * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * Remove applicationInfo key from the request parameters * - * @var array + * @var bool */ - protected $paramsToFilter = array( - "applicationInfo" - ); + protected $removeApplicationInfoFromRequest = true; /** * SubmitThirdParty constructor. @@ -27,6 +24,6 @@ class SubmitThirdParty extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/submitThirdParty'; - parent::__construct($service, $this->_endpoint, $this->paramsToFilter); + parent::__construct($service, $this->_endpoint, $this->removeApplicationInfoFromRequest); } } diff --git a/src/Adyen/Service/ResourceModel/Recurring/Disable.php b/src/Adyen/Service/ResourceModel/Recurring/Disable.php index 0d826782b..25dbeba34 100644 --- a/src/Adyen/Service/ResourceModel/Recurring/Disable.php +++ b/src/Adyen/Service/ResourceModel/Recurring/Disable.php @@ -10,14 +10,11 @@ class Disable extends \Adyen\Service\AbstractResource protected $endpoint; /** - * Add parameters that you want to filter out from the params in the request - * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * Remove applicationInfo key from the request parameters * - * @var array + * @var bool */ - protected $paramsToFilter = array( - "applicationInfo" - ); + protected $removeApplicationInfoFromRequest = true; /** * Disable constructor. @@ -27,6 +24,6 @@ class Disable extends \Adyen\Service\AbstractResource public function __construct($service) { $this->endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Recurring/' . $service->getClient()->getApiRecurringVersion() . '/disable'; - parent::__construct($service, $this->endpoint, $this->paramsToFilter); + parent::__construct($service, $this->endpoint, $this->removeApplicationInfoFromRequest); } } diff --git a/src/Adyen/Service/ResourceModel/Recurring/ListRecurringDetails.php b/src/Adyen/Service/ResourceModel/Recurring/ListRecurringDetails.php index c7fd2a398..ade31fa0f 100644 --- a/src/Adyen/Service/ResourceModel/Recurring/ListRecurringDetails.php +++ b/src/Adyen/Service/ResourceModel/Recurring/ListRecurringDetails.php @@ -10,14 +10,11 @@ class ListRecurringDetails extends \Adyen\Service\AbstractResource protected $endpoint; /** - * Add parameters that you want to filter out from the params in the request - * For more information about building this property please check Adyen\Service\AbstractResource filterParams doc block + * Remove applicationInfo key from the request parameters * - * @var array + * @var bool */ - protected $paramsToFilter = array( - "applicationInfo" - ); + protected $removeApplicationInfoFromRequest = true; /** * ListRecurringDetails constructor. @@ -27,6 +24,6 @@ class ListRecurringDetails extends \Adyen\Service\AbstractResource public function __construct($service) { $this->endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Recurring/' . $service->getClient()->getApiRecurringVersion() . '/listRecurringDetails'; - parent::__construct($service, $this->endpoint, $this->paramsToFilter); + parent::__construct($service, $this->endpoint, $this->removeApplicationInfoFromRequest); } } diff --git a/tests/Unit/AbstractResourceTest.php b/tests/Unit/AbstractResourceTest.php deleted file mode 100644 index a38ce4bde..000000000 --- a/tests/Unit/AbstractResourceTest.php +++ /dev/null @@ -1,238 +0,0 @@ -mockedClient = $this->createClientWithoutTestIni(); - } - - /** - * In case of empty $paramsToFilter array the function should not filter the $params array - * - * @author attilak - * @covers \Adyen\Service\AbstractResource::filterParams - */ - public function testFilterParamsNoFilter() - { - $paramsToFilter = array(); - - $params = array( - "topLevelKey" => array( - "secondLevelKey" => array( - "thirdLevelKey" - ), - "secondLevelKey2" - ), - "topLevelKey2" - ); - - $expectedParamsAfterFilter = array( - "topLevelKey" => array( - "secondLevelKey" => array( - "thirdLevelKey" - ), - "secondLevelKey2" - ), - "topLevelKey2" - ); - - // Mock abstract class with mocked client and $paramsToFilter parameters - $mockedClass = $this->getMockForAbstractClass($this->className, array((new \Adyen\Service($this->mockedClient)), "", $paramsToFilter)); - - // Get private method as testable public method - $method = $this->getMethod($this->className, "filterParams"); - - // Test against function - $result = $method->invokeArgs($mockedClass, array($params)); - $this->assertSame($expectedParamsAfterFilter, $result); - } - - /** - * Test top level filtering - * The test supposed to filter out only the keys (and optionally their values) if they are present in the $paramsToFilter - * variable - * - * @author attilak - * @covers \Adyen\Service\AbstractResource::filterParams - */ - public function testFilterParamsFilterTopLevel() - { - $paramsToFilter = array( - "topLevelKey2" - ); - - $params = array( - "topLevelKey" => array( - "secondLevelKey" => array( - "thirdLevelKey" => 'text', - "thirdLevelKey2" => 'text2' - ), - "secondLevelKey2" => 'text2' - ), - "topLevelKey2" => 'text2' - ); - - $expectedParamsAfterFilter = array( - "topLevelKey" => array( - "secondLevelKey" => array( - "thirdLevelKey" => 'text', - "thirdLevelKey2" => 'text2' - ), - "secondLevelKey2" => 'text2' - ) - ); - - // Mock abstract class with mocked client and paramsToSend parameters - $mockedClass = $this->getMockForAbstractClass($this->className, array((new \Adyen\Service($this->mockedClient)), "", $paramsToFilter)); - - // Get private method as testable public method - $method = $this->getMethod($this->className, "filterParams"); - - // Test against function - $result = $method->invokeArgs($mockedClass, array($params)); - $this->assertSame($expectedParamsAfterFilter, $result); - } - - /** - * Test multilevel filtering - * The test supposed to filter out only the keys (and optionally their values) if they are present in the $paramsToFilter - * variable - * - * @author attilak - * @covers \Adyen\Service\AbstractResource::filterParams - */ - public function testFilterParamsFilterMultiLevel() - { - $paramsToFilter = array( - "topLevelKey" => array( - "secondLevelKey" => array( - "thirdLevelKey2" - ) - ) - ); - - $params = array( - "topLevelKey" => array( - "secondLevelKey" => array( - "thirdLevelKey" => 'text', - "thirdLevelKey2" => 'text2' - ), - "secondLevelKey2" => 'text2' - ), - "topLevelKey2" => 'text2' - ); - - $expectedParamsAfterFilter = array( - "topLevelKey" => array( - "secondLevelKey" => array( - "thirdLevelKey" => 'text' - ), - "secondLevelKey2" => 'text2' - ), - "topLevelKey2" => 'text2' - ); - - // Mock abstract class with mocked client and paramsToSend parameters - $mockedClass = $this->getMockForAbstractClass($this->className, array((new \Adyen\Service($this->mockedClient)), "", $paramsToFilter)); - - // Get private method as testable public method - $method = $this->getMethod($this->className, "filterParams"); - - // Test against function - $result = $method->invokeArgs($mockedClass, array($params)); - $this->assertSame($expectedParamsAfterFilter, $result); - } - - /** - * The function should not modify the existing parameters to the default ones - * - * @author attilak - * @covers \Adyen\Service\AbstractResource::addDefaultParametersToRequest - */ - public function testAddDefaultParametersToRequestWithExistingKey() - { - $params = array( - "topLevelKey" => array( - "secondLevelKey" => array( - "thirdLevelKey" => 'text' - ), - "secondLevelKey2" => 'text2' - ), - "merchantAccount" => 'already existing param', - "applicationInfo" => array( - "adyenLibrary" => "already existing param" - ) - ); - - $expectedParamsAfterFilter = array( - "topLevelKey" => array( - "secondLevelKey" => array( - "thirdLevelKey" => 'text' - ), - "secondLevelKey2" => 'text2' - ), - "merchantAccount" => 'already existing param', - "applicationInfo" => array( - "adyenLibrary" => "already existing param" - ) - ); - - // Mock abstract class with mocked client and paramsToSend parameters - $mockedClass = $this->getMockForAbstractClass($this->className, array((new \Adyen\Service($this->mockedClient)), "")); - - // Get private method as testable public method - $method = $this->getMethod($this->className, "addDefaultParametersToRequest"); - - // Test against function - $result = $method->invokeArgs($mockedClass, array($params)); - $this->assertSame($expectedParamsAfterFilter, $result); - } - - /** - * The function should add the non existing parameters to the array - * - * @author attilak - * @covers \Adyen\Service\AbstractResource::addDefaultParametersToRequest - */ - public function testAddDefaultParametersToRequestWithNonExistingKey() - { - $params = array( - "topLevelKey" => array( - "secondLevelKey" => array( - "thirdLevelKey" => 'text' - ), - "secondLevelKey2" => 'text2' - ), - "applicationInfo" => array() - ); - - // Mock abstract class with mocked client and paramsToSend parameters - $mockedClass = $this->getMockForAbstractClass($this->className, array((new \Adyen\Service($this->mockedClient)), "")); - - // Get private method as testable public method - $method = $this->getMethod($this->className, "addDefaultParametersToRequest"); - - // Test against function - $result = $method->invokeArgs($mockedClass, array($params)); - - $this->assertArrayHasKey("adyenLibrary", $result["applicationInfo"]); - } -} From 1407fb2838086b95e5c248650517e1e22a7ac2e4 Mon Sep 17 00:00:00 2001 From: attilak Date: Thu, 11 Oct 2018 14:17:05 +0200 Subject: [PATCH 03/10] Set allow to default false based on code review --- src/Adyen/Service/AbstractResource.php | 25 ++++++++++--------- .../ResourceModel/Checkout/PaymentMethods.php | 9 +------ .../ResourceModel/Checkout/PaymentSession.php | 9 +------ .../ResourceModel/Checkout/Payments.php | 9 ++++++- .../Checkout/PaymentsDetails.php | 9 ++++++- .../ResourceModel/Checkout/PaymentsResult.php | 9 ++++++- .../CheckoutUtility/OriginKeys.php | 9 +------ .../DirectoryLookup/Directory.php | 9 +------ .../Modification/AdjustAuthorisation.php | 9 ++++++- .../ResourceModel/Modification/Cancel.php | 9 ++++++- .../Modification/CancelOrRefund.php | 9 ++++++- .../ResourceModel/Modification/Capture.php | 9 ++++++- .../ResourceModel/Modification/Refund.php | 9 ++++++- .../ResourceModel/Payment/Authorise.php | 9 ++++++- .../ResourceModel/Payment/Authorise3D.php | 9 ++++++- .../Payment/TerminalCloudAPI.php | 9 +------ .../Service/ResourceModel/Payout/Confirm.php | 9 +------ .../Service/ResourceModel/Payout/Decline.php | 9 +------ .../Payout/StoreDetailsAndSubmit.php | 9 +------ .../Service/ResourceModel/Payout/Submit.php | 9 +------ .../Payout/ThirdParty/ConfirmThirdParty.php | 9 +------ .../Payout/ThirdParty/DeclineThirdParty.php | 11 +------- .../Payout/ThirdParty/StoreDetail.php | 9 +------ .../StoreDetailsAndSubmitThirdParty.php | 9 +------ .../Payout/ThirdParty/SubmitThirdParty.php | 9 +------ .../ResourceModel/Recurring/Disable.php | 9 +------ .../Recurring/ListRecurringDetails.php | 9 +------ 27 files changed, 109 insertions(+), 152 deletions(-) diff --git a/src/Adyen/Service/AbstractResource.php b/src/Adyen/Service/AbstractResource.php index 96e59d6f0..444bd2a30 100644 --- a/src/Adyen/Service/AbstractResource.php +++ b/src/Adyen/Service/AbstractResource.php @@ -17,20 +17,20 @@ class AbstractResource /** * @var bool */ - protected $removeApplicationInfoFromRequest; + protected $allowApplicationInfo; /** * AbstractResource constructor. * * @param \Adyen\Service $service * @param $endpoint - * @param bool $removeApplicationInfoFromRequest + * @param bool $allowApplicationInfo */ - public function __construct(\Adyen\Service $service, $endpoint, $removeApplicationInfoFromRequest = false) + public function __construct(\Adyen\Service $service, $endpoint, $allowApplicationInfo = false) { $this->_service = $service; $this->_endpoint = $endpoint; - $this->removeApplicationInfoFromRequest = $removeApplicationInfoFromRequest; + $this->allowApplicationInfo = $allowApplicationInfo; } /** @@ -102,23 +102,24 @@ private function addDefaultParametersToRequest($params) } /** - * If removeApplicationInfoFromRequest is true then it removes unnecessary applicationInfo from request - * otherwise sets the default values + * If allowApplicationInfo is true then it adds applicationInfo to request + * otherwise removes from the request * * @param $params * @return mixed */ private function handleApplicationInfoInRequest($params) { - // remove if exists - if ($this->removeApplicationInfoFromRequest) { - if (isset($params['applicationInfo'])) { - unset($params['applicationInfo']); - } - } else { + // Only add if allowed + if ($this->allowApplicationInfo) { // add/overwrite applicationInfo adyenLibrary even if it's already set $params['applicationInfo']['adyenLibrary']['name'] = $this->_service->getClient()->getLibraryName(); $params['applicationInfo']['adyenLibrary']['version'] = $this->_service->getClient()->getLibraryVersion(); + } else { + // remove if exists + if (isset($params['applicationInfo'])) { + unset($params['applicationInfo']); + } } return $params; diff --git a/src/Adyen/Service/ResourceModel/Checkout/PaymentMethods.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentMethods.php index 55de358c5..2470d73fb 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/PaymentMethods.php +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentMethods.php @@ -9,13 +9,6 @@ class PaymentMethods extends \Adyen\Service\AbstractCheckoutResource */ protected $_endpoint; - /** - * Remove applicationInfo key from the request parameters - * - * @var bool - */ - protected $removeApplicationInfoFromRequest = true; - /** * PaymentMethods constructor. * @@ -25,6 +18,6 @@ class PaymentMethods extends \Adyen\Service\AbstractCheckoutResource public function __construct($service) { $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutVersion() . '/paymentMethods'; - parent::__construct($service, $this->_endpoint, $this->removeApplicationInfoFromRequest); + parent::__construct($service, $this->_endpoint); } } diff --git a/src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php index eaeb292f2..d0f617c2a 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php @@ -9,13 +9,6 @@ class PaymentSession extends \Adyen\Service\AbstractCheckoutResource */ protected $_endpoint; - /** - * Remove applicationInfo key from the request parameters - * - * @var bool - */ - protected $removeApplicationInfoFromRequest = true; - /** * PaymentSession constructor. * @@ -25,6 +18,6 @@ class PaymentSession extends \Adyen\Service\AbstractCheckoutResource public function __construct($service) { $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutVersion() . '/paymentSession'; - parent::__construct($service, $this->_endpoint, $this->removeApplicationInfoFromRequest); + parent::__construct($service, $this->_endpoint); } } diff --git a/src/Adyen/Service/ResourceModel/Checkout/Payments.php b/src/Adyen/Service/ResourceModel/Checkout/Payments.php index 059a9d693..68dde8fa0 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/Payments.php +++ b/src/Adyen/Service/ResourceModel/Checkout/Payments.php @@ -9,6 +9,13 @@ class Payments extends \Adyen\Service\AbstractCheckoutResource */ protected $_endpoint; + /** + * Include applicationInfo key in the request parameters + * + * @var bool + */ + protected $allowApplicationInfo = true; + /** * Payments constructor. * @@ -18,6 +25,6 @@ class Payments extends \Adyen\Service\AbstractCheckoutResource public function __construct($service) { $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutVersion() . '/payments'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->allowApplicationInfo); } } diff --git a/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php index 482c24dc5..8d33eabcf 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php @@ -9,6 +9,13 @@ class PaymentsDetails extends \Adyen\Service\AbstractCheckoutResource */ protected $_endpoint; + /** + * Include applicationInfo key in the request parameters + * + * @var bool + */ + protected $allowApplicationInfo = true; + /** * PaymentsDetails constructor. * @@ -18,6 +25,6 @@ class PaymentsDetails extends \Adyen\Service\AbstractCheckoutResource public function __construct($service) { $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutVersion() . '/payments/details'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->allowApplicationInfo); } } diff --git a/src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php index 51cc7c808..1250aba4f 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php @@ -9,6 +9,13 @@ class PaymentsResult extends \Adyen\Service\AbstractCheckoutResource */ protected $_endpoint; + /** + * Include applicationInfo key in the request parameters + * + * @var bool + */ + protected $allowApplicationInfo = true; + /** * PaymentsResult constructor. * @@ -18,6 +25,6 @@ class PaymentsResult extends \Adyen\Service\AbstractCheckoutResource public function __construct($service) { $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutVersion() . '/payments/result'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->allowApplicationInfo); } } diff --git a/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php b/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php index 72fedacf5..1fbac8cf5 100644 --- a/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php +++ b/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php @@ -9,13 +9,6 @@ class OriginKeys extends \Adyen\Service\AbstractCheckoutResource */ protected $_endpoint; - /** - * Remove applicationInfo key from the request parameters - * - * @var bool - */ - protected $removeApplicationInfoFromRequest = true; - /** * OriginKeys constructor. * @@ -25,6 +18,6 @@ class OriginKeys extends \Adyen\Service\AbstractCheckoutResource public function __construct($service) { $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutUtilityVersion() . '/originKeys'; - parent::__construct($service, $this->_endpoint, $this->removeApplicationInfoFromRequest); + parent::__construct($service, $this->_endpoint); } } diff --git a/src/Adyen/Service/ResourceModel/DirectoryLookup/Directory.php b/src/Adyen/Service/ResourceModel/DirectoryLookup/Directory.php index 1a03729c2..52d35d32d 100644 --- a/src/Adyen/Service/ResourceModel/DirectoryLookup/Directory.php +++ b/src/Adyen/Service/ResourceModel/DirectoryLookup/Directory.php @@ -11,13 +11,6 @@ class Directory extends \Adyen\Service\AbstractResource */ protected $_endpoint; - /** - * Remove applicationInfo key from the request parameters - * - * @var bool - */ - protected $removeApplicationInfoFromRequest = true; - /** * Directory constructor. * @@ -26,6 +19,6 @@ class Directory extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpointDirectorylookup'); - parent::__construct($service, $this->_endpoint, $this->removeApplicationInfoFromRequest); + parent::__construct($service, $this->_endpoint); } } diff --git a/src/Adyen/Service/ResourceModel/Modification/AdjustAuthorisation.php b/src/Adyen/Service/ResourceModel/Modification/AdjustAuthorisation.php index 8ab70bf43..e9db79a1c 100644 --- a/src/Adyen/Service/ResourceModel/Modification/AdjustAuthorisation.php +++ b/src/Adyen/Service/ResourceModel/Modification/AdjustAuthorisation.php @@ -9,6 +9,13 @@ class AdjustAuthorisation extends \Adyen\Service\AbstractResource */ protected $_endpoint; + /** + * Include applicationInfo key in the request parameters + * + * @var bool + */ + protected $allowApplicationInfo = true; + /** * AdjustAuthorisation constructor. * @@ -17,6 +24,6 @@ class AdjustAuthorisation extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint').'/pal/servlet/Payment/'.$service->getClient()->getApiVersion().'/adjustAuthorisation'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->allowApplicationInfo); } } diff --git a/src/Adyen/Service/ResourceModel/Modification/Cancel.php b/src/Adyen/Service/ResourceModel/Modification/Cancel.php index 79fcab0a8..f203bbecf 100644 --- a/src/Adyen/Service/ResourceModel/Modification/Cancel.php +++ b/src/Adyen/Service/ResourceModel/Modification/Cancel.php @@ -9,6 +9,13 @@ class Cancel extends \Adyen\Service\AbstractResource */ protected $_endpoint; + /** + * Include applicationInfo key in the request parameters + * + * @var bool + */ + protected $allowApplicationInfo = true; + /** * Cancel constructor. * @@ -17,6 +24,6 @@ class Cancel extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payment/' . $service->getClient()->getApiVersion() . '/cancel'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->allowApplicationInfo); } } diff --git a/src/Adyen/Service/ResourceModel/Modification/CancelOrRefund.php b/src/Adyen/Service/ResourceModel/Modification/CancelOrRefund.php index fcb025b91..0778d99bb 100644 --- a/src/Adyen/Service/ResourceModel/Modification/CancelOrRefund.php +++ b/src/Adyen/Service/ResourceModel/Modification/CancelOrRefund.php @@ -9,6 +9,13 @@ class CancelOrRefund extends \Adyen\Service\AbstractResource */ protected $_endpoint; + /** + * Include applicationInfo key in the request parameters + * + * @var bool + */ + protected $allowApplicationInfo = true; + /** * CancelOrRefund constructor. * @@ -17,6 +24,6 @@ class CancelOrRefund extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payment/'. $service->getClient()->getApiVersion() . '/cancelOrRefund'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->allowApplicationInfo); } } diff --git a/src/Adyen/Service/ResourceModel/Modification/Capture.php b/src/Adyen/Service/ResourceModel/Modification/Capture.php index d02f81397..15440a854 100644 --- a/src/Adyen/Service/ResourceModel/Modification/Capture.php +++ b/src/Adyen/Service/ResourceModel/Modification/Capture.php @@ -9,6 +9,13 @@ class Capture extends \Adyen\Service\AbstractResource */ protected $_endpoint; + /** + * Include applicationInfo key in the request parameters + * + * @var bool + */ + protected $allowApplicationInfo = true; + /** * Capture constructor. * @@ -17,6 +24,6 @@ class Capture extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payment/' . $service->getClient()->getApiVersion() . '/capture'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->allowApplicationInfo); } } diff --git a/src/Adyen/Service/ResourceModel/Modification/Refund.php b/src/Adyen/Service/ResourceModel/Modification/Refund.php index 166f274bc..b17e58639 100644 --- a/src/Adyen/Service/ResourceModel/Modification/Refund.php +++ b/src/Adyen/Service/ResourceModel/Modification/Refund.php @@ -9,6 +9,13 @@ class Refund extends \Adyen\Service\AbstractResource */ protected $_endpoint; + /** + * Include applicationInfo key in the request parameters + * + * @var bool + */ + protected $allowApplicationInfo = true; + /** * Refund constructor. * @@ -17,6 +24,6 @@ class Refund extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payment/' . $service->getClient()->getApiVersion() . '/refund'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->allowApplicationInfo); } } diff --git a/src/Adyen/Service/ResourceModel/Payment/Authorise.php b/src/Adyen/Service/ResourceModel/Payment/Authorise.php index a6d8245e7..ce2afd982 100644 --- a/src/Adyen/Service/ResourceModel/Payment/Authorise.php +++ b/src/Adyen/Service/ResourceModel/Payment/Authorise.php @@ -9,6 +9,13 @@ class Authorise extends \Adyen\Service\AbstractResource */ protected $_endpoint; + /** + * Include applicationInfo key in the request parameters + * + * @var bool + */ + protected $allowApplicationInfo = true; + /** * Authorise constructor. * @@ -17,6 +24,6 @@ class Authorise extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payment/' . $service->getClient()->getApiVersion() . '/authorise'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->allowApplicationInfo); } } diff --git a/src/Adyen/Service/ResourceModel/Payment/Authorise3D.php b/src/Adyen/Service/ResourceModel/Payment/Authorise3D.php index a67752fc1..c505376c0 100644 --- a/src/Adyen/Service/ResourceModel/Payment/Authorise3D.php +++ b/src/Adyen/Service/ResourceModel/Payment/Authorise3D.php @@ -9,6 +9,13 @@ class Authorise3D extends \Adyen\Service\AbstractResource */ protected $_endpoint; + /** + * Include applicationInfo key in the request parameters + * + * @var bool + */ + protected $allowApplicationInfo = true; + /** * Authorise3D constructor. * @@ -17,6 +24,6 @@ class Authorise3D extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payment/' . $service->getClient()->getApiVersion() . '/authorise3d'; - parent::__construct($service, $this->_endpoint); + parent::__construct($service, $this->_endpoint, $this->allowApplicationInfo); } } diff --git a/src/Adyen/Service/ResourceModel/Payment/TerminalCloudAPI.php b/src/Adyen/Service/ResourceModel/Payment/TerminalCloudAPI.php index 63acfb99f..870181e56 100644 --- a/src/Adyen/Service/ResourceModel/Payment/TerminalCloudAPI.php +++ b/src/Adyen/Service/ResourceModel/Payment/TerminalCloudAPI.php @@ -9,13 +9,6 @@ class TerminalCloudAPI extends \Adyen\Service\AbstractResource */ protected $_endpoint; - /** - * Remove applicationInfo key from the request parameters - * - * @var bool - */ - protected $removeApplicationInfoFromRequest = true; - /** * TerminalCloudAPI constructor. * @@ -29,6 +22,6 @@ public function __construct($service, $asynchronous) } else { $this->_endpoint = $service->getClient()->getConfig()->get('endpointTerminalCloud') . '/sync'; } - parent::__construct($service, $this->_endpoint, $this->removeApplicationInfoFromRequest); + parent::__construct($service, $this->_endpoint); } } diff --git a/src/Adyen/Service/ResourceModel/Payout/Confirm.php b/src/Adyen/Service/ResourceModel/Payout/Confirm.php index 3f74a01cd..1699d90a4 100644 --- a/src/Adyen/Service/ResourceModel/Payout/Confirm.php +++ b/src/Adyen/Service/ResourceModel/Payout/Confirm.php @@ -9,13 +9,6 @@ class Confirm extends \Adyen\Service\AbstractResource */ protected $_endpoint; - /** - * Remove applicationInfo key from the request parameters - * - * @var bool - */ - protected $removeApplicationInfoFromRequest = true; - /** * Confirm constructor. * @@ -24,6 +17,6 @@ class Confirm extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/confirm'; - parent::__construct($service, $this->_endpoint, $this->removeApplicationInfoFromRequest); + parent::__construct($service, $this->_endpoint); } } diff --git a/src/Adyen/Service/ResourceModel/Payout/Decline.php b/src/Adyen/Service/ResourceModel/Payout/Decline.php index 258a5a78d..f82b6ca4f 100644 --- a/src/Adyen/Service/ResourceModel/Payout/Decline.php +++ b/src/Adyen/Service/ResourceModel/Payout/Decline.php @@ -9,13 +9,6 @@ class Decline extends \Adyen\Service\AbstractResource */ protected $_endpoint; - /** - * Remove applicationInfo key from the request parameters - * - * @var bool - */ - protected $removeApplicationInfoFromRequest = true; - /** * Decline constructor. * @@ -24,6 +17,6 @@ class Decline extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/decline'; - parent::__construct($service, $this->_endpoint, $this->removeApplicationInfoFromRequest); + parent::__construct($service, $this->_endpoint); } } diff --git a/src/Adyen/Service/ResourceModel/Payout/StoreDetailsAndSubmit.php b/src/Adyen/Service/ResourceModel/Payout/StoreDetailsAndSubmit.php index 0171a98b3..1491d0274 100644 --- a/src/Adyen/Service/ResourceModel/Payout/StoreDetailsAndSubmit.php +++ b/src/Adyen/Service/ResourceModel/Payout/StoreDetailsAndSubmit.php @@ -9,13 +9,6 @@ class StoreDetailsAndSubmit extends \Adyen\Service\AbstractResource */ protected $_endpoint; - /** - * Remove applicationInfo key from the request parameters - * - * @var bool - */ - protected $removeApplicationInfoFromRequest = true; - /** * StoreDetailsAndSubmit constructor. * @@ -24,6 +17,6 @@ class StoreDetailsAndSubmit extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/storeDetailAndSubmit'; - parent::__construct($service, $this->_endpoint, $this->removeApplicationInfoFromRequest); + parent::__construct($service, $this->_endpoint); } } diff --git a/src/Adyen/Service/ResourceModel/Payout/Submit.php b/src/Adyen/Service/ResourceModel/Payout/Submit.php index 22e78ce9c..81be2d7d3 100644 --- a/src/Adyen/Service/ResourceModel/Payout/Submit.php +++ b/src/Adyen/Service/ResourceModel/Payout/Submit.php @@ -9,13 +9,6 @@ class Submit extends \Adyen\Service\AbstractResource */ protected $_endpoint; - /** - * Remove applicationInfo key from the request parameters - * - * @var bool - */ - protected $removeApplicationInfoFromRequest = true; - /** * Submit constructor. * @@ -24,6 +17,6 @@ class Submit extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/submit'; - parent::__construct($service, $this->_endpoint, $this->removeApplicationInfoFromRequest); + parent::__construct($service, $this->_endpoint); } } diff --git a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/ConfirmThirdParty.php b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/ConfirmThirdParty.php index c62141bd7..6c9cf850f 100644 --- a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/ConfirmThirdParty.php +++ b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/ConfirmThirdParty.php @@ -9,13 +9,6 @@ class ConfirmThirdParty extends \Adyen\Service\AbstractResource */ protected $_endpoint; - /** - * Remove applicationInfo key from the request parameters - * - * @var bool - */ - protected $removeApplicationInfoFromRequest = true; - /** * ConfirmThirdParty constructor. * @@ -24,6 +17,6 @@ class ConfirmThirdParty extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/confirmThirdParty'; - parent::__construct($service, $this->_endpoint, $this->removeApplicationInfoFromRequest); + parent::__construct($service, $this->_endpoint); } } diff --git a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/DeclineThirdParty.php b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/DeclineThirdParty.php index 61478a427..162b3e14d 100644 --- a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/DeclineThirdParty.php +++ b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/DeclineThirdParty.php @@ -2,8 +2,6 @@ namespace Adyen\Service\ResourceModel\Payout\ThirdParty; -use Adyen\Service; - class DeclineThirdParty extends \Adyen\Service\AbstractResource { /** @@ -11,13 +9,6 @@ class DeclineThirdParty extends \Adyen\Service\AbstractResource */ protected $_endpoint; - /** - * Remove applicationInfo key from the request parameters - * - * @var bool - */ - protected $removeApplicationInfoFromRequest = true; - /** * DeclineThirdParty constructor. * @@ -26,6 +17,6 @@ class DeclineThirdParty extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/declineThirdParty'; - parent::__construct($service, $this->_endpoint, $this->removeApplicationInfoFromRequest); + parent::__construct($service, $this->_endpoint); } } diff --git a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetail.php b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetail.php index d9710c5ca..9f6ef242d 100644 --- a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetail.php +++ b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetail.php @@ -9,13 +9,6 @@ class StoreDetail extends \Adyen\Service\AbstractResource */ protected $_endpoint; - /** - * Remove applicationInfo key from the request parameters - * - * @var bool - */ - protected $removeApplicationInfoFromRequest = true; - /** * StoreDetail constructor. * @@ -24,6 +17,6 @@ class StoreDetail extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/storeDetail'; - parent::__construct($service, $this->_endpoint, $this->removeApplicationInfoFromRequest); + parent::__construct($service, $this->_endpoint); } } diff --git a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetailsAndSubmitThirdParty.php b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetailsAndSubmitThirdParty.php index e2f92941f..6be93f413 100644 --- a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetailsAndSubmitThirdParty.php +++ b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetailsAndSubmitThirdParty.php @@ -9,13 +9,6 @@ class StoreDetailsAndSubmitThirdParty extends \Adyen\Service\AbstractResource */ protected $_endpoint; - /** - * Remove applicationInfo key from the request parameters - * - * @var bool - */ - protected $removeApplicationInfoFromRequest = true; - /** * StoreDetailsAndSubmitThirdParty constructor. * @@ -24,6 +17,6 @@ class StoreDetailsAndSubmitThirdParty extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/storeDetailAndSubmitThirdParty'; - parent::__construct($service, $this->_endpoint, $this->removeApplicationInfoFromRequest); + parent::__construct($service, $this->_endpoint); } } diff --git a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/SubmitThirdParty.php b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/SubmitThirdParty.php index 174c80210..393c38ad8 100644 --- a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/SubmitThirdParty.php +++ b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/SubmitThirdParty.php @@ -9,13 +9,6 @@ class SubmitThirdParty extends \Adyen\Service\AbstractResource */ protected $_endpoint; - /** - * Remove applicationInfo key from the request parameters - * - * @var bool - */ - protected $removeApplicationInfoFromRequest = true; - /** * SubmitThirdParty constructor. * @@ -24,6 +17,6 @@ class SubmitThirdParty extends \Adyen\Service\AbstractResource public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/submitThirdParty'; - parent::__construct($service, $this->_endpoint, $this->removeApplicationInfoFromRequest); + parent::__construct($service, $this->_endpoint); } } diff --git a/src/Adyen/Service/ResourceModel/Recurring/Disable.php b/src/Adyen/Service/ResourceModel/Recurring/Disable.php index 25dbeba34..2f2978e32 100644 --- a/src/Adyen/Service/ResourceModel/Recurring/Disable.php +++ b/src/Adyen/Service/ResourceModel/Recurring/Disable.php @@ -9,13 +9,6 @@ class Disable extends \Adyen\Service\AbstractResource */ protected $endpoint; - /** - * Remove applicationInfo key from the request parameters - * - * @var bool - */ - protected $removeApplicationInfoFromRequest = true; - /** * Disable constructor. * @@ -24,6 +17,6 @@ class Disable extends \Adyen\Service\AbstractResource public function __construct($service) { $this->endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Recurring/' . $service->getClient()->getApiRecurringVersion() . '/disable'; - parent::__construct($service, $this->endpoint, $this->removeApplicationInfoFromRequest); + parent::__construct($service, $this->endpoint); } } diff --git a/src/Adyen/Service/ResourceModel/Recurring/ListRecurringDetails.php b/src/Adyen/Service/ResourceModel/Recurring/ListRecurringDetails.php index ade31fa0f..650554280 100644 --- a/src/Adyen/Service/ResourceModel/Recurring/ListRecurringDetails.php +++ b/src/Adyen/Service/ResourceModel/Recurring/ListRecurringDetails.php @@ -9,13 +9,6 @@ class ListRecurringDetails extends \Adyen\Service\AbstractResource */ protected $endpoint; - /** - * Remove applicationInfo key from the request parameters - * - * @var bool - */ - protected $removeApplicationInfoFromRequest = true; - /** * ListRecurringDetails constructor. * @@ -24,6 +17,6 @@ class ListRecurringDetails extends \Adyen\Service\AbstractResource public function __construct($service) { $this->endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Recurring/' . $service->getClient()->getApiRecurringVersion() . '/listRecurringDetails'; - parent::__construct($service, $this->endpoint, $this->removeApplicationInfoFromRequest); + parent::__construct($service, $this->endpoint); } } From 69dc7aff4f906c6d933f76ff65b93f037fe5533e Mon Sep 17 00:00:00 2001 From: attilak Date: Thu, 11 Oct 2018 16:53:49 +0200 Subject: [PATCH 04/10] Add Client public setter functions for applicationInfo properties Php unit tests added --- src/Adyen/Client.php | 24 +++++- src/Adyen/Config.php | 16 ++++ src/Adyen/Service/AbstractResource.php | 11 +++ tests/Unit/AbstractResourceTest.php | 115 +++++++++++++++++++++++++ 4 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 tests/Unit/AbstractResourceTest.php diff --git a/src/Adyen/Client.php b/src/Adyen/Client.php index 8f06e08cf..d3bfb7111 100644 --- a/src/Adyen/Client.php +++ b/src/Adyen/Client.php @@ -27,7 +27,7 @@ class Client const ENDPOINT_PROTOCOL = "https://"; /** - * @var Adyen_Config $config + * @var \Adyen\Config $config */ private $_config; private $_httpClient; @@ -155,6 +155,28 @@ public function setApplicationName($applicationName) $this->_config->set('applicationName', $applicationName); } + /** + * Set external platform name and version + * + * @param string $name + * @param string $version + */ + public function setExternalPlatform($name, $version) + { + $this->_config->set('externalPlatform', array('name' => $name, 'version' => $version)); + } + + /** + * Set Adyen payment source name and version + * + * @param string $name + * @param string $version + */ + public function setAdyenPaymentSource($name, $version) + { + $this->_config->set('adyenPaymentSource', array('name' => $name, 'version' => $version)); + } + /** * Type can be json or array * diff --git a/src/Adyen/Config.php b/src/Adyen/Config.php index a807cc338..4d0d44021 100644 --- a/src/Adyen/Config.php +++ b/src/Adyen/Config.php @@ -97,4 +97,20 @@ public function getMerchantAccount() { return isset($this->data['merchantAccount']) ? $this->data['merchantAccount'] : null; } + + /** + * @return mixed|null + */ + public function getAdyenPaymentSource() + { + return isset($this->data['adyenPaymentSource']) ? $this->data['adyenPaymentSource'] : null; + } + + /** + * @return mixed|null + */ + public function getExternalPlatform() + { + return isset($this->data['externalPlatform']) ? $this->data['externalPlatform'] : null; + } } \ No newline at end of file diff --git a/src/Adyen/Service/AbstractResource.php b/src/Adyen/Service/AbstractResource.php index 444bd2a30..0ea0486e5 100644 --- a/src/Adyen/Service/AbstractResource.php +++ b/src/Adyen/Service/AbstractResource.php @@ -115,6 +115,17 @@ private function handleApplicationInfoInRequest($params) // add/overwrite applicationInfo adyenLibrary even if it's already set $params['applicationInfo']['adyenLibrary']['name'] = $this->_service->getClient()->getLibraryName(); $params['applicationInfo']['adyenLibrary']['version'] = $this->_service->getClient()->getLibraryVersion(); + + if ($adyenPaymentSource = $this->_service->getClient()->getConfig()->getAdyenPaymentSource()) { + $params['applicationInfo']['adyenPaymentSource']['version'] = $adyenPaymentSource['version']; + $params['applicationInfo']['adyenPaymentSource']['name'] = $adyenPaymentSource['name']; + } + + if ($externalPlatform = $this->_service->getClient()->getConfig()->getExternalPlatform()) { + $params['applicationInfo']['externalPlatform']['version'] = $externalPlatform['version']; + $params['applicationInfo']['externalPlatform']['name'] = $externalPlatform['name']; + } + } else { // remove if exists if (isset($params['applicationInfo'])) { diff --git a/tests/Unit/AbstractResourceTest.php b/tests/Unit/AbstractResourceTest.php new file mode 100644 index 000000000..46d31a05f --- /dev/null +++ b/tests/Unit/AbstractResourceTest.php @@ -0,0 +1,115 @@ + "test", + "applicationInfo" => array( + "adyenLibrary" => array( + "name" => "test", + "version" => "test" + ) + ) + ); + + // Mock client without the Test ini settings + $mockedClient = $this->createClientWithoutTestIni(); + + // Mock abstract class with mocked client and $paramsToFilter parameters + $mockedClass = $this->getMockForAbstractClass($this->className, array((new \Adyen\Service($mockedClient)), "", false)); + + // Get private method as testable public method + $method = $this->getMethod($this->className, "handleApplicationInfoInRequest"); + + // Test against function + $result = $method->invokeArgs($mockedClass, array($params)); + $this->assertArrayNotHasKey("applicationInfo", $result); + } + + /** + * If the allowApplicationInfo is true the applicationInfo Adyen Library should be overwritten with the real values + * + * @author attilak + * @covers \Adyen\Service\AbstractResource::handleApplicationInfoInRequest + */ + public function testHandleApplicationInfoInRequestShouldOverwriteApplicationInfoAdyenLibraryParams() + { + $params = array( + "topLevelKey" => "test", + "applicationInfo" => array( + "adyenLibrary" => array( + "name" => "test", + "version" => "test" + ) + ) + ); + + // Mock client without the Test ini settings + $mockedClient = $this->createClientWithoutTestIni(); + + // Mock abstract class with mocked client and $paramsToFilter parameters + $mockedClass = $this->getMockForAbstractClass($this->className, array((new \Adyen\Service($mockedClient)), "", true)); + + // Get private method as testable public method + $method = $this->getMethod($this->className, "handleApplicationInfoInRequest"); + + // Test against function + $result = $method->invokeArgs($mockedClass, array($params)); + $this->assertSame($mockedClient->getLibraryName(), $result['applicationInfo']['adyenLibrary']['name']); + $this->assertSame($mockedClient->getLibraryVersion(), $result['applicationInfo']['adyenLibrary']['version']); + } + + /** + * If the config adyenPaymentSource is set the applicationInfo adyenPaymentSource should be added to the params + * If the config externalPlatform is not set the applicationInfo externalPlatform should not be added to the params + * + * @author attilak + * @covers \Adyen\Service\AbstractResource::handleApplicationInfoInRequest + */ + public function testHandleApplicationInfoInRequestShouldAddApplicationInfoAdyenPaymentSourceToParams() + { + $params = array( + "topLevelKey" => "test" + ); + + $expectedArraySubset = array( + "applicationInfo" => array( + "adyenPaymentSource" => array( + "name" => "name-test", + "version" => "version-test") + ) + ); + + // Mock client without the Test ini settings + $mockedClient = $this->createClientWithoutTestIni(); + + $mockedClient->setAdyenPaymentSource("name-test", "version-test"); + + // Mock abstract class with mocked client and $paramsToFilter parameters + $mockedClass = $this->getMockForAbstractClass($this->className, array((new \Adyen\Service($mockedClient)), "", true)); + + // Get private method as testable public method + $method = $this->getMethod($this->className, "handleApplicationInfoInRequest"); + + // Test against function + $result = $method->invokeArgs($mockedClass, array($params)); + + $this->assertArrayHasKey("applicationInfo", $result); + $this->assertArraySubset($expectedArraySubset, $result); + } +} From 91d6e433402e2677ec2a7957db2450e3f3f381ae Mon Sep 17 00:00:00 2001 From: attilak Date: Fri, 12 Oct 2018 11:54:34 +0200 Subject: [PATCH 05/10] Remove allow ApplicaionInfo from payment details and payment result endpoints --- .../Service/ResourceModel/Checkout/PaymentsDetails.php | 9 +-------- .../Service/ResourceModel/Checkout/PaymentsResult.php | 9 +-------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php index 8d33eabcf..482c24dc5 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php @@ -9,13 +9,6 @@ class PaymentsDetails extends \Adyen\Service\AbstractCheckoutResource */ protected $_endpoint; - /** - * Include applicationInfo key in the request parameters - * - * @var bool - */ - protected $allowApplicationInfo = true; - /** * PaymentsDetails constructor. * @@ -25,6 +18,6 @@ class PaymentsDetails extends \Adyen\Service\AbstractCheckoutResource public function __construct($service) { $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutVersion() . '/payments/details'; - parent::__construct($service, $this->_endpoint, $this->allowApplicationInfo); + parent::__construct($service, $this->_endpoint); } } diff --git a/src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php index 1250aba4f..51cc7c808 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php @@ -9,13 +9,6 @@ class PaymentsResult extends \Adyen\Service\AbstractCheckoutResource */ protected $_endpoint; - /** - * Include applicationInfo key in the request parameters - * - * @var bool - */ - protected $allowApplicationInfo = true; - /** * PaymentsResult constructor. * @@ -25,6 +18,6 @@ class PaymentsResult extends \Adyen\Service\AbstractCheckoutResource public function __construct($service) { $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutVersion() . '/payments/result'; - parent::__construct($service, $this->_endpoint, $this->allowApplicationInfo); + parent::__construct($service, $this->_endpoint); } } From 1d067ceafddcb86ac634a909691c64957ee88bb1 Mon Sep 17 00:00:00 2001 From: attilak Date: Fri, 12 Oct 2018 16:08:35 +0200 Subject: [PATCH 06/10] Add integrator as a possible parameter in the applicationInfo.externalPlatform Unit tests added --- src/Adyen/Client.php | 9 ++-- src/Adyen/Service/AbstractResource.php | 4 ++ tests/Unit/AbstractResourceTest.php | 68 ++++++++++++++++++++++++-- 3 files changed, 73 insertions(+), 8 deletions(-) diff --git a/src/Adyen/Client.php b/src/Adyen/Client.php index d3bfb7111..fa2a43fc1 100644 --- a/src/Adyen/Client.php +++ b/src/Adyen/Client.php @@ -33,7 +33,7 @@ class Client private $_httpClient; /** - * @var Adyen_Logger_Abstract $logger + * @var Logger $logger */ private $logger; @@ -156,14 +156,15 @@ public function setApplicationName($applicationName) } /** - * Set external platform name and version + * Set external platform name, version and integrator * * @param string $name * @param string $version + * @param string $integrator */ - public function setExternalPlatform($name, $version) + public function setExternalPlatform($name, $version, $integrator = "") { - $this->_config->set('externalPlatform', array('name' => $name, 'version' => $version)); + $this->_config->set('externalPlatform', array('name' => $name, 'version' => $version, 'integrator' => $integrator)); } /** diff --git a/src/Adyen/Service/AbstractResource.php b/src/Adyen/Service/AbstractResource.php index 0ea0486e5..32d9ec4c7 100644 --- a/src/Adyen/Service/AbstractResource.php +++ b/src/Adyen/Service/AbstractResource.php @@ -124,6 +124,10 @@ private function handleApplicationInfoInRequest($params) if ($externalPlatform = $this->_service->getClient()->getConfig()->getExternalPlatform()) { $params['applicationInfo']['externalPlatform']['version'] = $externalPlatform['version']; $params['applicationInfo']['externalPlatform']['name'] = $externalPlatform['name']; + + if (!empty($externalPlatform['integrator'])) { + $params['applicationInfo']['externalPlatform']['integrator'] = $externalPlatform['integrator']; + } } } else { diff --git a/tests/Unit/AbstractResourceTest.php b/tests/Unit/AbstractResourceTest.php index 46d31a05f..83724558f 100644 --- a/tests/Unit/AbstractResourceTest.php +++ b/tests/Unit/AbstractResourceTest.php @@ -12,7 +12,6 @@ class AbstractResourceTest extends TestCase /** * If the allowApplicationInfo is false the applicationInfo key should be removed from the params * - * @author attilak * @covers \Adyen\Service\AbstractResource::handleApplicationInfoInRequest */ public function testHandleApplicationInfoInRequestShouldRemoveApplicationInfoFromParams() @@ -44,7 +43,6 @@ public function testHandleApplicationInfoInRequestShouldRemoveApplicationInfoFro /** * If the allowApplicationInfo is true the applicationInfo Adyen Library should be overwritten with the real values * - * @author attilak * @covers \Adyen\Service\AbstractResource::handleApplicationInfoInRequest */ public function testHandleApplicationInfoInRequestShouldOverwriteApplicationInfoAdyenLibraryParams() @@ -78,7 +76,6 @@ public function testHandleApplicationInfoInRequestShouldOverwriteApplicationInfo * If the config adyenPaymentSource is set the applicationInfo adyenPaymentSource should be added to the params * If the config externalPlatform is not set the applicationInfo externalPlatform should not be added to the params * - * @author attilak * @covers \Adyen\Service\AbstractResource::handleApplicationInfoInRequest */ public function testHandleApplicationInfoInRequestShouldAddApplicationInfoAdyenPaymentSourceToParams() @@ -91,7 +88,8 @@ public function testHandleApplicationInfoInRequestShouldAddApplicationInfoAdyenP "applicationInfo" => array( "adyenPaymentSource" => array( "name" => "name-test", - "version" => "version-test") + "version" => "version-test" + ) ) ); @@ -112,4 +110,66 @@ public function testHandleApplicationInfoInRequestShouldAddApplicationInfoAdyenP $this->assertArrayHasKey("applicationInfo", $result); $this->assertArraySubset($expectedArraySubset, $result); } + + /** + * If the config adyenPaymentSource integrator is set, the applicationInfo adyenPaymentSource integrator should be + * added to the params. + * + * @covers \Adyen\Service\AbstractResource::handleApplicationInfoInRequest + */ + public function testHandleApplicationInfoInRequestShouldAddApplicationInfoAdyenPaymentSourceIntegratorToParams() + { + $params = array( + "topLevelKey" => "test" + ); + + // Mock client without the Test ini settings + $mockedClient = $this->createClientWithoutTestIni(); + + $mockedClient->setExternalPlatform("name-test", "version-test", "integrator-test"); + + // Mock abstract class with mocked client and $paramsToFilter parameters + $mockedClass = $this->getMockForAbstractClass($this->className, array((new \Adyen\Service($mockedClient)), "", true)); + + // Get private method as testable public method + $method = $this->getMethod($this->className, "handleApplicationInfoInRequest"); + + // Test against function + $result = $method->invokeArgs($mockedClass, array($params)); + + $this->assertArrayHasKey("applicationInfo", $result); + $this->assertArrayHasKey("externalPlatform", $result["applicationInfo"]); + $this->assertArrayHasKey("integrator", $result["applicationInfo"]["externalPlatform"]); + } + + /** + * If the config adyenPaymentSource integrator is not set, the applicationInfo adyenPaymentSource integrator should + * not be added to the params. + * + * @covers \Adyen\Service\AbstractResource::handleApplicationInfoInRequest + */ + public function testHandleApplicationInfoInRequestShouldNotAddApplicationInfoAdyenPaymentSourceIntegratorToParams() + { + $params = array( + "topLevelKey" => "test" + ); + + // Mock client without the Test ini settings + $mockedClient = $this->createClientWithoutTestIni(); + + $mockedClient->setExternalPlatform("name-test", "version-test"); + + // Mock abstract class with mocked client and $paramsToFilter parameters + $mockedClass = $this->getMockForAbstractClass($this->className, array((new \Adyen\Service($mockedClient)), "", true)); + + // Get private method as testable public method + $method = $this->getMethod($this->className, "handleApplicationInfoInRequest"); + + // Test against function + $result = $method->invokeArgs($mockedClass, array($params)); + + $this->assertArrayHasKey("applicationInfo", $result); + $this->assertArrayHasKey("externalPlatform", $result["applicationInfo"]); + $this->assertArrayNotHasKey("integrator", $result["applicationInfo"]["externalPlatform"]); + } } From 27cfe43296ec861603236b4d543e2b3df9645e3d Mon Sep 17 00:00:00 2001 From: attilak Date: Tue, 16 Oct 2018 08:23:09 +0200 Subject: [PATCH 07/10] remove topLevelKey from test params since we don't use it anymore --- tests/Unit/AbstractResourceTest.php | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/tests/Unit/AbstractResourceTest.php b/tests/Unit/AbstractResourceTest.php index 83724558f..80269eae2 100644 --- a/tests/Unit/AbstractResourceTest.php +++ b/tests/Unit/AbstractResourceTest.php @@ -17,7 +17,6 @@ class AbstractResourceTest extends TestCase public function testHandleApplicationInfoInRequestShouldRemoveApplicationInfoFromParams() { $params = array( - "topLevelKey" => "test", "applicationInfo" => array( "adyenLibrary" => array( "name" => "test", @@ -48,7 +47,6 @@ public function testHandleApplicationInfoInRequestShouldRemoveApplicationInfoFro public function testHandleApplicationInfoInRequestShouldOverwriteApplicationInfoAdyenLibraryParams() { $params = array( - "topLevelKey" => "test", "applicationInfo" => array( "adyenLibrary" => array( "name" => "test", @@ -80,9 +78,7 @@ public function testHandleApplicationInfoInRequestShouldOverwriteApplicationInfo */ public function testHandleApplicationInfoInRequestShouldAddApplicationInfoAdyenPaymentSourceToParams() { - $params = array( - "topLevelKey" => "test" - ); + $params = array(); $expectedArraySubset = array( "applicationInfo" => array( @@ -119,9 +115,7 @@ public function testHandleApplicationInfoInRequestShouldAddApplicationInfoAdyenP */ public function testHandleApplicationInfoInRequestShouldAddApplicationInfoAdyenPaymentSourceIntegratorToParams() { - $params = array( - "topLevelKey" => "test" - ); + $params = array(); // Mock client without the Test ini settings $mockedClient = $this->createClientWithoutTestIni(); @@ -150,9 +144,7 @@ public function testHandleApplicationInfoInRequestShouldAddApplicationInfoAdyenP */ public function testHandleApplicationInfoInRequestShouldNotAddApplicationInfoAdyenPaymentSourceIntegratorToParams() { - $params = array( - "topLevelKey" => "test" - ); + $params = array(); // Mock client without the Test ini settings $mockedClient = $this->createClientWithoutTestIni(); From d063e513a0d9cd7f311007480abe8340814005f5 Mon Sep 17 00:00:00 2001 From: Alessio Zampatti Date: Thu, 18 Oct 2018 11:56:09 +0200 Subject: [PATCH 08/10] PW-614: Provide a code for errors thrown by Curl (#79) * PW-614: Provide a code for errors thrown by Curl * PW-614: added empty line at the end of file * PW-614: Updated mocktests for curl errors * PW-614: Remove if check, since an errno is always passed --- src/Adyen/HttpClient/CurlClient.php | 2 +- tests/MockTest/PaymentTest.php | 6 +-- tests/PosPaymentTest.php | 66 ++++++++++++++++++++++++++++- 3 files changed, 68 insertions(+), 6 deletions(-) diff --git a/src/Adyen/HttpClient/CurlClient.php b/src/Adyen/HttpClient/CurlClient.php index 9dc762f9c..71b1d7882 100644 --- a/src/Adyen/HttpClient/CurlClient.php +++ b/src/Adyen/HttpClient/CurlClient.php @@ -222,7 +222,7 @@ protected function handleCurlError($url, $errno, $message, $logger) } $msg .= "\n(Network error [errno $errno]: $message)"; $logger->error($msg); - throw new \Adyen\ConnectionException($msg); + throw new \Adyen\ConnectionException($msg, $errno); } /** diff --git a/tests/MockTest/PaymentTest.php b/tests/MockTest/PaymentTest.php index d771c7d01..9634e07ec 100644 --- a/tests/MockTest/PaymentTest.php +++ b/tests/MockTest/PaymentTest.php @@ -107,9 +107,7 @@ public function testAuthoriseConnectionFailure($jsonFile, $httpStatus, $errno, $ } catch (\Exception $e) { $this->assertInstanceOf('Adyen\ConnectionException', $e); $this->assertContains($expectedExceptionMessage, $e->getMessage()); - if ($httpStatus != null) { - $this->assertEquals($httpStatus, $e->getCode()); - } + $this->assertEquals($errno, $e->getCode()); } } @@ -173,4 +171,4 @@ public static function resultFailureAuthoriseProvider() array('tests/Resources/Payment/invalid-merchant-account.json', 403, "Invalid Merchant Account") ); } -} \ No newline at end of file +} diff --git a/tests/PosPaymentTest.php b/tests/PosPaymentTest.php index 568b3993b..e79bc0fe0 100644 --- a/tests/PosPaymentTest.php +++ b/tests/PosPaymentTest.php @@ -187,4 +187,68 @@ public function testCreatePosEMVRefundSuccess() } -} \ No newline at end of file + /** + * After timeout, an Exception will be returned with code: CURLE_OPERATION_TIMEOUTED + * @covers \Adyen\HttpClient\CurlClient::handleCurlError + */ + public function testPosPaymentFailTimeout() + { + // initialize client + $client = $this->createTerminalCloudAPIClient(); + $client->setTimeout(1); + + // initialize service + $service = new Service\PosPayment($client); + + //Construct request + $transactionType = \Adyen\TransactionType::NORMAL; + $serviceID = date("dHis"); + $timeStamper = date("Y-m-d") . "T" . date("H:i:s+00:00"); + + $json = '{ + "SaleToPOIRequest": { + "MessageHeader": { + "MessageType": "Request", + "MessageClass": "Service", + "MessageCategory": "Payment", + "SaleID": "PosTestLibrary", + "POIID": "' . $this->getPOIID() . '", + "ProtocolVersion": "3.0", + "ServiceID": "' . $serviceID . '" + }, + "PaymentRequest": { + "SaleData": { + "SaleTransactionID": { + "TransactionID": "POStimeout", + "TimeStamp": "' . $timeStamper . '" + }, + "TokenRequestedType": "Customer", + "SaleReferenceID": "SalesRefABC" + }, + "PaymentTransaction": { + "AmountsReq": { + "Currency": "EUR", + "RequestedAmount": ' . 14.91 . ' + } + }, + "PaymentData": { + "PaymentType": "' . $transactionType . '" + } + } + } + } + '; + + $params = json_decode($json, true); //Create associative array for passing along + + try { + $result = $service->runTenderSync($params); + $this->fail(); + } catch (\Exception $e) { + $this->assertEquals(CURLE_OPERATION_TIMEOUTED, $e->getCode()); + $this->validateApiPermission($e); + } + + } + +} From a1288f7b818ab62422e2a0316de516b1fcf263b2 Mon Sep 17 00:00:00 2001 From: cyattilakiss <42297201+cyattilakiss@users.noreply.github.com> Date: Mon, 22 Oct 2018 13:57:53 +0200 Subject: [PATCH 09/10] fix local unit test running caused by the missing date_default_timezone_set (#78) Set date_default_timezone if missing from the defaults --- tests/TestCase.php | 46 ++++++++++++++++++++++++++++++++----------- tests/config/test.ini | 2 +- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index 680fd16c8..5d40080bb 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -9,15 +9,34 @@ class TestCase extends \PHPUnit_Framework_TestCase protected $_skinCode; protected $_hmacSignature; + /** + * Settings parsed from the config/test.ini file + * + * @var array + */ + protected $settings; + public function __construct() { - $this->_merchantAccount = $this->getMerchantAccount(); $this->_skinCode = $this->getSkinCode(); $this->_hmacSignature = $this->getHmacSignature(); + $this->settings = $this->_loadConfigIni(); + $this->setDefaultsDuringDevelopment(); } + /** + * During development of the standalone php api library this function sets the necessary defaults which would + * otherwise set by the merchant + */ + private function setDefaultsDuringDevelopment() + { + // Check default timezone if not set use a default value for that + if (!ini_get('date.timezone')) { + ini_set('date.timezone', 'Europe/Amsterdam'); + } + } /** * Mock client @@ -27,7 +46,7 @@ public function __construct() protected function createClient() { // load settings from .ini file - $settings = $this->_loadConfigIni(); + $settings = $this->settings; // validate username, password and MERCHANTAccount @@ -82,7 +101,7 @@ protected function createClientWithoutTestIni() protected function createPayoutClient() { // load settings from .ini file - $settings = $this->_loadConfigIni(); + $settings = $this->settings; // validate username, password and MERCHANTAccount @@ -119,7 +138,7 @@ protected function createPayoutClient() protected function createReviewPayoutClient() { // load settings from .ini file - $settings = $this->_loadConfigIni(); + $settings = $this->settings; // validate username, password and MERCHANTAccount @@ -151,7 +170,7 @@ protected function createReviewPayoutClient() protected function createTerminalCloudAPIClient() { // load settings from .ini file - $settings = $this->_loadConfigIni(); + $settings = $this->settings; if(!isset($settings['x-api-key']) || !isset($settings['POIID']) || $settings['x-api-key'] == 'YOUR X-API KEY' || $settings['POIID'] == 'UNIQUETERMINALID'){ $this->_skipTest("Skipped the test. Configure your x-api-key and POIID in the config"); @@ -171,7 +190,7 @@ protected function createClientWithMerchantAccount() $client = $this->createClient(); // load settings from .ini file - $settings = $this->_loadConfigIni(); + $settings = $this->settings; if(!isset($settings['merchantAccount']) || $settings['merchantAccount'] == 'YOUR MERCHANTACCOUNT') { $this->_skipTest("Skipped the test. Configure your MerchantAccount in the config"); @@ -184,7 +203,7 @@ protected function createClientWithMerchantAccount() protected function getMerchantAccount() { - $settings = $this->_loadConfigIni(); + $settings = $this->settings; if(!isset($settings['merchantAccount']) || $settings['merchantAccount'] == 'YOUR MERCHANTACCOUNT') { return null; @@ -195,7 +214,7 @@ protected function getMerchantAccount() protected function getSkinCode() { - $settings = $this->_loadConfigIni(); + $settings = $this->settings; if(!isset($settings['skinCode']) || $settings['skinCode'] == 'YOUR SKIN CODE') { return null; @@ -206,7 +225,7 @@ protected function getSkinCode() protected function getHmacSignature() { - $settings = $this->_loadConfigIni(); + $settings = $this->settings; if(!isset($settings['hmacSignature'])|| $settings['hmacSignature'] == 'YOUR HMAC SIGNATURE') { return null; @@ -217,7 +236,7 @@ protected function getHmacSignature() protected function getPOIID() { - $settings = $this->_loadConfigIni(); + $settings = $this->settings; if(!isset($settings['POIID']) || $settings['POIID'] == 'MODEL-SERIALNUMBER') { return null; @@ -226,6 +245,11 @@ protected function getPOIID() return $settings['POIID']; } + /** + * Loads the settings into and array from the config/test.ini file + * + * @return array|bool + */ protected function _loadConfigIni() { return parse_ini_file(__DIR__ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'test.ini', true); @@ -242,7 +266,7 @@ protected function _needSkinCode() { $this->_skipTest("Skipped the test. Configure your SkinCode in the config"); } } - + public function validateApiPermission($e) { // it is possible you do not have permission to use full API then switch over to CSE diff --git a/tests/config/test.ini b/tests/config/test.ini index 2c550e032..b79a75dbe 100644 --- a/tests/config/test.ini +++ b/tests/config/test.ini @@ -10,4 +10,4 @@ POIID = UNIQUETERMINALID storePayoutUsername = YOUR STORE PAYOUT USERNAME storePayoutPassword = "YOUR STORE PAYOUT PASSWORD" reviewPayoutUsername = YOUR REVIEW PAYOUT USERNAME -reviewPayoutPassword = "YOUR REVIEW PAYOUT PASSWORD" +reviewPayoutPassword = "YOUR REVIEW PAYOUT PASSWORD" \ No newline at end of file From c4e32b03bc0a02030b82ce4fa9db072470913aee Mon Sep 17 00:00:00 2001 From: attilak Date: Mon, 22 Oct 2018 14:05:47 +0200 Subject: [PATCH 10/10] Version bump 1.5.2 --- src/Adyen/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Adyen/Client.php b/src/Adyen/Client.php index fa2a43fc1..ed94c860c 100644 --- a/src/Adyen/Client.php +++ b/src/Adyen/Client.php @@ -8,7 +8,7 @@ class Client { - const LIB_VERSION = "1.5.1"; + const LIB_VERSION = "1.5.2"; const LIB_NAME = "adyen-php-api-library"; const USER_AGENT_SUFFIX = "adyen-php-api-library/"; const ENDPOINT_TEST = "https://pal-test.adyen.com";