From 27518274b5ee097354b00ea7ec4f746c1a676b24 Mon Sep 17 00:00:00 2001 From: Rene Korss Date: Fri, 3 Feb 2023 16:01:31 +0200 Subject: [PATCH] Add PHP 8 support --- src/Protocol/IPizza.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Protocol/IPizza.php b/src/Protocol/IPizza.php index 512378f..a074403 100644 --- a/src/Protocol/IPizza.php +++ b/src/Protocol/IPizza.php @@ -178,7 +178,7 @@ public function __construct( $this->requestUrl = $requestUrl; // Detect which service to use - if (strlen($sellerName) > 0 && strlen($sellerAccount) > 0) { + if (is_string($sellerName) && strlen($sellerName) > 0 && is_string($sellerAccount) && strlen($sellerAccount) > 0) { $this->serviceId = Services::PAYMENT_REQUEST_1011; return; } @@ -443,7 +443,11 @@ public function getSignature(array $data, string $encoding = 'UTF-8') : string } openssl_sign($mac, $signature, $privateKey, $this->algorithm); - openssl_free_key($privateKey); + + // Only needed if < PHP 8 + if (version_compare(PHP_VERSION, '8.0.0', '<')) { + openssl_free_key($privateKey); + } $result = base64_encode($signature); @@ -512,7 +516,11 @@ protected function validateSignature(array $response, string $encoding = 'UTF-8' } $this->result = openssl_verify($data, base64_decode($response[static::FIELD_MAC]), $publicKey, $this->algorithm); - openssl_free_key($publicKey); + + // Only needed if < PHP 8 + if (version_compare(PHP_VERSION, '8.0.0', '<')) { + openssl_free_key($publicKey); + } return $this->result === 1; }