diff --git a/src/StripeDriver.php b/src/StripeDriver.php index 8ae3b01..e94cd12 100644 --- a/src/StripeDriver.php +++ b/src/StripeDriver.php @@ -15,7 +15,6 @@ use Stripe\Event; use Stripe\StripeClient; use Stripe\Webhook; -use Throwable; class StripeDriver extends Driver { @@ -225,15 +224,16 @@ public function handleIpn(Event $event): void { $order = $this->resolveOrderForNotification($event); - try { - $transaction = Transaction::proxy()->newQuery()->where('key', $event->data['object']['id'])->firstOrFail(); - } catch (Throwable $exception) { - $transaction = $this->pay( - $order, - $event->data['object']['amount'] / 100, - ['key' => $event->data['object']['id']] - ); - } + $transaction = Transaction::proxy() + ->newQuery() + ->where('key', $event->data['object']['id']) + ->firstOr(function () use ($order, $event): Transaction { + return $this->pay( + $order, + $event->data['object']['amount'] / 100, + ['key' => $event->data['object']['id']] + ); + }); $transaction->markAsCompleted(); }