diff --git a/src/Nuvei/Api/Config.php b/src/Nuvei/Api/Config.php index 79f84cf..ab3c6c9 100644 --- a/src/Nuvei/Api/Config.php +++ b/src/Nuvei/Api/Config.php @@ -247,6 +247,50 @@ public function sslVerifyPeer() return true; } + /** + * @param int $timeout + * + * @return $this + */ + public function setTimeout($timeout) + { + $this->configData['timeout'] = (int)$timeout; + return $this; + } + + /** + * @return int + */ + public function getTimeout() + { + if (!isset($this->configData['timeout'])) { + return 0; + } + return (int)$this->configData['timeout']; + } + + /** + * @param int $timeout + * + * @return $this + */ + public function setConnectionTimeout($timeout) + { + $this->configData['connectionTimeout'] = (int)$timeout; + return $this; + } + + /** + * @return int + */ + public function getConnectionTimeout() + { + if (!isset($this->configData['connectionTimeout'])) { + return 0; + } + return (int)$this->configData['connectionTimeout']; + } + /** * @return boolean */ diff --git a/src/Nuvei/Api/HttpClient.php b/src/Nuvei/Api/HttpClient.php index 4bc27af..ed3eab6 100644 --- a/src/Nuvei/Api/HttpClient.php +++ b/src/Nuvei/Api/HttpClient.php @@ -48,6 +48,9 @@ public function requestJson(ServiceInterface $service, $requestUrl, $params) curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); } + // set timeouts + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $config->getConnectionTimeout()); + curl_setopt($ch, CURLOPT_TIMEOUT, $config->getTimeout()); //Tell cURL that we want to send a POST request. curl_setopt($ch, CURLOPT_POST, 1); // set authorisation diff --git a/tests/TestCaseHelper.php b/tests/TestCaseHelper.php index 62229e3..7bd54c5 100644 --- a/tests/TestCaseHelper.php +++ b/tests/TestCaseHelper.php @@ -49,6 +49,8 @@ public static function getClient() 'merchantSiteId' => $config['merchantSiteId'], 'merchantSecretKey' => $config['merchantSecretKey'], 'hashAlgorithm' => $config['hashAlgorithm'], + 'timeout' => $config['timeout'], + 'connectionTimeout' => $config['connectionTimeout'], 'debugMode' => $config['debugMode'], ]); @@ -335,4 +337,4 @@ public static function generateMinimalWithdrawalOrder($amount = 0.01) : array $service = new Processing(self::getClient()); return $service->placeWithdrawalOrder($params); } -} \ No newline at end of file +} diff --git a/tests/config.ini b/tests/config.ini index f9284f9..7b9903e 100644 --- a/tests/config.ini +++ b/tests/config.ini @@ -4,4 +4,6 @@ merchantId = '5078248497400694938' merchantSiteId = '142163' merchantSecretKey = 'F0EpuOTjZPIKw5SGcNGyISClL1zaVnArABS65EkfUIwVmzgNbEiiQeesGp4N79Rg' hashAlgorithm = 'sha256' -debugMode = false \ No newline at end of file +timeout = 15 +connectionTimeout = 5 +debugMode = false