Skip to content

Commit 2840874

Browse files
authored
Merge pull request #756 from Adyen/DR-1284
[DR-1284] Add CURLOPT_CONNECTTIMEOUT setting and define default values for timeouts
2 parents 34ccb68 + e9b6719 commit 2840874

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

src/Adyen/Client.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class Client
4949
const MANAGEMENT_API_TEST = "https://management-test.adyen.com";
5050
const MANAGEMENT_API_LIVE = "https://management-live.adyen.com";
5151
const MANAGEMENT_API = "v1";
52+
const DEFAULT_CURLOPT_TIMEOUT = 60;
53+
const DEFAULT_CURLOPT_CONNECTTIMEOUT = 30;
5254

5355
/**
5456
* @var Config
@@ -299,6 +301,14 @@ public function setTimeout($value)
299301
$this->config->set('timeout', $value);
300302
}
301303

304+
/**
305+
* @param $value
306+
*/
307+
public function setConnectionTimeout($value)
308+
{
309+
$this->config->set('connectionTimeout', $value);
310+
}
311+
302312
/**
303313
* Get the library name
304314
*

src/Adyen/Config.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,19 @@ public function getOutputType()
141141
*/
142142
public function getTimeout()
143143
{
144-
return !empty($this->data['timeout']) ? $this->data['timeout'] : null;
144+
return !empty($this->data['timeout']) ?
145+
$this->data['timeout'] :
146+
Client::DEFAULT_CURLOPT_TIMEOUT;
147+
}
148+
149+
/**
150+
* @return mixed|null
151+
*/
152+
public function getConnectionTimeout()
153+
{
154+
return !empty($this->data['connectionTimeout']) ?
155+
$this->data['connectionTimeout'] :
156+
Client::DEFAULT_CURLOPT_CONNECTTIMEOUT;
145157
}
146158

147159
/**

src/Adyen/HttpClient/CurlClient.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,11 @@ public function requestHttp(Service $service, $requestUrl, $params, $method, $re
336336
curl_setopt($ch, CURLOPT_TIMEOUT, $config->getTimeout());
337337
}
338338

339+
// Set the connection timeout
340+
if ($config->getConnectionTimeout() != null) {
341+
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $config->getConnectionTimeout());
342+
}
343+
339344
// Set the headers
340345
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
341346

tests/Unit/TestCaseMock.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ protected function createMockClient($jsonFile, $httpStatus, $errno = null, $envi
3232
$client->setApplicationName("My Test Application");
3333
$client->setEnvironment($environment);
3434
$client->setXApiKey("MockAPIKey");
35+
$client->setTimeout(60);
36+
$client->setConnectionTimeout(30);
3537

3638
$json = null;
3739
if ($jsonFile != null) {

0 commit comments

Comments
 (0)