Skip to content

Commit

Permalink
Merge branch 'develop' into fix/multiple-calls
Browse files Browse the repository at this point in the history
  • Loading branch information
jillingk authored Jul 10, 2023
2 parents 054620b + d493fc3 commit 072aaf6
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"monolog/monolog": "^1.16 || ^2.0 || ^3.0"
},
"require-dev": {
"dms/phpunit-arraysubset-asserts": "0.4.0",
"dms/phpunit-arraysubset-asserts": "0.5.0",
"friendsofphp/php-cs-fixer": "*",
"phpunit/phpunit": "9.6.7",
"phpunit/phpunit": "9.6.10",
"php-coveralls/php-coveralls": "2.5.3",
"squizlabs/php_codesniffer": "3.7.2"
},
Expand Down
10 changes: 10 additions & 0 deletions src/Adyen/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ public function setHttpProxy($proxy)
$this->config->set('http-proxy', $proxy);
}

/**
* Set the path to a CA bundle file that enables verification using a custom certificate
*
* @param string $certFilePath
*/
public function setSslVerify($certFilePath)
{
$this->config->set('ssl-verify', $certFilePath);
}

/**
* Set environment to connect to test or live platform of Adyen
* For live please specify the unique identifier.
Expand Down
10 changes: 10 additions & 0 deletions src/Adyen/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ public function getHttpProxy()
return !empty($this->data['http-proxy']) ? $this->data['http-proxy'] : null;
}

/**
* Get the path to a CA bundle file that enables verification using a custom certificate
*
* @return mixed|null
*/
public function getSslVerify()
{
return !empty($this->data['ssl-verify']) ? $this->data['ssl-verify'] : null;
}

/**
* @return mixed|string
*/
Expand Down
32 changes: 31 additions & 1 deletion src/Adyen/HttpClient/CurlClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ public function curlSetHttpProxy($ch, $httpProxy)
throw new AdyenException("Invalid proxy configuration " . $httpProxy);
}

$proxy = $urlParts["host"];
$proxy = "";
if (isset($urlParts["scheme"])) {
$proxy = $urlParts["scheme"] . "://";
}
$proxy .= $urlParts["host"];
if (isset($urlParts["port"])) {
$proxy .= ":" . $urlParts["port"];
}
Expand All @@ -90,6 +94,28 @@ public function curlSetHttpProxy($ch, $httpProxy)
}
}

/**
* Set the path to a custom CA bundle in the current curl configuration.
*
* @param resource $ch
* @param string $certFilePath
* @throws AdyenException
*/
public function curlSetSslVerify($ch, $certFilePath)
{
if (empty($certFilePath)) {
return;
}

if (!file_exists($certFilePath)) {
throw new AdyenException("SSL CA bundle not found: {$certFilePath}");
}

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, $certFilePath);
}

/**
* Request to Adyen with query string used for Directory Lookup
*
Expand All @@ -108,6 +134,7 @@ public function requestPost(\Adyen\Service $service, $requestUrl, $params)
$password = $config->getPassword();
$httpProxy = $config->getHttpProxy();
$environment = $config->getEnvironment();
$sslVerify = $config->getSslVerify();

// Log the request
$this->logRequest($logger, $requestUrl, $environment, $params);
Expand All @@ -119,6 +146,7 @@ public function requestPost(\Adyen\Service $service, $requestUrl, $params)
curl_setopt($ch, CURLOPT_POST, 1);

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

// set authorisation
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
Expand Down Expand Up @@ -368,6 +396,7 @@ public function requestHttp(\Adyen\Service $service, $requestUrl, $params, $meth
$xApiKey = $config->getXApiKey();
$httpProxy = $config->getHttpProxy();
$environment = $config->getEnvironment();
$sslVerify = $config->getSslVerify();

$jsonRequest = json_encode($params);

Expand All @@ -394,6 +423,7 @@ public function requestHttp(\Adyen\Service $service, $requestUrl, $params, $meth
}

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

// Create a custom User-Agent
$userAgent = $config->get('applicationName') . " " .
Expand Down

0 comments on commit 072aaf6

Please sign in to comment.