Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#83): RelatedAgents' BIC may be in BICFI instead of BIC node #150

Merged
merged 3 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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, 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
Loading