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": "" } }