fix(ledger): PayPal import survives a concurrent run of itself

A manual import overlapping the scheduled one could insert the same PayPal
transaction twice and fail on the unique key. The loser now updates the
row the other run created.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Fabian @ Blax Software 2026-10-07 12:57:11 +02:00
parent 644c84def3
commit e2ea2ff9ab
1 changed files with 13 additions and 1 deletions

View File

@ -172,7 +172,19 @@ class PaypalLedgerService
return 'updated';
}
try {
$model::query()->create($row);
} catch (\Illuminate\Database\QueryException $e) {
// A concurrent import (manual run during the scheduled one) inserted
// the same transaction first: update that row instead.
$existing = $model::query()->where('stripe_id', $row['stripe_id'])->first();
if (! $existing) {
throw $e;
}
$existing->fill($row)->save();
return 'updated';
}
return 'created';
}