From 7a9ab4acdedc36b0f2e5dc7d61f7281311d91401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=2E=20Nagy=20Gerg=C5=91?= Date: Tue, 20 Feb 2024 14:07:09 +0100 Subject: [PATCH] wip --- src/StripeDriver.php | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/StripeDriver.php b/src/StripeDriver.php index fb446b2..3b7e3e9 100644 --- a/src/StripeDriver.php +++ b/src/StripeDriver.php @@ -206,7 +206,7 @@ public function handleManualRefund(Transaction $transaction): void ], ]); - $transaction->setAttribute('key', $refund->id)->markAsCompleted(); + $transaction->setAttribute('key', $refund->id)->save(); } /** @@ -246,15 +246,20 @@ public function handleIrn(Event $event): void $order = $this->resolveOrderForNotification($event); foreach ($event->data['object']['refunds']['data'] as $refund) { - if (is_null($order->transactions->firstWhere('key', $refund['id']))) { - $transaction = $this->refund( - $order, - $refund['amount'] / 100, - ['key' => $refund['id']] - ); - - $transaction->markAsCompleted(); - } + $transaction = $order->refunds->first( + static function (Transaction $transaction) use ($refund): bool { + return $transaction->key === $refund['id']; + }, + function () use ($order, $refund): Transaction { + return $this->refund( + $order, + $refund['amount'] / 100, + ['key' => $refund['id']] + ); + } + ); + + $transaction->markAsCompleted(); } } }