From 34652ee5ee3c50fef3e25a498cd52d22bf94521d Mon Sep 17 00:00:00 2001 From: Sai Asish Y Date: Wed, 17 Jun 2026 21:02:39 -0700 Subject: [PATCH] Avoid undefined array key warnings when parsing HPP responses without uppercase keys Signed-off-by: Sai Asish Y --- src/Services/HostedService.php | 12 +++++----- .../Gateways/GpEcomConnector/HppTest.php | 24 +++++++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/Services/HostedService.php b/src/Services/HostedService.php index 113136b0..74f02b72 100644 --- a/src/Services/HostedService.php +++ b/src/Services/HostedService.php @@ -141,12 +141,12 @@ public function parseResponse($response, $encoded = false) $response = $this->mapTransactionStatusResponse($response); } - $timestamp = $response["TIMESTAMP"]; - $merchantId = $response["MERCHANT_ID"]; - $orderId = $response["ORDER_ID"]; - $result = $response["RESULT"]; - $message = $response["MESSAGE"]; - $transactionId = $response["PASREF"]; + $timestamp = $response["TIMESTAMP"] ?? ""; + $merchantId = $response["MERCHANT_ID"] ?? ""; + $orderId = $response["ORDER_ID"] ?? ""; + $result = $response["RESULT"] ?? ""; + $message = $response["MESSAGE"] ?? ""; + $transactionId = $response["PASREF"] ?? ""; $authCode = $response["AUTHCODE"] ?? ""; $paymentMethod = $response["PAYMENTMETHOD"] ?? ""; diff --git a/test/Integration/Gateways/GpEcomConnector/HppTest.php b/test/Integration/Gateways/GpEcomConnector/HppTest.php index bc19e545..56062b2e 100644 --- a/test/Integration/Gateways/GpEcomConnector/HppTest.php +++ b/test/Integration/Gateways/GpEcomConnector/HppTest.php @@ -1099,6 +1099,30 @@ public function testProcessPaymentConsumeResponse() $this->assertEquals("00", $responseCode); } + public function testParseResponseWithoutUppercaseKeysDoesNotWarn() + { + $service = new HostedService($this->config()); + + $response = []; + $response["SHA1HASH"] = GenerationUtils::generateNewHash( + "secret", + implode('.', ["", "", "", "", "", "", ""]), + ShaHashType::SHA1 + ); + + set_error_handler(function ($errno, $errstr) { + throw new \ErrorException($errstr); + }); + try { + $parsedResponse = $service->parseResponse(json_encode($response)); + } finally { + restore_error_handler(); + } + + $this->assertNotNull($parsedResponse); + $this->assertEquals("", $parsedResponse->responseCode); + } + /* 06. CardStorageCreatePayerStoreCardResponse */ public function testCardStorageCreatePayerStoreCardResponse()