Skip to content

Commit 5f4996f

Browse files
committed
Refactor response handling in payment re-query
1 parent 75afcad commit 5f4996f

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

src/Services/PaymentHandlers/Paystack.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function reQuery(Payment $existingPayment): ?ReQuery
9696
try {
9797
$verificationResponse = $this->verifyPaystackTransaction($existingPayment->processor_transaction_reference);
9898
} catch (\Throwable $th) {
99-
return new ReQuery($existingPayment, $th->getMessage());
99+
return new ReQuery($existingPayment, ['error' => $th->getMessage()]);
100100
}
101101

102102
// status should be true if there was a successful call
@@ -124,7 +124,7 @@ public function reQuery(Payment $existingPayment): ?ReQuery
124124

125125
return new ReQuery(
126126
payment: $payment,
127-
responseDescription: 'Response from gateway server: ' . json_encode((array)$verificationResponse),
127+
responseDetails: (array)$verificationResponse,
128128
);
129129
}
130130

src/Services/PaymentHandlers/Remita.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public function reQuery(Payment $existingPayment): ?ReQuery
158158

159159
return new ReQuery(
160160
payment: $payment,
161-
responseDescription: 'Response from gateway server: ' . json_encode((array)$rrrQueryResponse),
161+
responseDetails: (array)$rrrQueryResponse,
162162
);
163163
}
164164

src/ValueObjects/ReQuery.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ class ReQuery
88
{
99
public function __construct(
1010
public Payment $payment,
11-
public string $responseDescription,
11+
12+
/**
13+
* An array of arbitrary shape based on the specific payment handler.
14+
*/
15+
public array $responseDetails,
1216
) {}
1317
}

tests/PaymentRequeryTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
$mock->expects('reQuery')->andReturn(
3434
new ReQuery(
3535
payment: new Payment(),
36-
responseDescription: 'Successful',
36+
responseDetails: ['status' => 'Successful'],
3737
),
3838
);
3939

@@ -52,7 +52,7 @@
5252
$mock->expects('reQuery')->andReturn(
5353
new ReQuery(
5454
payment: new Payment(['is_success' => true]),
55-
responseDescription: 'Successful',
55+
responseDetails: ['status' => 'Successful'],
5656
),
5757
);
5858

@@ -76,7 +76,7 @@
7676
$mock->expects('reQuery')->andReturn(
7777
new ReQuery(
7878
payment: new Payment(['is_success' => false]),
79-
responseDescription: 'Went South!',
79+
responseDetails: ['status' => 'Went South!'],
8080
),
8181
);
8282

0 commit comments

Comments
 (0)