diff --git a/src/Client.php b/src/Client.php index 0a84d7b..9fbf731 100644 --- a/src/Client.php +++ b/src/Client.php @@ -41,7 +41,7 @@ class Client /** * Sets a request header for the cURL request. - * + * * @param string $name The name of the header. Must not be empty. * @param string $value The value of the header. Must not be empty. */ @@ -60,7 +60,7 @@ private function setRequestHeader($name, $value) /** * Returns the request headers as an array of strings formatted as "Name: Value". - * + * * @return array An array of request headers formatted as "Name: Value". */ private function getRequestHeaders() @@ -122,7 +122,7 @@ public function startSolicitation($order) $this->setRequestHeader(self::HEADER_SEQURA_MERCHANT_ID, $order['merchant']['id'] ?? ''); $this->verbThePayload('POST', array('order' => $order)); $this->dealWithResponse(); - curl_close($this->ch); + $this->closeCurlHandle(); } public function qualifyForSolicitation($order) @@ -139,11 +139,11 @@ public function qualifyForSolicitation($order) /** * Retrieves the identification form for a given URI and options. - * + * * @param string $uri The URI to retrieve the identification form from. * @param array $options An associative array of options for the form. * @param string $merchant_id The merchant ID to be used in the request. - * + * * @return string The HTML content of the identification form. */ public function getIdentificationForm($uri, $options = array(), $merchant_id = '') @@ -158,7 +158,7 @@ public function getIdentificationForm($uri, $options = array(), $merchant_id = ' $this->sendRequest(); $this->dealWithResponse(); - curl_close($this->ch); + $this->closeCurlHandle(); return $this->curl_result; } @@ -171,7 +171,7 @@ public function sendIdentificationForm($uri, $options = array(), $merchant_id = $this->setRequestHeader(self::HEADER_SEQURA_MERCHANT_ID, $merchant_id); $this->verbThePayload('POST', $options); $this->dealWithResponse(); - curl_close($this->ch); + $this->closeCurlHandle(); return $this->curl_result; } @@ -185,7 +185,7 @@ public function startCards($order) $this->setRequestHeader(self::HEADER_SEQURA_MERCHANT_ID, $order['merchant']['id'] ?? ''); $this->verbThePayload('POST', array('order' => $order)); $this->dealWithResponse(); - curl_close($this->ch); + $this->closeCurlHandle(); } public function getCardsForm($uri, $options = array(), $merchant_id = '') @@ -198,7 +198,7 @@ public function getCardsForm($uri, $options = array(), $merchant_id = '') $this->sendRequest(); $this->dealWithResponse(); - curl_close($this->ch); + $this->closeCurlHandle(); } public function qualifyForstartCards($order) @@ -230,7 +230,7 @@ public function getPaymentMethods($uri, $options = array(), $merchant_id = '') curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, 'GET'); $this->sendRequest(); $this->dealWithResponse(); - curl_close($this->ch); + $this->closeCurlHandle(); } public function getAvailableDisbursements($merchant_id) @@ -243,7 +243,7 @@ public function getAvailableDisbursements($merchant_id) $this->sendRequest(); $this->dealWithResponse(); - curl_close($this->ch); + $this->closeCurlHandle(); } public function getDisbursementDetails($path) @@ -259,7 +259,7 @@ public function getDisbursementDetails($path) $this->sendRequest(); $this->dealWithResponse(); - curl_close($this->ch); + $this->closeCurlHandle(); } public function getCreditAgreements($amount, $merchant_id, $locale = 'es-ES', $country = 'ES', $currency = 'EUR') @@ -277,7 +277,7 @@ public function getCreditAgreements($amount, $merchant_id, $locale = 'es-ES', $c curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, 'GET'); $this->sendRequest(); $this->dealWithResponse(); - curl_close($this->ch); + $this->closeCurlHandle(); } public function updateOrder($uri, $order, $verb = 'PUT') @@ -292,7 +292,7 @@ public function updateOrder($uri, $order, $verb = 'PUT') if ($this->status == 409) { $this->cart_has_changed = true; } - curl_close($this->ch); + $this->closeCurlHandle(); } public function sendDeliveryReport($delivery_report) @@ -301,7 +301,7 @@ public function sendDeliveryReport($delivery_report) $this->setRequestHeader(self::HEADER_SEQURA_MERCHANT_ID, $delivery_report['merchant']['id'] ?? ''); $this->verbThePayload('POST', array('delivery_report' => $delivery_report)); $this->dealWithResponse(); - curl_close($this->ch); + $this->closeCurlHandle(); } public function orderUpdate($order) @@ -316,7 +316,7 @@ public function orderUpdate($order) if ($this->status == 409) { $this->cart_has_changed = true; } - curl_close($this->ch); + $this->closeCurlHandle(); } public function callCron($cron_url) @@ -326,7 +326,7 @@ public function callCron($cron_url) curl_setopt($this->ch, CURLOPT_HTTPGET, 1); curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false); $this->sendRequest(); - curl_close($this->ch); + $this->closeCurlHandle(); } public function succeeded() @@ -375,9 +375,24 @@ public function dump() // Private methods below + /** + * Releases the cURL handle after a request. + * On PHP < 8.0 the resource must be explicitly closed; on PHP 8.0+ the + * CurlHandle object is reference-counted, so we simply null the property + * to let it be garbage-collected and avoid the curl_close() deprecation + * introduced in PHP 8.5. + */ + private function closeCurlHandle() + { + if (PHP_VERSION_ID < 80000) { + curl_close($this->ch); + } + $this->ch = null; + } + /** * Initializes the cURL session with the given URL and sets the necessary options. - * + * * @param string $url The URL to initialize the cURL session with. */ private function initCurl($url) diff --git a/tests/ClientTest.php b/tests/ClientTest.php index d8885cf..460d689 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -80,6 +80,29 @@ public function testGetPaymentMethods(): void ); } + public function testNoCurlCloseDeprecationOnPhp85Plus(): void + { + if (PHP_VERSION_ID < 80500) { + $this->markTestSkipped('curl_close() deprecation notices only apply to PHP 8.5+'); + } + + set_error_handler(function (int $errno, string $errstr): bool { + if ($errno === E_DEPRECATED) { + $this->fail("Unexpected E_DEPRECATED notice triggered: $errstr"); + } + return false; + }); + + try { + $client = new Client(self::$username, self::$password, self::$endpoint); + $client->getAvailableDisbursements(self::$merchant); + } finally { + restore_error_handler(); + } + + $this->assertTrue(true); // reached here without any deprecation notice + } + private function createOrder($client): string { $order = json_decode(