Skip to content

Commit

Permalink
fix(genkgo#83): RelatedAgents' BIC may be in BICFI instead of BIC node (
Browse files Browse the repository at this point in the history
genkgo#150)

RelatedAgents' BIC is also available in CAMT 054

Because the RelatedAgents' BIC may be in BICFI instead of BIC node

Fixes genkgo#83
---------

Co-authored-by: Thomas Lamy <[email protected]>
Co-authored-by: Adrien Crivelli <[email protected]>
  • Loading branch information
3 people authored and Alvyre committed Oct 9, 2024
1 parent 331dd21 commit dfe88d7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
8 changes: 8 additions & 0 deletions src/Camt054/Decoder/EntryTransactionDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,12 @@ public function getRelatedPartyAccount(?SimpleXMLElement $xmlRelatedPartyTypeAcc

return null;
}

/**
* Get Agent BIC from either FinInstnId.BIC or .BICFI, depending on the protocol version.
*/
protected function getAgentBic(SimpleXMLElement $xmlAgent): ?SimpleXMLElement
{
return $xmlAgent->FinInstnId->BICFI;
}
}
14 changes: 12 additions & 2 deletions src/Decoder/EntryTransactionDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,15 @@ public function addRelatedAgents(DTO\EntryTransactionDetail $detail, SimpleXMLEl

foreach ($xmlDetail->RltdAgts as $xmlRelatedAgent) {
if (isset($xmlRelatedAgent->CdtrAgt)) {
$agent = new DTO\CreditorAgent((string) $xmlRelatedAgent->CdtrAgt->FinInstnId->Nm, (string) $xmlRelatedAgent->CdtrAgt->FinInstnId->BIC);
$bic = $this->getAgentBic($xmlRelatedAgent->CdtrAgt);
$agent = new DTO\CreditorAgent((string) $xmlRelatedAgent->CdtrAgt->FinInstnId->Nm, (string) $bic);
$relatedAgent = new DTO\RelatedAgent($agent);
$detail->addRelatedAgent($relatedAgent);
}

if (isset($xmlRelatedAgent->DbtrAgt)) {
$agent = new DTO\DebtorAgent((string) $xmlRelatedAgent->DbtrAgt->FinInstnId->Nm, (string) $xmlRelatedAgent->DbtrAgt->FinInstnId->BIC);
$bic = $this->getAgentBic($xmlRelatedAgent->DbtrAgt);
$agent = new DTO\DebtorAgent((string) $xmlRelatedAgent->DbtrAgt->FinInstnId->Nm, (string) $bic);
$relatedAgent = new DTO\RelatedAgent($agent);
$detail->addRelatedAgent($relatedAgent);
}
Expand Down Expand Up @@ -363,4 +365,12 @@ public function addAmount(DTO\EntryTransactionDetail $detail, SimpleXMLElement $
}

abstract public function getRelatedPartyAccount(?SimpleXMLElement $xmlRelatedPartyTypeAccount): ?DTO\Account;

/**
* Get Agent BIC from either FinInstnId.BIC or .BICFI, depending on the protocol version.
*/
protected function getAgentBic(SimpleXMLElement $xmlAgent): ?SimpleXMLElement
{
return $xmlAgent->FinInstnId->BIC;
}
}
10 changes: 5 additions & 5 deletions test/data/camt054.v4.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
"__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent",
"getRelatedAgentType": {
"__CLASS__": "Genkgo\\Camt\\DTO\\DebtorAgent",
"getBIC": "",
"getBIC": "BANKCHZHXXX",
"getName": ""
}
}
Expand Down Expand Up @@ -287,7 +287,7 @@
"__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent",
"getRelatedAgentType": {
"__CLASS__": "Genkgo\\Camt\\DTO\\CreditorAgent",
"getBIC": "",
"getBIC": "BANKCHBE",
"getName": ""
}
},
Expand All @@ -297,7 +297,7 @@
"__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent",
"getRelatedAgentType": {
"__CLASS__": "Genkgo\\Camt\\DTO\\DebtorAgent",
"getBIC": "",
"getBIC": "BANKCHZHXXX",
"getName": ""
}
}
Expand Down Expand Up @@ -431,7 +431,7 @@
"__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent",
"getRelatedAgentType": {
"__CLASS__": "Genkgo\\Camt\\DTO\\CreditorAgent",
"getBIC": "",
"getBIC": "BANKCHBE",
"getName": ""
}
},
Expand All @@ -441,7 +441,7 @@
"__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent",
"getRelatedAgentType": {
"__CLASS__": "Genkgo\\Camt\\DTO\\DebtorAgent",
"getBIC": "",
"getBIC": "BANKCHZHXXX",
"getName": ""
}
}
Expand Down
10 changes: 5 additions & 5 deletions test/data/camt054.v8.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
"__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent",
"getRelatedAgentType": {
"__CLASS__": "Genkgo\\Camt\\DTO\\DebtorAgent",
"getBIC": "",
"getBIC": "BANKCHZHXXX",
"getName": ""
}
}
Expand Down Expand Up @@ -287,7 +287,7 @@
"__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent",
"getRelatedAgentType": {
"__CLASS__": "Genkgo\\Camt\\DTO\\CreditorAgent",
"getBIC": "",
"getBIC": "BANKCHBE",
"getName": ""
}
},
Expand All @@ -297,7 +297,7 @@
"__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent",
"getRelatedAgentType": {
"__CLASS__": "Genkgo\\Camt\\DTO\\DebtorAgent",
"getBIC": "",
"getBIC": "BANKCHZHXXX",
"getName": ""
}
}
Expand Down Expand Up @@ -431,7 +431,7 @@
"__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent",
"getRelatedAgentType": {
"__CLASS__": "Genkgo\\Camt\\DTO\\CreditorAgent",
"getBIC": "",
"getBIC": "BANKCHBE",
"getName": ""
}
},
Expand All @@ -441,7 +441,7 @@
"__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent",
"getRelatedAgentType": {
"__CLASS__": "Genkgo\\Camt\\DTO\\DebtorAgent",
"getBIC": "",
"getBIC": "BANKCHZHXXX",
"getName": ""
}
}
Expand Down

0 comments on commit dfe88d7

Please sign in to comment.