Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 33 additions & 18 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -60,7 +60,7 @@ private function setRequestHeader($name, $value)

/**
* Returns the request headers as an array of strings formatted as "Name: Value".
*
*
* @return array<string> An array of request headers formatted as "Name: Value".
*/
private function getRequestHeaders()
Expand Down Expand Up @@ -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)
Expand All @@ -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 = '')
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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 = '')
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -243,7 +243,7 @@ public function getAvailableDisbursements($merchant_id)

$this->sendRequest();
$this->dealWithResponse();
curl_close($this->ch);
$this->closeCurlHandle();
}

public function getDisbursementDetails($path)
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
23 changes: 23 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down