Configurations for payment modules

This commit is contained in:
2026-07-29 12:37:48 +02:00
parent ab3d526217
commit 29db141b84
19 changed files with 436 additions and 19 deletions
@@ -64,6 +64,7 @@ class CreateEventCommand {
EventPaymentMethods::create([
'event_id' => $event->id,
'slug' => $availablePaymentMethod->slug,
'configuration' => $availablePaymentMethod->configuration ?? [],
]);
}
@@ -2,6 +2,10 @@
namespace App\Domains\Event\Actions\UpdateEvent;
use App\Models\AvailablePaymentMethod;
use App\Models\PaymentMethod;
use App\RelationModels\EventPaymentMethods;
class UpdateEventCommand {
public UpdateEventRequest $request;
public function __construct(UpdateEventRequest $request) {
@@ -32,7 +36,6 @@ class UpdateEventCommand {
$this->request->event->resetAllowedEatingHabits();
$this->request->event->resetContributingLocalGroups();
$this->request->event->resetPaymentMethods();
foreach($this->request->eatingHabits as $eatingHabit) {
$this->request->event->eatingHabits()->attach($eatingHabit);
@@ -42,13 +45,58 @@ class UpdateEventCommand {
$this->request->event->localGroups()->attach($contributingLocalGroup);
}
foreach($this->request->paymentMethods as $paymentMethod) {
$this->request->event->paymentMethods()->attach($paymentMethod);
}
$this->syncPaymentMethods();
$this->request->event->save();
$response->success = true;
return $response;
}
/**
* Differenzieller Sync der Zahlungsmethoden mit Snapshot-Copy-Semantik:
* - entfernte Methoden werden gelöscht,
* - neue Methoden erhalten einen Snapshot der Tenant-Config (oder eines expliziten Overrides),
* - bestehende Methoden behalten ihre pro-Event-Config, sofern kein Override übergeben wird.
*/
private function syncPaymentMethods(): void
{
$event = $this->request->event;
$desiredSlugs = $this->request->paymentMethods;
$overrides = $this->request->paymentMethodConfigurations;
$existing = EventPaymentMethods::where('event_id', $event->id)->get()->keyBy('slug');
// Nicht mehr gewünschte Methoden entfernen.
foreach ($existing as $slug => $row) {
if (!in_array($slug, $desiredSlugs, true)) {
$row->delete();
}
}
// Tenant-Instanzen (für Snapshot-Kopie neuer Methoden) laden.
$tenantMethods = AvailablePaymentMethod::whereIn('slug', $desiredSlugs)->get()->keyBy('slug');
foreach ($desiredSlugs as $slug) {
$override = $overrides[$slug] ?? null;
if (isset($existing[$slug])) {
// Bestehende Zuweisung: Config nur bei explizitem Override anpassen, sonst unverändert lassen.
if ($override !== null) {
$row = $existing[$slug];
$row->configuration = PaymentMethod::sanitizeConfiguration($slug, $override);
$row->save();
}
continue;
}
// Neue Zuweisung: expliziter Override oder Snapshot der Tenant-Config.
$snapshot = $override ?? ($tenantMethods[$slug]->configuration ?? []);
EventPaymentMethods::create([
'event_id' => $event->id,
'slug' => $slug,
'configuration' => PaymentMethod::sanitizeConfiguration($slug, $snapshot ?? []),
]);
}
}
}
@@ -23,7 +23,16 @@ class UpdateEventRequest {
public array $eatingHabits;
public array $paymentMethods;
public function __construct(Event $event, string $eventName, string $eventLocation, string $postalCode, string $email, DateTime $earlyBirdEnd, DateTime $registrationFinalEnd, int $alcoholicsAge, bool $sendWeeklyReports, bool $registrationAllowed, Amount $flatSupport, Amount $supportPerPerson, array $contributingLocalGroups, array $eatingHabits, array $paymentMethods) {
/**
* Optionale pro-Event-Config-Overrides je Zahlungsmethode: [slug => [option => value]].
* Fehlt ein Slug, bleibt die bestehende Config erhalten bzw. wird beim ersten Zuweisen
* aus der Tenant-Config als Snapshot kopiert.
*
* @var array<string, array<string, mixed>>
*/
public array $paymentMethodConfigurations;
public function __construct(Event $event, string $eventName, string $eventLocation, string $postalCode, string $email, DateTime $earlyBirdEnd, DateTime $registrationFinalEnd, int $alcoholicsAge, bool $sendWeeklyReports, bool $registrationAllowed, Amount $flatSupport, Amount $supportPerPerson, array $contributingLocalGroups, array $eatingHabits, array $paymentMethods, array $paymentMethodConfigurations = []) {
$this->event = $event;
$this->eventName = $eventName;
$this->eventLocation = $eventLocation;
@@ -39,5 +48,6 @@ class UpdateEventRequest {
$this->contributingLocalGroups = $contributingLocalGroups;
$this->eatingHabits = $eatingHabits;
$this->paymentMethods = $paymentMethods;
$this->paymentMethodConfigurations = $paymentMethodConfigurations;
}
}