From 5f4996f59e6fa919e8c5f7a5dbb149dc4f0b95d9 Mon Sep 17 00:00:00 2001 From: Damilola Olowookere Date: Fri, 25 Oct 2024 14:08:09 +0100 Subject: [PATCH] Refactor response handling in payment re-query --- src/Services/PaymentHandlers/Paystack.php | 4 ++-- src/Services/PaymentHandlers/Remita.php | 2 +- src/ValueObjects/ReQuery.php | 6 +++++- tests/PaymentRequeryTest.php | 6 +++--- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Services/PaymentHandlers/Paystack.php b/src/Services/PaymentHandlers/Paystack.php index 39a1f35..39e5ec0 100644 --- a/src/Services/PaymentHandlers/Paystack.php +++ b/src/Services/PaymentHandlers/Paystack.php @@ -96,7 +96,7 @@ public function reQuery(Payment $existingPayment): ?ReQuery try { $verificationResponse = $this->verifyPaystackTransaction($existingPayment->processor_transaction_reference); } catch (\Throwable $th) { - return new ReQuery($existingPayment, $th->getMessage()); + return new ReQuery($existingPayment, ['error' => $th->getMessage()]); } // status should be true if there was a successful call @@ -124,7 +124,7 @@ public function reQuery(Payment $existingPayment): ?ReQuery return new ReQuery( payment: $payment, - responseDescription: 'Response from gateway server: ' . json_encode((array)$verificationResponse), + responseDetails: (array)$verificationResponse, ); } diff --git a/src/Services/PaymentHandlers/Remita.php b/src/Services/PaymentHandlers/Remita.php index 166e02c..778b3b2 100644 --- a/src/Services/PaymentHandlers/Remita.php +++ b/src/Services/PaymentHandlers/Remita.php @@ -158,7 +158,7 @@ public function reQuery(Payment $existingPayment): ?ReQuery return new ReQuery( payment: $payment, - responseDescription: 'Response from gateway server: ' . json_encode((array)$rrrQueryResponse), + responseDetails: (array)$rrrQueryResponse, ); } diff --git a/src/ValueObjects/ReQuery.php b/src/ValueObjects/ReQuery.php index 3b215a5..d39fde2 100644 --- a/src/ValueObjects/ReQuery.php +++ b/src/ValueObjects/ReQuery.php @@ -8,6 +8,10 @@ class ReQuery { public function __construct( public Payment $payment, - public string $responseDescription, + + /** + * An array of arbitrary shape based on the specific payment handler. + */ + public array $responseDetails, ) {} } diff --git a/tests/PaymentRequeryTest.php b/tests/PaymentRequeryTest.php index 94cd134..96e54b8 100644 --- a/tests/PaymentRequeryTest.php +++ b/tests/PaymentRequeryTest.php @@ -33,7 +33,7 @@ $mock->expects('reQuery')->andReturn( new ReQuery( payment: new Payment(), - responseDescription: 'Successful', + responseDetails: ['status' => 'Successful'], ), ); @@ -52,7 +52,7 @@ $mock->expects('reQuery')->andReturn( new ReQuery( payment: new Payment(['is_success' => true]), - responseDescription: 'Successful', + responseDetails: ['status' => 'Successful'], ), ); @@ -76,7 +76,7 @@ $mock->expects('reQuery')->andReturn( new ReQuery( payment: new Payment(['is_success' => false]), - responseDescription: 'Went South!', + responseDetails: ['status' => 'Went South!'], ), );