Skip to content

Commit

Permalink
Merge pull request #109 from Adyen/develop
Browse files Browse the repository at this point in the history
Release 2.1.0
  • Loading branch information
Aleffio authored Jun 26, 2019
2 parents cd62774 + 37f048f commit 5452203
Show file tree
Hide file tree
Showing 20 changed files with 484 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ignore config file
/tests/config/*
tests/config

# Ignore the /vendor/ directory
/vendor/
Expand All @@ -11,4 +11,4 @@ composer.lock
.DS_Store

# ignore PhpStorm .idea folder
.idea
.idea
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ matrix:
allow_failures:
- php: nightly
include:
- php: 7.1
- php: 7.3
- php: 7.2
- php: 7.1
- php: 7.0
Expand All @@ -16,4 +16,4 @@ matrix:
- dist: precise
php: 5.3
before_script:
- composer install
- composer install
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
"Adyen\\Tests\\": "tests/"
}
}
}
}
43 changes: 32 additions & 11 deletions src/Adyen/AdyenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,32 @@ class AdyenException extends Exception
*/
protected $errorType;

/**
* AdyenException constructor.
*
* @param string $message
* @param int $code
* @param Exception|null $previous
* @param null $status
* @param null $errorType
*/
public function __construct($message = "", $code = 0, Exception $previous = null, $status = null, $errorType = null)
{
/**
* @var string
*/
protected $pspReference;

/**
* AdyenException constructor.
*
* @param string $message
* @param int $code
* @param Exception|null $previous
* @param null $status
* @param null $errorType
* @param null $pspReference
*/
public function __construct(
$message = "",
$code = 0,
Exception $previous = null,
$status = null,
$errorType = null,
$pspReference = null
) {
$this->status = $status;
$this->errorType = $errorType;
$this->pspReference = $pspReference;
parent::__construct($message, (int)$code, $previous);
}

Expand All @@ -49,4 +62,12 @@ public function getErrorType()
{
return $this->errorType;
}

/**
* @return string
*/
public function getPspReference()
{
return $this->pspReference;
}
}
23 changes: 22 additions & 1 deletion src/Adyen/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class Client
{
const LIB_VERSION = "2.0.0";
const LIB_VERSION = "2.1.0";
const LIB_NAME = "adyen-php-api-library";
const USER_AGENT_SUFFIX = "adyen-php-api-library/";
const ENDPOINT_TEST = "https://pal-test.adyen.com";
Expand All @@ -17,6 +17,7 @@ class Client
const ENDPOINT_TEST_DIRECTORY_LOOKUP = "https://test.adyen.com/hpp/directory/v2.shtml";
const ENDPOINT_LIVE_DIRECTORY_LOOKUP = "https://live.adyen.com/hpp/directory/v2.shtml";
const API_PAYMENT_VERSION = "v40";
const API_BIN_LOOKUP_VERSION = "v40";
const API_PAYOUT_VERSION = "v30";
const API_RECURRING_VERSION = "v25";
const API_CHECKOUT_VERSION = "v41";
Expand Down Expand Up @@ -108,6 +109,16 @@ public function setXApiKey($xApiKey)
$this->config->set('x-api-key', $xApiKey);
}

/**
* Set HTTP proxy information
*
* @param string $proxy
*/
public function setHttpProxy($proxy)
{
$this->config->set('http-proxy', $proxy);
}

/**
* Set environment to connect to test or live platform of Adyen
* For live please specify the unique identifier.
Expand Down Expand Up @@ -269,6 +280,16 @@ public function getApiPaymentVersion()
return self::API_PAYMENT_VERSION;
}

/**
* Get the version of the API BinLookUp endpoint
*
* @return string
*/
public function getApiBinLookupVersion()
{
return self::API_BIN_LOOKUP_VERSION;
}

/**
* Get the version of the API Payout endpoint
*
Expand Down
10 changes: 10 additions & 0 deletions src/Adyen/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ public function getXApiKey()
return !empty($this->data['x-api-key']) ? $this->data['x-api-key'] : null;
}

/**
* Get the http proxy configuration
*
* @return mixed|null
*/
public function getHttpProxy()
{
return !empty($this->data['http-proxy']) ? $this->data['http-proxy'] : null;
}

/**
* @return mixed|string
*/
Expand Down
60 changes: 52 additions & 8 deletions src/Adyen/HttpClient/CurlClient.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

namespace Adyen\HttpClient;
use Adyen\AdyenException;



class CurlClient implements ClientInterface
{
Expand All @@ -11,7 +14,7 @@ class CurlClient implements ClientInterface
* @param $requestUrl
* @param $params
* @return mixed
* @throws \Adyen\AdyenException
* @throws AdyenException
*/
public function requestJson(\Adyen\Service $service, $requestUrl, $params)
{
Expand All @@ -21,6 +24,7 @@ public function requestJson(\Adyen\Service $service, $requestUrl, $params)
$username = $config->getUsername();
$password = $config->getPassword();
$xApiKey = $config->getXApiKey();
$httpProxy = $config->getHttpProxy();

$jsonRequest = json_encode($params);

Expand All @@ -36,6 +40,8 @@ public function requestJson(\Adyen\Service $service, $requestUrl, $params)
//Attach our encoded JSON string to the POST fields.
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonRequest);

$this->curlSetHttpProxy($ch, $httpProxy);

//create a custom User-Agent
$userAgent = $config->get('applicationName') . " " . \Adyen\Client::USER_AGENT_SUFFIX . $client->getLibraryVersion();

Expand All @@ -51,7 +57,7 @@ public function requestJson(\Adyen\Service $service, $requestUrl, $params)
$headers[] = 'x-api-key: ' . $xApiKey;
} elseif ($service->requiresApiKey()) {
$msg = "Please provide a valid Checkout API Key";
throw new \Adyen\AdyenException($msg);
throw new AdyenException($msg);
} else {

//Set the basic auth credentials
Expand Down Expand Up @@ -101,14 +107,43 @@ public function requestJson(\Adyen\Service $service, $requestUrl, $params)
return $result;
}

