Payment methode now selectable
This commit is contained in:
@@ -22,36 +22,83 @@ abstract class AbstractEventPaymentModule implements EventPaymentModule
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Payer-seitige Eingaben, die eine Zahlungsart vom Teilnehmer benötigt (z.B. später SEPA-IBAN,
|
||||
* PayPal-Mail). Standard: keine. Gleiche Form wie getOptions(): [{name,label,type,required}].
|
||||
*
|
||||
* @return array<int, array{name: string, label: string, type: string, required: bool}>
|
||||
*/
|
||||
public function getParticipantOptions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------
|
||||
// Aus getOptions() abgeleitete Helfer (zuvor statisch auf PaymentMethod).
|
||||
// Aus dem jeweiligen Schema abgeleitete Helfer (Admin-Config = getOptions(),
|
||||
// Teilnehmer-Eingaben = getParticipantOptions()).
|
||||
// -----------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Namen aller Pflicht-Optionen dieses Moduls.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
/** @return array<int, string> */
|
||||
public function requiredOptionKeys(): array
|
||||
{
|
||||
return array_values(array_map(
|
||||
static fn (array $option) => $option['name'],
|
||||
array_filter($this->getOptions(), static fn (array $option) => $option['required'] ?? false)
|
||||
));
|
||||
return $this->requiredKeys($this->getOptions());
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduziert eine Konfiguration auf die im Schema definierten Options-Keys.
|
||||
* Unbekannte Keys werden verworfen -- getOptions() ist die Autorität.
|
||||
*
|
||||
* @param array<string, mixed> $config
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function sanitizeConfiguration(array $config): array
|
||||
{
|
||||
return $this->sanitizeAgainst($this->getOptions(), $config);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $config */
|
||||
public function isConfigurationComplete(array $config): bool
|
||||
{
|
||||
return $this->allRequiredFilled($this->getOptions(), $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $input
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function sanitizeParticipantOptions(array $input): array
|
||||
{
|
||||
return $this->sanitizeAgainst($this->getParticipantOptions(), $input);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $input */
|
||||
public function participantOptionsComplete(array $input): bool
|
||||
{
|
||||
return $this->allRequiredFilled($this->getParticipantOptions(), $input);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, array{name: string, required?: bool}> $schema
|
||||
* @return array<int, string>
|
||||
*/
|
||||
private function requiredKeys(array $schema): array
|
||||
{
|
||||
return array_values(array_map(
|
||||
static fn (array $option) => $option['name'],
|
||||
array_filter($schema, static fn(array $option) => $option['required'] ?? false)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduziert Eingaben auf die im Schema definierten Keys (unbekannte werden verworfen).
|
||||
*
|
||||
* @param array<int, array{name: string}> $schema
|
||||
* @param array<string, mixed> $input
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function sanitizeAgainst(array $schema, array $input): array
|
||||
{
|
||||
$result = [];
|
||||
foreach ($this->getOptions() as $option) {
|
||||
if (array_key_exists($option['name'], $config)) {
|
||||
$result[$option['name']] = $config[$option['name']];
|
||||
foreach ($schema as $option) {
|
||||
if (array_key_exists($option['name'], $input)) {
|
||||
$result[$option['name']] = $input[$option['name']];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,14 +106,15 @@ abstract class AbstractEventPaymentModule implements EventPaymentModule
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft, ob alle Pflicht-Optionen befüllt (non-empty) sind.
|
||||
* Sind alle Pflichtfelder des Schemas befüllt (non-empty)?
|
||||
*
|
||||
* @param array<string, mixed> $config
|
||||
* @param array<int, array{name: string, required?: bool}> $schema
|
||||
* @param array<string, mixed> $input
|
||||
*/
|
||||
public function isConfigurationComplete(array $config): bool
|
||||
private function allRequiredFilled(array $schema, array $input): bool
|
||||
{
|
||||
foreach ($this->requiredOptionKeys() as $key) {
|
||||
$value = $config[$key] ?? null;
|
||||
foreach ($this->requiredKeys($schema) as $key) {
|
||||
$value = $input[$key] ?? null;
|
||||
if ($value === null || $value === '' || $value === []) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user