From ac4f640cdc97ba4a83072a59154bbe68720dd049 Mon Sep 17 00:00:00 2001 From: Jerome Onadja Date: Thu, 23 Dec 2021 17:52:18 +0000 Subject: [PATCH] fix(sdk): fix unable to access undefined property on stdClass --- src/Http/XMLHttp.php | 2 +- src/Sdk/Transaction.php | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Http/XMLHttp.php b/src/Http/XMLHttp.php index fe47451..3ddfc03 100644 --- a/src/Http/XMLHttp.php +++ b/src/Http/XMLHttp.php @@ -38,7 +38,7 @@ public static function request(string $url, array $headers, mixed $body, bool $w return [ $errno, $error, - TransactionResponse::fromXMLResponse(XMLResponse::parse("$response")) + XMLResponse::parse("$response") ]; } diff --git a/src/Sdk/Transaction.php b/src/Sdk/Transaction.php index a4159e3..75219ba 100644 --- a/src/Sdk/Transaction.php +++ b/src/Sdk/Transaction.php @@ -37,12 +37,15 @@ public function on(callable $success, callable $error): mixed /** * @var $errno int * @var $error string - * @var $response TransactionResponse + * @var $response mixed */ [$errno, $errorMessage, $response] = $this->processRequest(); if ($errno > 0) { return $error($errorMessage, $errno); } + + $response = TransactionResponse::fromXMLResponse($response); + if ($response->getStatus() !== 200) { return $error($response->getMessage(), $response->getStatus()); } @@ -58,12 +61,15 @@ public function handleTransaction(): TransactionResponse /** * @var $errno int * @var $errorMessage string - * @var $response TransactionResponse + * @var $response mixed */ [$errno, $errorMessage, $response] = $this->processRequest(); if ($errno > 0) { throw new TransactionException($errorMessage, $errno); } + + $response = TransactionResponse::fromXMLResponse($response); + if ($response->getStatus() !== 200) { throw new TransactionException($response->getMessage(), $response->getStatus()); }