73 lines
2.0 KiB
PHP
73 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Form\Model;
|
|
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
/**
|
|
* DTO for bank account information used in payment processing.
|
|
*/
|
|
class BankAccountDto
|
|
{
|
|
#[Assert\NotBlank(message: 'Bitte geben Sie Ihre IBAN ein.')]
|
|
#[Assert\Iban(message: 'Die eingegebene IBAN ist ungültig.')]
|
|
public ?string $iban = null;
|
|
|
|
#[Assert\NotBlank(message: 'Bitte geben Sie den Kontoinhaber ein.')]
|
|
#[Assert\Length(
|
|
min: 2,
|
|
max: 70,
|
|
minMessage: 'Der Kontoinhaber muss mindestens {{ limit }} Zeichen lang sein.',
|
|
maxMessage: 'Der Kontoinhaber darf maximal {{ limit }} Zeichen lang sein.'
|
|
)]
|
|
public ?string $accountHolder = null;
|
|
|
|
#[Assert\Length(
|
|
max: 70,
|
|
maxMessage: 'Der Bankname darf maximal {{ limit }} Zeichen lang sein.'
|
|
)]
|
|
public ?string $bankName = null;
|
|
|
|
#[Assert\IsTrue(message: 'Bitte akzeptieren Sie das SEPA-Mandat.')]
|
|
public bool $sepaMandateAccepted = false;
|
|
|
|
public static function fromBankAccount(\App\BusProNet\Model\BankAccount $bankAccount): static
|
|
{
|
|
$instance = new static();
|
|
$instance->iban = $bankAccount->iban;
|
|
$instance->accountHolder = $bankAccount->holder;
|
|
$instance->bankName = $bankAccount->bankName;
|
|
$instance->sepaMandateAccepted = true;
|
|
|
|
return $instance;
|
|
}
|
|
|
|
/**
|
|
* Returns IBAN formatted with spaces for display (e.g., DE12 3456 7890 1234 5678 90).
|
|
*/
|
|
public function getFormattedIban(): ?string
|
|
{
|
|
if (null === $this->iban) {
|
|
return null;
|
|
}
|
|
|
|
$cleanIban = $this->getIbanWithoutSpaces();
|
|
|
|
return chunk_split($cleanIban, 4, ' ');
|
|
}
|
|
|
|
/**
|
|
* Returns IBAN without spaces for storage and API submission.
|
|
*/
|
|
public function getIbanWithoutSpaces(): ?string
|
|
{
|
|
if (null === $this->iban) {
|
|
return null;
|
|
}
|
|
|
|
return (string) preg_replace('/\s+/', '', $this->iban);
|
|
}
|
|
}
|