1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Genkgo\Camt\Camt054\Decoder; |
6
|
|
|
|
7
|
|
|
use Genkgo\Camt\Camt054\DTO as Camt054DTO; |
8
|
|
|
use Genkgo\Camt\Decoder\Message as BaseMessageDecoder; |
9
|
|
|
use Genkgo\Camt\DTO; |
10
|
|
|
use Genkgo\Camt\DTO\Account; |
11
|
|
|
use Genkgo\Camt\Exception\InvalidMessageException; |
12
|
|
|
use Genkgo\Camt\Iban; |
13
|
|
|
use SimpleXMLElement; |
14
|
|
|
|
15
|
|
|
class Message extends BaseMessageDecoder |
16
|
5 |
|
{ |
17
|
|
|
public function addRecords(DTO\Message $message, SimpleXMLElement $document): void |
18
|
5 |
|
{ |
19
|
|
|
$notifications = []; |
20
|
5 |
|
|
21
|
5 |
|
$xmlNotifications = $this->getRootElement($document)->Ntfctn; |
22
|
5 |
|
foreach ($xmlNotifications as $xmlNotification) { |
23
|
5 |
|
$notification = new Camt054DTO\Notification( |
24
|
5 |
|
(string) $xmlNotification->Id, |
25
|
5 |
|
$this->dateDecoder->decode((string) $xmlNotification->CreDtTm), |
26
|
|
|
$this->getAccount($xmlNotification) |
|
|
|
|
27
|
|
|
); |
28
|
5 |
|
|
29
|
4 |
|
if (isset($xmlNotification->NtfctnPgntn)) { |
30
|
4 |
|
$notification->setPagination(new DTO\Pagination( |
31
|
4 |
|
(string) $xmlNotification->NtfctnPgntn->PgNb, |
32
|
|
|
('true' === (string) $xmlNotification->NtfctnPgntn->LastPgInd) ? true : false |
33
|
|
|
)); |
34
|
|
|
} |
35
|
5 |
|
|
36
|
4 |
|
if (isset($xmlNotification->AddtlNtfctnInf)) { |
37
|
|
|
$notification->setAdditionalInformation((string) $xmlNotification->AddtlNtfctnInf); |
38
|
|
|
} |
39
|
5 |
|
|
40
|
5 |
|
$this->addCommonRecordInformation($notification, $xmlNotification); |
41
|
|
|
$this->recordDecoder->addEntries($notification, $xmlNotification); |
42
|
5 |
|
|
43
|
|
|
$notifications[] = $notification; |
44
|
|
|
} |
45
|
5 |
|
|
46
|
5 |
|
$message->setRecords($notifications); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @inheritDoc |
51
|
6 |
|
*/ |
52
|
|
|
public function getRootElement(SimpleXMLElement $document): SimpleXMLElement |
53
|
6 |
|
{ |
54
|
|
|
return $document->BkToCstmrDbtCdtNtfctn; |
55
|
|
|
} |
56
|
5 |
|
|
57
|
|
|
protected function getAccount(SimpleXMLElement $xmlRecord): Account |
58
|
5 |
|
{ |
59
|
4 |
|
if (isset($xmlRecord->Acct->Id->IBAN)) { |
60
|
|
|
return new DTO\IbanAccount(new Iban((string) $xmlRecord->Acct->Id->IBAN)); |
61
|
|
|
} |
62
|
5 |
|
|
63
|
|
|
if (isset($xmlRecord->Acct->Id->BBAN)) { |
64
|
|
|
return new DTO\BBANAccount((string) $xmlRecord->Acct->Id->BBAN); |
65
|
|
|
} |
66
|
5 |
|
|
67
|
|
|
if (isset($xmlRecord->Acct->Id->UPIC)) { |
68
|
|
|
return new DTO\UPICAccount((string) $xmlRecord->Acct->Id->UPIC); |
69
|
|
|
} |
70
|
5 |
|
|
71
|
1 |
|
if (isset($xmlRecord->Acct->Id->PrtryAcct)) { |
72
|
|
|
return new DTO\ProprietaryAccount((string) $xmlRecord->Acct->Id->PrtryAcct->Id); |
73
|
|
|
} |
74
|
4 |
|
|
75
|
4 |
|
if (isset($xmlRecord->Acct->Id->Othr)) { |
76
|
4 |
|
$xmlOtherIdentification = $xmlRecord->Acct->Id->Othr; |
77
|
|
|
$otherAccount = new DTO\OtherAccount((string) $xmlOtherIdentification->Id); |
78
|
4 |
|
|
79
|
|
|
if (isset($xmlOtherIdentification->SchmeNm)) { |
80
|
|
|
if (isset($xmlOtherIdentification->SchmeNm->Cd)) { |
81
|
|
|
$otherAccount->setSchemeName((string) $xmlOtherIdentification->SchmeNm->Cd); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
if (isset($xmlOtherIdentification->SchmeNm->Prtry)) { |
85
|
|
|
$otherAccount->setSchemeName((string) $xmlOtherIdentification->SchmeNm->Prtry); |
86
|
|
|
} |
87
|
|
|
} |
88
|
4 |
|
|
89
|
|
|
if (isset($xmlOtherIdentification->Issr)) { |
90
|
|
|
$otherAccount->setIssuer((string) $xmlOtherIdentification->Issr); |
91
|
|
|
} |
92
|
4 |
|
|
93
|
|
|
return $otherAccount; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
throw new InvalidMessageException('Cannot decode account'); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|