69 lines
2.2 KiB
PHP
69 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Admin\Actions\UpdateTenantPayment;
|
|
|
|
use App\Models\AvailablePaymentMethod;
|
|
use App\Models\PaymentMethod;
|
|
use App\Scopes\SiteScope;
|
|
|
|
class UpdateTenantPaymentAction
|
|
{
|
|
/** Zahlungsarten, deren Konto das Konto des Stammes ist (Überweisung: Ziel, Lastschrift: Gläubiger). */
|
|
private const array BANK_ACCOUNT_SLUGS = [
|
|
PaymentMethod::PAYMENT_ACCOUNT_TRANSACTION,
|
|
PaymentMethod::PAYMENT_SEPA_DIRECT_DEBIT,
|
|
];
|
|
|
|
public function __construct(private UpdateTenantPaymentRequest $request)
|
|
{
|
|
}
|
|
|
|
public function execute(): UpdateTenantPaymentResponse
|
|
{
|
|
$response = new UpdateTenantPaymentResponse();
|
|
|
|
$this->request->tenant->update([
|
|
'account_iban' => $this->request->accountIban,
|
|
'account_bic' => $this->request->accountBic,
|
|
'account_name' => $this->request->accountName,
|
|
]);
|
|
|
|
foreach (self::BANK_ACCOUNT_SLUGS as $slug) {
|
|
$this->syncPaymentConfiguration($slug);
|
|
}
|
|
|
|
$response->success = true;
|
|
$response->message = 'IBAN-Informationen wurden gespeichert.';
|
|
|
|
return $response;
|
|
}
|
|
|
|
/**
|
|
* Übernimmt die eingegebenen IBAN-Daten direkt in die Tenant-Config der Zahlungsart
|
|
* (Kontoinhaber/IBAN/BIC), damit sie nicht doppelt gepflegt werden müssen. Bestehende weitere
|
|
* Config-Werte (z.B. Symbol, Gläubiger-ID) bleiben erhalten. Der Ziel-Tenant kann ein verwalteter
|
|
* sein, daher ohne SiteScope explizit auf den Tenant-Slug gefiltert.
|
|
*/
|
|
private function syncPaymentConfiguration(string $slug): void
|
|
{
|
|
$method = AvailablePaymentMethod::withoutGlobalScope(SiteScope::class)
|
|
->where('tenant', $this->request->tenant->slug)
|
|
->where('slug', $slug)
|
|
->first();
|
|
|
|
if ($method === null) {
|
|
return;
|
|
}
|
|
|
|
$method->configuration = PaymentMethod::sanitizeConfiguration($slug, array_merge(
|
|
$method->configuration ?? [],
|
|
[
|
|
'account_owner' => $this->request->accountName,
|
|
'iban' => $this->request->accountIban,
|
|
'bic' => $this->request->accountBic,
|
|
],
|
|
));
|
|
$method->save();
|
|
}
|
|
}
|