48 lines
1.6 KiB
PHP
48 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Repositories;
|
|
|
|
use App\Models\AvailablePaymentMethod;
|
|
use App\Models\Event;
|
|
use App\Models\PaymentMethod;
|
|
|
|
/**
|
|
* Zugriff auf die Zahlungsmethoden-Instanzen des Mandanten.
|
|
*
|
|
* Existiert, damit die Zahlungsmodule DB-frei bleiben können: Sie bekommen ihre Konfiguration als
|
|
* Array hereingereicht ({@see \App\EventPaymentModules\ProvidesStatementRuleset}) und holen sie sich
|
|
* nicht selbst -- sonst bräuchte jeder Modul-Unit-Test eine Datenbank.
|
|
*/
|
|
class PaymentMethodRepository
|
|
{
|
|
/**
|
|
* Konfiguration einer Zahlungsart beim aktuellen Mandanten. Der Tenant-Filter kommt vom SiteScope.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function tenantConfiguration(string $slug): array
|
|
{
|
|
return (array) (AvailablePaymentMethod::where('slug', $slug)->first()?->configuration ?? []);
|
|
}
|
|
|
|
/**
|
|
* Darf bei dieser Veranstaltung mit dieser Zahlungsart angemeldet werden?
|
|
*
|
|
* Nur wenn sie der Veranstaltung zugewiesen ist, beim Mandanten aktiv ist und ihre Config am Event
|
|
* vollständig und gültig ist. Sonst ließe sich über einen manipulierten Request eine Zahlungsart
|
|
* wählen, für die die Angaben zur Zahlung fehlen -- bei der Lastschrift etwa die Gläubiger-ID.
|
|
*/
|
|
public function isUsableForSignUp(Event $event, string $slug): bool
|
|
{
|
|
$method = $event->paymentMethods()->where('available_payment_methods.slug', $slug)->first();
|
|
|
|
if ($method === null || !$method->active) {
|
|
return false;
|
|
}
|
|
|
|
return PaymentMethod::isConfigurationComplete($slug, (array) ($method->pivot->configuration ?? []));
|
|
}
|
|
}
|