Skip to content

Commit

Permalink
Merge pull request #80 from Adyen/develop
Browse files Browse the repository at this point in the history
Release version 1.5.2
  • Loading branch information
cyattilakiss authored Oct 24, 2018
2 parents 8b5b9df + c4e32b0 commit 9f35128
Show file tree
Hide file tree
Showing 35 changed files with 786 additions and 110 deletions.
41 changes: 37 additions & 4 deletions src/Adyen/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

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";
const ENDPOINT_LIVE = "https://pal-live.adyen.com";
Expand All @@ -26,13 +27,13 @@ class Client
const ENDPOINT_PROTOCOL = "https://";

/**
* @var Adyen_Config $config
* @var \Adyen\Config $config
*/
private $_config;
private $_httpClient;

/**
* @var Adyen_Logger_Abstract $logger
* @var Logger $logger
*/
private $logger;

Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -154,6 +155,29 @@ public function setApplicationName($applicationName)
$this->_config->set('applicationName', $applicationName);
}

/**
* Set external platform name, version and integrator
*
* @param string $name
* @param string $version
* @param string $integrator
*/
public function setExternalPlatform($name, $version, $integrator = "")
{
$this->_config->set('externalPlatform', array('name' => $name, 'version' => $version, 'integrator' => $integrator));
}

/**
* 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
*
Expand All @@ -179,6 +203,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
Expand Down
16 changes: 16 additions & 0 deletions src/Adyen/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/Adyen/HttpClient/CurlClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
115 changes: 102 additions & 13 deletions src/Adyen/Service/AbstractResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,74 @@

class AbstractResource
{

/**
* @var \Adyen\Service
*/
protected $_service;

/**
* @var string
*/
protected $_endpoint;

public function __construct(\Adyen\Service $service, $endpoint)
/**
* @var bool
*/
protected $allowApplicationInfo;

/**
* AbstractResource constructor.
*
* @param \Adyen\Service $service
* @param $endpoint
* @param bool $allowApplicationInfo
*/
public function __construct(\Adyen\Service $service, $endpoint, $allowApplicationInfo = false)
{
$this->_service = $service;
$this->_endpoint = $endpoint;
$this->allowApplicationInfo = $allowApplicationInfo;
}

/**
* 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->handleApplicationInfoInRequest($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
Expand All @@ -50,4 +85,58 @@ public function requestPost($params)
return $curlClient->requestPost($this->_service, $this->_endpoint, $params);
}

}
/**
* 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();
}

return $params;
}

/**
* If allowApplicationInfo is true then it adds applicationInfo to request
* otherwise removes from the request
*
* @param $params
* @return mixed
*/
private function handleApplicationInfoInRequest($params)
{
// 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();

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'];

if (!empty($externalPlatform['integrator'])) {
$params['applicationInfo']['externalPlatform']['integrator'] = $externalPlatform['integrator'];
}
}

} else {
// remove if exists
if (isset($params['applicationInfo'])) {
unset($params['applicationInfo']);
}
}

return $params;
}
}
12 changes: 10 additions & 2 deletions src/Adyen/Service/ResourceModel/Checkout/PaymentMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@

class PaymentMethods extends \Adyen\Service\AbstractCheckoutResource
{
protected $_endpoint;
/**
* @var string
*/
protected $_endpoint;

/**
* 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);
}

}
13 changes: 11 additions & 2 deletions src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@

class PaymentSession extends \Adyen\Service\AbstractCheckoutResource
{
protected $_endpoint;
/**
* @var string
*/
protected $_endpoint;

/**
* 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);
}
}
}
21 changes: 18 additions & 3 deletions src/Adyen/Service/ResourceModel/Checkout/Payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,27 @@

class Payments extends \Adyen\Service\AbstractCheckoutResource
{
/**
* @var string
*/
protected $_endpoint;

protected $_endpoint;
/**
* Include applicationInfo key in the request parameters
*
* @var bool
*/
protected $allowApplicationInfo = true;

/**
* 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->allowApplicationInfo);
}
}
}
12 changes: 10 additions & 2 deletions src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@

class PaymentsDetails extends \Adyen\Service\AbstractCheckoutResource
{
protected $_endpoint;
/**
* @var string
*/
protected $_endpoint;

/**
* 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);
}

}
12 changes: 10 additions & 2 deletions src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@

class PaymentsResult extends \Adyen\Service\AbstractCheckoutResource
{
protected $_endpoint;
/**
* @var string
*/
protected $_endpoint;

/**
* 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);
}

}
Loading

0 comments on commit 9f35128

Please sign in to comment.