/**
* Set httpProxy in the current curl configuration
*
* @param resource $ch
* @param string $httpProxy
* @throws AdyenException
*/
public function curlSetHttpProxy($ch, $httpProxy)
{
if (empty($httpProxy)) {
return;
}

$urlParts = parse_url($httpProxy);
if ($urlParts == false || !array_key_exists("host", $urlParts)) {
throw new AdyenException("Invalid proxy configuration " . $httpProxy);
}

$proxy = $urlParts["host"];
if (isset($urlParts["port"])) {
$proxy .= ":" . $urlParts["port"];
}
curl_setopt($ch, CURLOPT_PROXY, $proxy);

if (isset($urlParts["user"])) {
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $urlParts["user"] . ":" . $urlParts["pass"]);
}
}

/**
* Request to Adyen with query string used for Directory Lookup
*
* @param \Adyen\Service $service
* @param $requestUrl
* @param $params
* @return mixed
* @throws \Adyen\AdyenException
* @throws AdyenException
*/
public function requestPost(\Adyen\Service $service, $requestUrl, $params)
{
Expand All @@ -117,6 +152,7 @@ public function requestPost(\Adyen\Service $service, $requestUrl, $params)
$logger = $client->getLogger();
$username = $config->getUsername();
$password = $config->getPassword();
$httpProxy = $config->getHttpProxy();

// log the requestUr, params and json request
$logger->info("Request url to Adyen: " . $requestUrl);
Expand All @@ -128,6 +164,8 @@ public function requestPost(\Adyen\Service $service, $requestUrl, $params)
//Tell cURL that we want to send a POST request.
curl_setopt($ch, CURLOPT_POST, 1);

$this->curlSetHttpProxy($ch, $httpProxy);

// set authorisation
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
Expand Down Expand Up @@ -173,7 +211,7 @@ public function requestPost(\Adyen\Service $service, $requestUrl, $params)
if (!$result) {
$msg = "The result is empty, looks like your request is invalid";
$logger->error($msg);
throw new \Adyen\AdyenException($msg);
throw new AdyenException($msg);
}

// log the array result
Expand Down Expand Up @@ -224,18 +262,24 @@ protected function handleCurlError($url, $errno, $message, $logger)
*
* @param $result
* @param $logger
* @throws \Adyen\AdyenException
* @throws AdyenException
*/
protected function handleResultError($result, $logger)
{
$decodeResult = json_decode($result, true);
if (isset($decodeResult['message']) && isset($decodeResult['errorCode'])) {
$logger->error($decodeResult['errorCode'] . ': ' . $decodeResult['message']);
throw new \Adyen\AdyenException($decodeResult['message'], $decodeResult['errorCode'], null,
$decodeResult['status'], $decodeResult['errorType']);
throw new AdyenException(
$decodeResult['message'],
$decodeResult['errorCode'],
null,
$decodeResult['status'],
$decodeResult['errorType'],
isset($decodeResult['pspReference']) ? $decodeResult['pspReference'] : null
);
}
$logger->error($result);
throw new \Adyen\AdyenException($result);
throw new AdyenException($result);
}

/**
Expand Down
35 changes: 35 additions & 0 deletions src/Adyen/Service/BinLookup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Adyen\Service;

class BinLookup extends \Adyen\Service
{
/**
* @var ResourceModel\BinLookup\Get3dsAvailability
*/
protected $get3dsAvailability;

/**
* BinLookup constructor.
*
* @param \Adyen\Client $client
* @throws \Adyen\AdyenException
*/
public function __construct(\Adyen\Client $client)
{
parent::__construct($client);
$this->get3dsAvailability = new \Adyen\Service\ResourceModel\BinLookup\Get3dsAvailability($this);
}


/**
* @param $params
* @return mixed
* @throws \Adyen\AdyenException
*/
public function get3dsAvailability($params)
{
$result = $this->get3dsAvailability->request($params);
return $result;
}
}
17 changes: 17 additions & 0 deletions src/Adyen/Service/Modification.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class Modification extends \Adyen\Service
*/
protected $refund;

/**
* @var ResourceModel\Modification\RefundWithData
*/
protected $refundWithData;

/**
* @var ResourceModel\Modification\AdjustAuthorisation
*/
Expand All @@ -42,6 +47,7 @@ public function __construct(\Adyen\Client $client)
$this->cancelOrRefund = new \Adyen\Service\ResourceModel\Modification\CancelOrRefund($this);
$this->capture = new \Adyen\Service\ResourceModel\Modification\Capture($this);
$this->refund = new \Adyen\Service\ResourceModel\Modification\Refund($this);
$this->refundWithData = new \Adyen\Service\ResourceModel\Modification\RefundWithData($this);
$this->adjustAuthorisation = new \Adyen\Service\ResourceModel\Modification\AdjustAuthorisation($this);
}

Expand Down Expand Up @@ -89,6 +95,17 @@ public function refund($params)
return $result;
}

/**
* @param $params
* @return mixed
* @throws \Adyen\AdyenException
*/
public function refundWithData($params)
{
$result = $this->refundWithData->request($params);
return $result;
}

/**
* @param $params
* @return mixed
Expand Down
Loading

0 comments on commit 5452203

Please sign in to comment.