From 11399e74923df81aff789ee8c61a3222b056a211 Mon Sep 17 00:00:00 2001 From: HolgerHatGarKeineNode Date: Mon, 2 Feb 2026 13:37:06 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=92=20Handle=20`UniqueConstraintViolat?= =?UTF-8?q?ionException`=20in=20`createPaymentEvent`=20to=20prevent=20dupl?= =?UTF-8?q?icate=20payment=20events=20creation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../livewire/association/profile.blade.php | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/resources/views/livewire/association/profile.blade.php b/resources/views/livewire/association/profile.blade.php index 5536c81..fc4c5a7 100644 --- a/resources/views/livewire/association/profile.blade.php +++ b/resources/views/livewire/association/profile.blade.php @@ -8,6 +8,7 @@ use App\Support\NostrAuth; use App\Traits\NostrFetcherTrait; use Carbon\Carbon; use Flux\Flux; +use Illuminate\Database\UniqueConstraintViolationException; use Illuminate\Support\Collection; use Illuminate\Support\Str; use Livewire\Component; @@ -469,12 +470,25 @@ new class extends Component { public function createPaymentEvent(): PaymentEvent { + $existing = $this->currentPleb + ->paymentEvents() + ->where('year', date('Y')) + ->first(); + + if ($existing) { + return $existing; + } + if (app()->environment('testing')) { - return $this->currentPleb->paymentEvents()->create([ - 'year' => date('Y'), - 'event_id' => 'test_event_'.Str::uuid(), - 'amount' => $this->amountToPay, - ]); + try { + return $this->currentPleb->paymentEvents()->create([ + 'year' => date('Y'), + 'event_id' => 'test_event_'.Str::uuid(), + 'amount' => $this->amountToPay, + ]); + } catch (UniqueConstraintViolationException) { + return $this->currentPleb->paymentEvents()->where('year', date('Y'))->firstOrFail(); + } } $note = new NostrEvent; @@ -498,11 +512,15 @@ new class extends Component { $relay->setMessage($eventMessage); $result = $relay->send(); - return $this->currentPleb->paymentEvents()->create([ - 'year' => date('Y'), - 'event_id' => $result->eventId, - 'amount' => $this->amountToPay, - ]); + try { + return $this->currentPleb->paymentEvents()->create([ + 'year' => date('Y'), + 'event_id' => $result->eventId, + 'amount' => $this->amountToPay, + ]); + } catch (UniqueConstraintViolationException) { + return $this->currentPleb->paymentEvents()->where('year', date('Y'))->firstOrFail(); + } } public function loadEvents(): void