forked from nemiah/phpFinTS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKti.php
More file actions
69 lines (60 loc) · 2.12 KB
/
Kti.php
File metadata and controls
69 lines (60 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/** @noinspection PhpUnused */
namespace Fhp\Segment\Common;
use Fhp\Model\SEPAAccount;
use Fhp\Segment\BaseDeg;
/**
* Data Element Group: Kontoverbindung international (Version 1)
*
* @link https://www.hbci-zka.de/dokumente/spezifikation_deutsch/fintsv3/FinTS_3.0_Messages_Geschaeftsvorfaelle_2015-08-07_final_version.pdf
* Section: B.3.2
*/
class Kti extends BaseDeg implements AccountInfo
{
/** Max length: 34 */
public ?string $iban = null;
/** Max length: 11, required if IBAN is present. */
public ?string $bic = null;
// The following fields can only be set if the BPD parameters allow it. If they are set, the fields above become
// optional.
/** Also known as Depotnummer. */
public ?string $kontonummer = null;
public ?string $unterkontomerkmal = null;
public ?Kik $kreditinstitutskennung = null;
public function validate()
{
parent::validate();
if ($this->iban !== null) {
if ($this->bic == null) {
throw new \InvalidArgumentException('Kti cannot have IBAN without BIC');
}
} else {
if ($this->kontonummer === null || $this->kreditinstitutskennung === null) {
throw new \InvalidArgumentException('Kti must have IBAN+BIC or Kontonummer+Kik or both');
}
}
}
public static function create(?string $iban, ?string $bic): Kti
{
$result = new Kti();
$result->iban = $iban;
$result->bic = $bic;
return $result;
}
public static function fromAccount(SEPAAccount $account): Kti
{
$result = static::create($account->getIban(), $account->getBic());
$result->kontonummer = $account->getAccountNumber();
$result->unterkontomerkmal = $account->getSubAccount();
$result->kreditinstitutskennung = Kik::create($account->getBlz());
return $result;
}
public function getAccountNumber(): string
{
return $this->iban ?? $this->kontonummer;
}
public function getBankIdentifier(): ?string
{
return $this->bic ?? $this->kreditinstitutskennung->kreditinstitutscode;
}
}