Skip to content

Commit 84f1b7f

Browse files
committed
refactor: streamline constructor syntax and improve code readability across event classes and drivers
1 parent 75b8795 commit 84f1b7f

11 files changed

Lines changed: 18 additions & 22 deletions

src/Drivers/AbstractDriver.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ public function __construct(
2929
protected array $config,
3030
protected Dispatcher $events,
3131
protected LoggerInterface $logger,
32-
) {
33-
}
32+
) {}
3433

3534
abstract public function name(): string;
3635

@@ -56,6 +55,7 @@ final public function pay(PaymentRequest $request): PaymentResponse
5655
try {
5756
$response = $this->executePayment($request, $txn);
5857
$this->applyResponse($txn, $response);
58+
5959
return $response;
6060
} catch (Throwable $e) {
6161
return $this->handleFailure($txn, $e);
@@ -67,6 +67,7 @@ final public function status(Transaction $transaction): StatusResponse
6767
$response = $this->executeStatus($transaction);
6868
$transaction->refreshFromStatus($response);
6969
$this->events->dispatch(new PaymentStatusChecked($transaction, $response));
70+
7071
return $response;
7172
}
7273

@@ -83,6 +84,7 @@ protected function credential(string $key, mixed $default = null): mixed
8384
protected function baseUrl(): string
8485
{
8586
$key = $this->mode() === 'live' ? 'live_url' : 'sandbox_url';
87+
8688
return (string) ($this->config[$key] ?? '');
8789
}
8890

@@ -189,12 +191,14 @@ protected function extractError(Throwable $e): array
189191
$e->providerErrorMessage() ?? $e->getMessage(),
190192
];
191193
}
194+
192195
return ['PROVIDER_FAILURE', $e->getMessage()];
193196
}
194197

195198
protected function throwsExceptions(): bool
196199
{
197200
$flag = config('payify.throw_exceptions');
201+
198202
return $flag ?? (bool) config('app.debug');
199203
}
200204

src/Drivers/FakeDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Illuminate\Http\Request;
1818
use Illuminate\Support\Str;
1919

20-
class FakeDriver extends AbstractDriver implements SupportsRefund, SupportsHostedCheckout, HandlesWebhook
20+
class FakeDriver extends AbstractDriver implements HandlesWebhook, SupportsHostedCheckout, SupportsRefund
2121
{
2222
public function name(): string
2323
{

src/Events/PaymentCancelled.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,5 @@ class PaymentCancelled
1111
use Dispatchable;
1212
use SerializesModels;
1313

14-
public function __construct(public Transaction $transaction)
15-
{
16-
}
14+
public function __construct(public Transaction $transaction) {}
1715
}

src/Events/PaymentFailed.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ public function __construct(
1515
public Transaction $transaction,
1616
public string $errorCode,
1717
public string $errorMessage,
18-
) {
19-
}
18+
) {}
2019
}

src/Events/PaymentInitiated.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,5 @@ class PaymentInitiated
1111
use Dispatchable;
1212
use SerializesModels;
1313

14-
public function __construct(public Transaction $transaction)
15-
{
16-
}
14+
public function __construct(public Transaction $transaction) {}
1715
}

src/Events/PaymentRefunded.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ class PaymentRefunded
1515
public function __construct(
1616
public Transaction $transaction,
1717
public RefundResponse $refund,
18-
) {
19-
}
18+
) {}
2019
}

src/Events/PaymentStatusChecked.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ class PaymentStatusChecked
1515
public function __construct(
1616
public Transaction $transaction,
1717
public StatusResponse $status,
18-
) {
19-
}
18+
) {}
2019
}

src/Events/PaymentSucceeded.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,5 @@ class PaymentSucceeded
1111
use Dispatchable;
1212
use SerializesModels;
1313

14-
public function __construct(public Transaction $transaction)
15-
{
16-
}
14+
public function __construct(public Transaction $transaction) {}
1715
}

src/Events/WebhookReceived.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ class WebhookReceived
1515
public function __construct(
1616
public WebhookPayload $payload,
1717
public ?Transaction $transaction,
18-
) {
19-
}
18+
) {}
2019
}

tests/Feature/Drivers/FakeDriverTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use GuzzleHttp\Handler\MockHandler;
1414
use GuzzleHttp\HandlerStack;
1515
use Illuminate\Foundation\Testing\RefreshDatabase;
16+
use Illuminate\Http\Request;
1617
use Illuminate\Support\Facades\Event;
1718
use Illuminate\Support\Facades\Log;
1819

@@ -75,7 +76,7 @@ function makeFakeDriver(array $config = []): FakeDriver
7576

7677
it('verifies webhooks unconditionally', function () {
7778
$driver = makeFakeDriver();
78-
$req = new \Illuminate\Http\Request(query: [], request: [
79+
$req = new Request(query: [], request: [
7980
'event' => 'payment.succeeded',
8081
'reference' => 'INV-WH',
8182
'provider_transaction_id' => 'pay_1',

0 commit comments

Comments
 (0)