Skip to content

Commit

Permalink
fix(#83): RelatedAgents' BIC may be in BICFI instead of BIC node
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Lamy committed Oct 11, 2023
1 parent 87643ff commit bdfc742
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
7 changes: 7 additions & 0 deletions src/Camt054/Decoder/EntryTransactionDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,11 @@ public function getRelatedPartyAccount(?SimpleXMLElement $xmlRelatedPartyTypeAcc

return null;
}
/**
* Get Agent BIC from either FinInstnId.BIC or .BICFI, dependeing on 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 @@ -354,4 +356,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, dependeing on protocol version
*/
protected function getAgentBic(SimpleXMLElement $xmlAgent): ?SimpleXMLElement
{
return $xmlAgent->FinInstnId->BIC;
}
}
2 changes: 1 addition & 1 deletion test/Unit/RegressionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected function tearDown(): void
public function testRegression(string $file): void
{
$reader = new Reader(Config::getDefault());
$message = $reader->readFile($file);
$message = $reader->readFile(__DIR__.'/../../'.$file);

$dumper = new Dumper();
$actual = $dumper->dump($message);
Expand Down
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 bdfc742

Please sign in to comment.