Skip to content

Commit

Permalink
Refactor response handling in payment re-query
Browse files Browse the repository at this point in the history
  • Loading branch information
damms005 committed Oct 25, 2024
1 parent 75afcad commit 5f4996f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/Services/PaymentHandlers/Paystack.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Services/PaymentHandlers/Remita.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}

Expand Down
6 changes: 5 additions & 1 deletion src/ValueObjects/ReQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {}
}
6 changes: 3 additions & 3 deletions tests/PaymentRequeryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
$mock->expects('reQuery')->andReturn(
new ReQuery(
payment: new Payment(),
responseDescription: 'Successful',
responseDetails: ['status' => 'Successful'],
),
);

Expand All @@ -52,7 +52,7 @@
$mock->expects('reQuery')->andReturn(
new ReQuery(
payment: new Payment(['is_success' => true]),
responseDescription: 'Successful',
responseDetails: ['status' => 'Successful'],
),
);

Expand All @@ -76,7 +76,7 @@
$mock->expects('reQuery')->andReturn(
new ReQuery(
payment: new Payment(['is_success' => false]),
responseDescription: 'Went South!',
responseDetails: ['status' => 'Went South!'],
),
);

Expand Down

0 comments on commit 5f4996f

Please sign in to comment.