From dfe88d781337370bb89b9cfb499de6ea3f351943 Mon Sep 17 00:00:00 2001 From: Thomas Lamy Date: Fri, 22 Mar 2024 04:06:27 +0100 Subject: [PATCH] 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 Co-authored-by: Adrien Crivelli --- src/Camt054/Decoder/EntryTransactionDetail.php | 8 ++++++++ src/Decoder/EntryTransactionDetail.php | 14 ++++++++++++-- test/data/camt054.v4.json | 10 +++++----- test/data/camt054.v8.json | 10 +++++----- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/Camt054/Decoder/EntryTransactionDetail.php b/src/Camt054/Decoder/EntryTransactionDetail.php index bfbafc2..f8d9229 100644 --- a/src/Camt054/Decoder/EntryTransactionDetail.php +++ b/src/Camt054/Decoder/EntryTransactionDetail.php @@ -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; + } } diff --git a/src/Decoder/EntryTransactionDetail.php b/src/Decoder/EntryTransactionDetail.php index cc420bc..ee53b33 100644 --- a/src/Decoder/EntryTransactionDetail.php +++ b/src/Decoder/EntryTransactionDetail.php @@ -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); } @@ -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; + } } diff --git a/test/data/camt054.v4.json b/test/data/camt054.v4.json index bfea1e3..eb15fd4 100644 --- a/test/data/camt054.v4.json +++ b/test/data/camt054.v4.json @@ -146,7 +146,7 @@ "__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent", "getRelatedAgentType": { "__CLASS__": "Genkgo\\Camt\\DTO\\DebtorAgent", - "getBIC": "", + "getBIC": "BANKCHZHXXX", "getName": "" } } @@ -287,7 +287,7 @@ "__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent", "getRelatedAgentType": { "__CLASS__": "Genkgo\\Camt\\DTO\\CreditorAgent", - "getBIC": "", + "getBIC": "BANKCHBE", "getName": "" } }, @@ -297,7 +297,7 @@ "__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent", "getRelatedAgentType": { "__CLASS__": "Genkgo\\Camt\\DTO\\DebtorAgent", - "getBIC": "", + "getBIC": "BANKCHZHXXX", "getName": "" } } @@ -431,7 +431,7 @@ "__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent", "getRelatedAgentType": { "__CLASS__": "Genkgo\\Camt\\DTO\\CreditorAgent", - "getBIC": "", + "getBIC": "BANKCHBE", "getName": "" } }, @@ -441,7 +441,7 @@ "__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent", "getRelatedAgentType": { "__CLASS__": "Genkgo\\Camt\\DTO\\DebtorAgent", - "getBIC": "", + "getBIC": "BANKCHZHXXX", "getName": "" } } diff --git a/test/data/camt054.v8.json b/test/data/camt054.v8.json index bfea1e3..eb15fd4 100644 --- a/test/data/camt054.v8.json +++ b/test/data/camt054.v8.json @@ -146,7 +146,7 @@ "__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent", "getRelatedAgentType": { "__CLASS__": "Genkgo\\Camt\\DTO\\DebtorAgent", - "getBIC": "", + "getBIC": "BANKCHZHXXX", "getName": "" } } @@ -287,7 +287,7 @@ "__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent", "getRelatedAgentType": { "__CLASS__": "Genkgo\\Camt\\DTO\\CreditorAgent", - "getBIC": "", + "getBIC": "BANKCHBE", "getName": "" } }, @@ -297,7 +297,7 @@ "__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent", "getRelatedAgentType": { "__CLASS__": "Genkgo\\Camt\\DTO\\DebtorAgent", - "getBIC": "", + "getBIC": "BANKCHZHXXX", "getName": "" } } @@ -431,7 +431,7 @@ "__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent", "getRelatedAgentType": { "__CLASS__": "Genkgo\\Camt\\DTO\\CreditorAgent", - "getBIC": "", + "getBIC": "BANKCHBE", "getName": "" } }, @@ -441,7 +441,7 @@ "__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent", "getRelatedAgentType": { "__CLASS__": "Genkgo\\Camt\\DTO\\DebtorAgent", - "getBIC": "", + "getBIC": "BANKCHZHXXX", "getName": "" } }