Skip to content

Commit 08ff6d7

Browse files
tlamyThomas LamyPowerKiKi
authored
fix(#83): RelatedAgents' BIC may be in BICFI instead of BIC node (#150)
RelatedAgents' BIC is also available in CAMT 054 Because the RelatedAgents' BIC may be in BICFI instead of BIC node Fixes #83 --------- Co-authored-by: Thomas Lamy <thomas.lamy@iventuregroup.com> Co-authored-by: Adrien Crivelli <adrien.crivelli@gmail.com>
1 parent 77b39a0 commit 08ff6d7

4 files changed

Lines changed: 30 additions & 12 deletions

File tree

src/Camt054/Decoder/EntryTransactionDetail.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,12 @@ public function getRelatedPartyAccount(?SimpleXMLElement $xmlRelatedPartyTypeAcc
6363

6464
return null;
6565
}
66+
67+
/**
68+
* Get Agent BIC from either FinInstnId.BIC or .BICFI, depending on the protocol version.
69+
*/
70+
protected function getAgentBic(SimpleXMLElement $xmlAgent): ?SimpleXMLElement
71+
{
72+
return $xmlAgent->FinInstnId->BICFI;
73+
}
6674
}

src/Decoder/EntryTransactionDetail.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,15 @@ public function addRelatedAgents(DTO\EntryTransactionDetail $detail, SimpleXMLEl
133133

134134
foreach ($xmlDetail->RltdAgts as $xmlRelatedAgent) {
135135
if (isset($xmlRelatedAgent->CdtrAgt)) {
136-
$agent = new DTO\CreditorAgent((string) $xmlRelatedAgent->CdtrAgt->FinInstnId->Nm, (string) $xmlRelatedAgent->CdtrAgt->FinInstnId->BIC);
136+
$bic = $this->getAgentBic($xmlRelatedAgent->CdtrAgt);
137+
$agent = new DTO\CreditorAgent((string) $xmlRelatedAgent->CdtrAgt->FinInstnId->Nm, (string) $bic);
137138
$relatedAgent = new DTO\RelatedAgent($agent);
138139
$detail->addRelatedAgent($relatedAgent);
139140
}
140141

141142
if (isset($xmlRelatedAgent->DbtrAgt)) {
142-
$agent = new DTO\DebtorAgent((string) $xmlRelatedAgent->DbtrAgt->FinInstnId->Nm, (string) $xmlRelatedAgent->DbtrAgt->FinInstnId->BIC);
143+
$bic = $this->getAgentBic($xmlRelatedAgent->DbtrAgt);
144+
$agent = new DTO\DebtorAgent((string) $xmlRelatedAgent->DbtrAgt->FinInstnId->Nm, (string) $bic);
143145
$relatedAgent = new DTO\RelatedAgent($agent);
144146
$detail->addRelatedAgent($relatedAgent);
145147
}
@@ -354,4 +356,12 @@ public function addAmount(DTO\EntryTransactionDetail $detail, SimpleXMLElement $
354356
}
355357

356358
abstract public function getRelatedPartyAccount(?SimpleXMLElement $xmlRelatedPartyTypeAccount): ?DTO\Account;
359+
360+
/**
361+
* Get Agent BIC from either FinInstnId.BIC or .BICFI, depending on the protocol version.
362+
*/
363+
protected function getAgentBic(SimpleXMLElement $xmlAgent): ?SimpleXMLElement
364+
{
365+
return $xmlAgent->FinInstnId->BIC;
366+
}
357367
}

test/data/camt054.v4.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
"__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent",
147147
"getRelatedAgentType": {
148148
"__CLASS__": "Genkgo\\Camt\\DTO\\DebtorAgent",
149-
"getBIC": "",
149+
"getBIC": "BANKCHZHXXX",
150150
"getName": ""
151151
}
152152
}
@@ -287,7 +287,7 @@
287287
"__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent",
288288
"getRelatedAgentType": {
289289
"__CLASS__": "Genkgo\\Camt\\DTO\\CreditorAgent",
290-
"getBIC": "",
290+
"getBIC": "BANKCHBE",
291291
"getName": ""
292292
}
293293
},
@@ -297,7 +297,7 @@
297297
"__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent",
298298
"getRelatedAgentType": {
299299
"__CLASS__": "Genkgo\\Camt\\DTO\\DebtorAgent",
300-
"getBIC": "",
300+
"getBIC": "BANKCHZHXXX",
301301
"getName": ""
302302
}
303303
}
@@ -431,7 +431,7 @@
431431
"__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent",
432432
"getRelatedAgentType": {
433433
"__CLASS__": "Genkgo\\Camt\\DTO\\CreditorAgent",
434-
"getBIC": "",
434+
"getBIC": "BANKCHBE",
435435
"getName": ""
436436
}
437437
},
@@ -441,7 +441,7 @@
441441
"__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent",
442442
"getRelatedAgentType": {
443443
"__CLASS__": "Genkgo\\Camt\\DTO\\DebtorAgent",
444-
"getBIC": "",
444+
"getBIC": "BANKCHZHXXX",
445445
"getName": ""
446446
}
447447
}

test/data/camt054.v8.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
"__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent",
147147
"getRelatedAgentType": {
148148
"__CLASS__": "Genkgo\\Camt\\DTO\\DebtorAgent",
149-
"getBIC": "",
149+
"getBIC": "BANKCHZHXXX",
150150
"getName": ""
151151
}
152152
}
@@ -287,7 +287,7 @@
287287
"__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent",
288288
"getRelatedAgentType": {
289289
"__CLASS__": "Genkgo\\Camt\\DTO\\CreditorAgent",
290-
"getBIC": "",
290+
"getBIC": "BANKCHBE",
291291
"getName": ""
292292
}
293293
},
@@ -297,7 +297,7 @@
297297
"__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent",
298298
"getRelatedAgentType": {
299299
"__CLASS__": "Genkgo\\Camt\\DTO\\DebtorAgent",
300-
"getBIC": "",
300+
"getBIC": "BANKCHZHXXX",
301301
"getName": ""
302302
}
303303
}
@@ -431,7 +431,7 @@
431431
"__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent",
432432
"getRelatedAgentType": {
433433
"__CLASS__": "Genkgo\\Camt\\DTO\\CreditorAgent",
434-
"getBIC": "",
434+
"getBIC": "BANKCHBE",
435435
"getName": ""
436436
}
437437
},
@@ -441,7 +441,7 @@
441441
"__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent",
442442
"getRelatedAgentType": {
443443
"__CLASS__": "Genkgo\\Camt\\DTO\\DebtorAgent",
444-
"getBIC": "",
444+
"getBIC": "BANKCHZHXXX",
445445
"getName": ""
446446
}
447447
}

0 commit comments

Comments
 (0)