98 lines
3.1 KiB
PHP
98 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\EventPaymentModules\EventPaymentModuleRegistry;
|
|
use App\Scopes\CommonModel;
|
|
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
|
|
|
/**
|
|
* @property string $id
|
|
* @property string $slug
|
|
*
|
|
* Hinweis: Das Verhalten je Zahlungsart (Options-Schema, Defaults, Zahlung, Rechnung) liegt in den
|
|
* Zahlungsmodulen unter {@see \App\EventPaymentModules}. Dieses Model bleibt eine dünne Fassade, damit
|
|
* bestehende Aufrufstellen (PaymentMethod::optionsFor/... ) unverändert weiterlaufen.
|
|
*/
|
|
class PaymentMethod extends CommonModel
|
|
{
|
|
use HasUuids;
|
|
|
|
public $incrementing = false;
|
|
protected $keyType = 'string';
|
|
|
|
public const string PAYMENT_ACCOUNT_TRANSACTION = 'PAYMENT_ACCOUNT_TRANSACTION';
|
|
public const string PAYMENT_NOT_DEFINED = 'PAYMENT_NOT_DEFINED';
|
|
|
|
protected $fillable = [
|
|
'slug',
|
|
];
|
|
|
|
/**
|
|
* Standard-Werte (name/description) je Slug -- aus den Zahlungsmodulen aufgebaut.
|
|
*
|
|
* @return array<string, array{name: string, description: ?string}>
|
|
*/
|
|
public static function defaults(): array
|
|
{
|
|
$defaults = [];
|
|
foreach (EventPaymentModuleRegistry::all() as $slug => $module) {
|
|
$defaults[$slug] = ['name' => $module->defaultName(), 'description' => $module->defaultDescription()];
|
|
}
|
|
|
|
return $defaults;
|
|
}
|
|
|
|
/**
|
|
* Admin-Options-Schema für einen Slug.
|
|
*
|
|
* @return array<int, array{name: string, label: string, type: string, required: bool}>
|
|
*/
|
|
public static function optionsFor(string $slug): array
|
|
{
|
|
return EventPaymentModuleRegistry::forSlug($slug)?->getOptions() ?? [];
|
|
}
|
|
|
|
/**
|
|
* Teilnehmer-Eingabe-Schema für einen Slug (payer-seitig).
|
|
*
|
|
* @return array<int, array{name: string, label: string, type: string, required: bool}>
|
|
*/
|
|
public static function participantOptionsFor(string $slug): array
|
|
{
|
|
return EventPaymentModuleRegistry::forSlug($slug)?->getParticipantOptions() ?? [];
|
|
}
|
|
|
|
/**
|
|
* Namen aller Pflicht-Optionen eines Slugs.
|
|
*
|
|
* @return array<int, string>
|
|
*/
|
|
public static function requiredOptionKeys(string $slug): array
|
|
{
|
|
return EventPaymentModuleRegistry::forSlug($slug)?->requiredOptionKeys() ?? [];
|
|
}
|
|
|
|
/**
|
|
* Reduziert eine Konfiguration auf die im Schema definierten Options-Keys des Slugs.
|
|
*
|
|
* @param array<string, mixed> $config
|
|
* @return array<string, mixed>
|
|
*/
|
|
public static function sanitizeConfiguration(string $slug, array $config): array
|
|
{
|
|
return EventPaymentModuleRegistry::forSlug($slug)?->sanitizeConfiguration($config) ?? [];
|
|
}
|
|
|
|
/**
|
|
* Prüft, ob alle Pflicht-Optionen eines Slugs in der Konfiguration befüllt (non-empty) sind.
|
|
* Unbekannte Slugs (kein Modul) gelten als vollständig -- kein Modul, keine Pflichtfelder.
|
|
*
|
|
* @param array<string, mixed> $config
|
|
*/
|
|
public static function isConfigurationComplete(string $slug, array $config): bool
|
|
{
|
|
return EventPaymentModuleRegistry::forSlug($slug)?->isConfigurationComplete($config) ?? true;
|
|
}
|
|
}
|