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
@@ -3,6 +3,7 @@
namespace App\Domains\Admin\Actions\UpdateAvailablePaymentMethod;
use App\Domains\Admin\Actions\RemovePaymentMethodUsage\RemovePaymentMethodUsageAction;
use App\Models\PaymentMethod;
class UpdateAvailablePaymentMethodAction
{
@@ -13,16 +14,29 @@ class UpdateAvailablePaymentMethodAction
public function execute(): UpdateAvailablePaymentMethodResponse
{
$response = new UpdateAvailablePaymentMethodResponse();
$wasActive = $this->request->availablePaymentMethod->active;
$paymentMethod = $this->request->availablePaymentMethod;
$wasActive = $paymentMethod->active;
$this->request->availablePaymentMethod->update([
// Nur bekannte Options-Keys übernehmen -- das Schema (PaymentMethod::OPTIONS) ist die Autorität.
$configuration = PaymentMethod::sanitizeConfiguration($paymentMethod->slug, $this->request->configuration);
// Guard: Aktivierung nur erlaubt, wenn alle Pflicht-Optionen befüllt sind.
if ($this->request->active && !PaymentMethod::isConfigurationComplete($paymentMethod->slug, $configuration)) {
$response->success = false;
$response->message = 'Bitte zuerst alle Pflichtfelder ausfüllen, bevor die Zahlungsmethode aktiviert wird.';
return $response;
}
$paymentMethod->update([
'name' => $this->request->name,
'description' => $this->request->description,
'active' => $this->request->active,
'configuration' => $configuration,
]);
if ($wasActive && !$this->request->active) {
(new RemovePaymentMethodUsageAction())->execute($this->request->availablePaymentMethod);
(new RemovePaymentMethodUsageAction())->execute($paymentMethod);
}
$response->success = true;
@@ -6,11 +6,15 @@ use App\Models\AvailablePaymentMethod;
class UpdateAvailablePaymentMethodRequest
{
/**
* @param array<string, mixed> $configuration
*/
public function __construct(
public AvailablePaymentMethod $availablePaymentMethod,
public string $name,
public ?string $description,
public bool $active,
public array $configuration = [],
) {
}
}