Skip to content
Open
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
4 changes: 3 additions & 1 deletion src/Camt052/Decoder/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ public function addRecords(DTO\Message $message, SimpleXMLElement $document): vo

$xmlReports = $this->getRootElement($document)->Rpt;
foreach ($xmlReports as $xmlReport) {
$account = $this->getAccount($xmlReport);
$account->setServicer($this->getAccountServicer($xmlReport->Acct));
$report = new Camt052DTO\Report(
(string) $xmlReport->Id,
$this->dateDecoder->decode((string) $xmlReport->CreDtTm),
$this->getAccount($xmlReport)
$account
);

if (isset($xmlReport->RptPgntn)) {
Expand Down
4 changes: 3 additions & 1 deletion src/Camt053/Decoder/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ public function addRecords(DTO\Message $message, SimpleXMLElement $document): vo

$xmlStatements = $this->getRootElement($document)->Stmt;
foreach ($xmlStatements as $xmlStatement) {
$account = $this->getAccount($xmlStatement);
$account->setServicer($this->getAccountServicer($xmlStatement->Acct));
$statement = new Camt053DTO\Statement(
(string) $xmlStatement->Id,
$this->dateDecoder->decode((string) $xmlStatement->CreDtTm),
$this->getAccount($xmlStatement)
$account
);

if (isset($xmlStatement->StmtPgntn)) {
Expand Down
4 changes: 3 additions & 1 deletion src/Camt054/Decoder/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ public function addRecords(DTO\Message $message, SimpleXMLElement $document): vo
$xmlNotifications = $this->getRootElement($document)->Ntfctn;
foreach ($xmlNotifications as $xmlNotification) {
$createdOn = (string) $xmlNotification->CreDtTm;
$account = $this->getAccount($xmlNotification);
$account->setServicer($this->getAccountServicer($xmlNotification->Acct));
$notification = new Camt054DTO\Notification(
(string) $xmlNotification->Id,
$createdOn ? $this->dateDecoder->decode($createdOn) : null,
$this->getAccount($xmlNotification)
$account
);

if (isset($xmlNotification->NtfctnPgntn)) {
Expand Down
12 changes: 12 additions & 0 deletions src/DTO/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,17 @@

abstract class Account
{
private ?FinancialInstitution $servicer = null;

abstract public function getIdentification(): string;

public function getServicer(): ?FinancialInstitution
{
return $this->servicer;
}

public function setServicer(?FinancialInstitution $servicer): void
{
$this->servicer = $servicer;
}
}
24 changes: 24 additions & 0 deletions src/DTO/FinancialInstitution.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Genkgo\Camt\DTO;

class FinancialInstitution
{
public function __construct(
private readonly ?string $bic,
private readonly ?string $name,
) {
}

public function getBic(): ?string
{
return $this->bic;
}

public function getName(): ?string
{
return $this->name;
}
}
22 changes: 22 additions & 0 deletions src/Decoder/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,26 @@ public function addCommonRecordInformation(DTO\Record $record, SimpleXMLElement
abstract public function addRecords(DTO\Message $message, SimpleXMLElement $document): void;

abstract public function getRootElement(SimpleXMLElement $document): SimpleXMLElement;

protected function getAccountServicer(SimpleXMLElement $xmlAccount): ?DTO\FinancialInstitution
{
if (!isset($xmlAccount->Svcr->FinInstnId)) {
return null;
}

$finInstnId = $xmlAccount->Svcr->FinInstnId;
$bic = null;
if (isset($finInstnId->BICFI)) {
$bic = (string) $finInstnId->BICFI;
} elseif (isset($finInstnId->BIC)) {
$bic = (string) $finInstnId->BIC;
}
$name = isset($finInstnId->Nm) ? (string) $finInstnId->Nm : null;

if ($bic === null && $name === null) {
return null;
}

return new DTO\FinancialInstitution($bic, $name);
}
}
6 changes: 6 additions & 0 deletions test/Unit/Camt054/EndToEndTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ public function testNotifications(): void
self::assertInstanceOf(DTO\Pagination::class, $notificationV4->getPagination());
self::assertEquals('2', $notificationV4->getPagination()->getPageNumber());
self::assertTrue($notificationV4->getPagination()->isLastPage());

$notificationV8 = $this->getV8Message()->getRecords()[0];
$servicer = $notificationV8->getAccount()->getServicer();
self::assertInstanceOf(DTO\FinancialInstitution::class, $servicer);
self::assertSame('UBSWCHZH80A', $servicer->getBic());
self::assertSame('UBS SWITZERLAND AG', $servicer->getName());
}

public function testEntries(): void
Expand Down
82 changes: 82 additions & 0 deletions test/Unit/Decoder/AccountServicerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

declare(strict_types=1);

namespace Genkgo\TestCamt\Unit\Decoder;

use Genkgo\Camt\Decoder\Message as BaseMessageDecoder;
use Genkgo\Camt\DTO;
use PHPUnit\Framework;
use ReflectionMethod;
use SimpleXMLElement;

class AccountServicerTest extends Framework\TestCase
{
private BaseMessageDecoder $decoder;

private ReflectionMethod $method;

protected function setUp(): void
{
$this->decoder = new class($this->createMock(\Genkgo\Camt\Decoder\Record::class), new \Genkgo\Camt\Decoder\Date()) extends BaseMessageDecoder {
public function addRecords(DTO\Message $message, SimpleXMLElement $document): void
{
}

public function getRootElement(SimpleXMLElement $document): SimpleXMLElement
{
return $document;
}
};

$this->method = new ReflectionMethod(BaseMessageDecoder::class, 'getAccountServicer');
$this->method->setAccessible(true);
}

public function testItReturnsNullWhenNoServicer(): void
{
$xml = new SimpleXMLElement('<Acct><Id><IBAN>DE89370400440532013000</IBAN></Id></Acct>');

self::assertNull($this->method->invoke($this->decoder, $xml));
}

public function testItExtractsBicFromBicTag(): void
{
$xml = new SimpleXMLElement('<Acct><Svcr><FinInstnId><BIC>COBADEFFXXX</BIC><Nm>Commerzbank AG</Nm></FinInstnId></Svcr></Acct>');

$servicer = $this->method->invoke($this->decoder, $xml);

self::assertInstanceOf(DTO\FinancialInstitution::class, $servicer);
self::assertSame('COBADEFFXXX', $servicer->getBic());
self::assertSame('Commerzbank AG', $servicer->getName());
}

public function testItExtractsBicFromBicfiTag(): void
{
$xml = new SimpleXMLElement('<Acct><Svcr><FinInstnId><BICFI>UBSWCHZH80A</BICFI><Nm>UBS SWITZERLAND AG</Nm></FinInstnId></Svcr></Acct>');

$servicer = $this->method->invoke($this->decoder, $xml);

self::assertInstanceOf(DTO\FinancialInstitution::class, $servicer);
self::assertSame('UBSWCHZH80A', $servicer->getBic());
self::assertSame('UBS SWITZERLAND AG', $servicer->getName());
}

public function testItReturnsNameOnlyWhenNoBic(): void
{
$xml = new SimpleXMLElement('<Acct><Svcr><FinInstnId><Nm>AAAA BANKEN</Nm></FinInstnId></Svcr></Acct>');

$servicer = $this->method->invoke($this->decoder, $xml);

self::assertInstanceOf(DTO\FinancialInstitution::class, $servicer);
self::assertNull($servicer->getBic());
self::assertSame('AAAA BANKEN', $servicer->getName());
}

public function testItReturnsNullWhenFinInstnIdIsEmpty(): void
{
$xml = new SimpleXMLElement('<Acct><Svcr><FinInstnId></FinInstnId></Svcr></Acct>');

self::assertNull($this->method->invoke($this->decoder, $xml));
}
}
3 changes: 2 additions & 1 deletion test/data/camt052.v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"getAccount": {
"__CLASS__": "Genkgo\\Camt\\DTO\\ProprietaryAccount",
"getId": "CH2801234000123456789",
"getIdentification": "CH2801234000123456789"
"getIdentification": "CH2801234000123456789",
"getServicer": null
},
"getAdditionalInformation": "Additional Information",
"getBalances": [],
Expand Down
13 changes: 10 additions & 3 deletions test/data/camt052.v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@
"__CLASS__": "Genkgo\\Camt\\DTO\\OtherAccount",
"getIdentification": "CH2801234000123456789",
"getIssuer": null,
"getSchemeName": null
"getSchemeName": null,
"getServicer": {
"__CLASS__": "Genkgo\\Camt\\DTO\\FinancialInstitution",
"getBic": null,
"getName": "AAAA BANKEN"
}
},
"getAdditionalInformation": "Additional Information",
"getBalances": [],
Expand Down Expand Up @@ -119,7 +124,8 @@
"getIban": "NL56AGDH9619008421"
},
"getIdentification": "NL56AGDH9619008421",
"getName": null
"getName": null,
"getServicer": null
},
"getRelatedPartyType": {
"__CLASS__": "Genkgo\\Camt\\DTO\\Creditor",
Expand Down Expand Up @@ -164,7 +170,8 @@
"getIban": "NL56AGDH9619008421"
},
"getIdentification": "NL56AGDH9619008421",
"getName": null
"getName": null,
"getServicer": null
},
"getRelatedPartyType": {
"__CLASS__": "Genkgo\\Camt\\DTO\\Debtor",
Expand Down
13 changes: 10 additions & 3 deletions test/data/camt052.v2.other-account.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@
"__CLASS__": "Genkgo\\Camt\\DTO\\OtherAccount",
"getIdentification": "CH2801234000123456789",
"getIssuer": null,
"getSchemeName": null
"getSchemeName": null,
"getServicer": {
"__CLASS__": "Genkgo\\Camt\\DTO\\FinancialInstitution",
"getBic": null,
"getName": "AAAA BANKEN"
}
},
"getAdditionalInformation": "Additional Information",
"getBalances": [],
Expand Down Expand Up @@ -116,7 +121,8 @@
"__CLASS__": "Genkgo\\Camt\\DTO\\OtherAccount",
"getIdentification": "0000000000",
"getIssuer": null,
"getSchemeName": null
"getSchemeName": null,
"getServicer": null
},
"getRelatedPartyType": {
"__CLASS__": "Genkgo\\Camt\\DTO\\Creditor",
Expand Down Expand Up @@ -158,7 +164,8 @@
"__CLASS__": "Genkgo\\Camt\\DTO\\OtherAccount",
"getIdentification": "1111111111",
"getIssuer": null,
"getSchemeName": null
"getSchemeName": null,
"getServicer": null
},
"getRelatedPartyType": {
"__CLASS__": "Genkgo\\Camt\\DTO\\Debtor",
Expand Down
9 changes: 6 additions & 3 deletions test/data/camt052.v2.with-account-name.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"getIban": "CH2801234000123456789"
},
"getIdentification": "CH2801234000123456789",
"getName": "Account Owner Name"
"getName": "Account Owner Name",
"getServicer": null
},
"getAdditionalInformation": null,
"getBalances": [],
Expand Down Expand Up @@ -80,7 +81,8 @@
"getIban": "CH2801234000123456789"
},
"getIdentification": "CH2801234000123456789",
"getName": "Creditor Account Name"
"getName": "Creditor Account Name",
"getServicer": null
},
"getRelatedPartyType": {
"__CLASS__": "Genkgo\\Camt\\DTO\\Creditor",
Expand All @@ -98,7 +100,8 @@
"getIban": "CH2801234000123456789"
},
"getIdentification": "CH2801234000123456789",
"getName": "Debitor Account Name"
"getName": "Debitor Account Name",
"getServicer": null
},
"getRelatedPartyType": {
"__CLASS__": "Genkgo\\Camt\\DTO\\Debtor",
Expand Down
13 changes: 10 additions & 3 deletions test/data/camt052.v4.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@
"getIban": "CH2801234000123456789"
},
"getIdentification": "CH2801234000123456789",
"getName": null
"getName": null,
"getServicer": {
"__CLASS__": "Genkgo\\Camt\\DTO\\FinancialInstitution",
"getBic": "UBSWCHZH80A",
"getName": "UBS SWITZERLAND AG"
}
},
"getAdditionalInformation": "Additional Information",
"getBalances": [
Expand Down Expand Up @@ -207,7 +212,8 @@
"getIban": "CH2801234000123456789"
},
"getIdentification": "CH2801234000123456789",
"getName": null
"getName": null,
"getServicer": null
},
"getRelatedPartyType": {
"__CLASS__": "Genkgo\\Camt\\DTO\\Creditor",
Expand All @@ -225,7 +231,8 @@
"getIban": "CH2401234004141414141"
},
"getIdentification": "CH2401234004141414141",
"getName": null
"getName": null,
"getServicer": null
},
"getRelatedPartyType": {
"__CLASS__": "Genkgo\\Camt\\DTO\\Debtor",
Expand Down
13 changes: 10 additions & 3 deletions test/data/camt052.v6.Amt-zero.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@
"getIban": "CH2801234000123456789"
},
"getIdentification": "CH2801234000123456789",
"getName": null
"getName": null,
"getServicer": {
"__CLASS__": "Genkgo\\Camt\\DTO\\FinancialInstitution",
"getBic": "UBSWCHZH80A",
"getName": "UBS SWITZERLAND AG"
}
},
"getAdditionalInformation": "Additional Information",
"getBalances": [
Expand Down Expand Up @@ -233,7 +238,8 @@
"getIban": "CH2801234000123456789"
},
"getIdentification": "CH2801234000123456789",
"getName": null
"getName": null,
"getServicer": null
},
"getRelatedPartyType": {
"__CLASS__": "Genkgo\\Camt\\DTO\\Creditor",
Expand All @@ -251,7 +257,8 @@
"getIban": "CH2401234004141414141"
},
"getIdentification": "CH2401234004141414141",
"getName": null
"getName": null,
"getServicer": null
},
"getRelatedPartyType": {
"__CLASS__": "Genkgo\\Camt\\DTO\\Debtor",
Expand Down
Loading