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

Add organisation id for related parties and add proprietary amount #141

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
11 changes: 11 additions & 0 deletions src/DTO/Creditor.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

Check warning on line 1 in src/DTO/Creditor.php

View workflow job for this annotation

GitHub Actions / php-cs-fixer

Found violation(s) of type: class_attributes_separation

declare(strict_types=1);

Expand All @@ -7,6 +7,7 @@
class Creditor implements RelatedPartyTypeInterface
{
private ?Address $address = null;
private ?string $orgId = null;

public function __construct(private ?string $name)
{
Expand All @@ -26,4 +27,14 @@
{
return $this->name;
}

public function setOrgId(string $orgId): void
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

orgId must be renamed into organisationId, in the private member, setter and getter.

{
$this->orgId = $orgId;
}

public function getOrgId(): ?string
{
return $this->orgId;
}
}
11 changes: 11 additions & 0 deletions src/DTO/Debtor.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

Check warning on line 1 in src/DTO/Debtor.php

View workflow job for this annotation

GitHub Actions / php-cs-fixer

Found violation(s) of type: class_attributes_separation

declare(strict_types=1);

Expand All @@ -7,6 +7,7 @@
class Debtor implements RelatedPartyTypeInterface
{
private ?Address $address = null;
private ?string $orgId = null;

public function __construct(private ?string $name)
{
Expand All @@ -26,4 +27,14 @@
{
return $this->name;
}

public function setOrgId(string $orgId): void
{
$this->orgId = $orgId;
}

public function getOrgId(): ?string
{
return $this->orgId;
}
}
8 changes: 7 additions & 1 deletion src/Decoder/EntryTransactionDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@

$xmlRelatedPartyName = (isset($xmlPartyDetail->Nm)) ? (string) $xmlPartyDetail->Nm : null;
$relatedPartyType = new $relatedPartyTypeClass($xmlRelatedPartyName);

$orgId = $xmlRelatedPartyType?->Id?->OrgId?->Othr?->Id;

Check failure on line 109 in src/Decoder/EntryTransactionDetail.php

View workflow job for this annotation

GitHub Actions / phpstan

Using nullsafe property access on non-nullable type SimpleXMLElement. Use -> instead.
if (isset($orgId)) {
$relatedPartyType->setOrgId((string) $orgId);

Check failure on line 111 in src/Decoder/EntryTransactionDetail.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method Genkgo\Camt\DTO\RelatedPartyTypeInterface::setOrgId().
}
if (isset($xmlPartyDetail->PstlAdr)) {
$relatedPartyType->setAddress(DTOFactory\Address::createFromXml($xmlPartyDetail->PstlAdr));
}
Expand Down Expand Up @@ -333,6 +336,9 @@
if (isset($xmlDetail->AmtDtls, $xmlDetail->AmtDtls->TxAmt, $xmlDetail->AmtDtls->TxAmt->Amt)) {
$money = $this->moneyFactory->create($xmlDetail->AmtDtls->TxAmt->Amt, $CdtDbtInd);
$detail->setAmountDetails($money);
} elseif (isset($xmlDetail->AmtDtls->PrtryAmt, $xmlDetail->AmtDtls->PrtryAmt->Amt, $xmlDetail->AmtDtls->PrtryAmt->Tp)) {
$money = $this->moneyFactory->create($xmlDetail->AmtDtls->PrtryAmt->Amt, $xmlDetail->AmtDtls->PrtryAmt->Tp);
$detail->setAmountDetails($money);
}
}

Expand Down
276 changes: 275 additions & 1 deletion test/Unit/Camt054/EndToEndTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

Check warning on line 1 in test/Unit/Camt054/EndToEndTest.php

View workflow job for this annotation

GitHub Actions / php-cs-fixer

Found violation(s) of type: php_unit_construct

Check warning on line 1 in test/Unit/Camt054/EndToEndTest.php

View workflow job for this annotation

GitHub Actions / php-cs-fixer

Found violation(s) of type: blank_line_before_statement

declare(strict_types=1);

Expand Down Expand Up @@ -154,11 +154,13 @@
public function testTransactionDetails(): void
{
$messages = [
$this->getV2Message(),
$this->getV4Message(),
$this->getV8Message(),
];

// this is because V4 and V8 don't support the structure with proprietary amount
$this->testV2Message();

foreach ($messages as $message) {
$notifications = $message->getRecords();

Expand Down Expand Up @@ -376,4 +378,276 @@
}
}
}

public function testV2Message(): void
{
$message = $this->getV2Message();

$notifications = $message->getRecords();

self::assertCount(1, $notifications);
foreach ($notifications as $notification) {
$entries = $notification->getEntries();

self::assertCount(1, $entries);
foreach ($entries as $entry) {
$transactionDetails = $entry->getTransactionDetails();
self::assertCount(4, $transactionDetails);
foreach ($transactionDetails as $index => $transactionDetail) {
switch ($index) {
case 0:
// Legacy : The first message comes from unstructured block
self::assertEquals(
'Unstructured Remittance Information V1',
$transactionDetail
->getRemittanceInformation()
->getMessage()
);

// Only one structured data block
self::assertEquals(
'Unstructured Remittance Information V1',
$transactionDetail
->getRemittanceInformation()
->getUnstructuredBlock()
->getMessage()
);

// Check structured and unstructured blocks
self::assertEquals(
'ISR ref number V1',
$transactionDetail
->getRemittanceInformation()
->getStructuredBlock()
->getCreditorReferenceInformation()
->getRef()
);

self::assertEquals(
'ISR Reference',
$transactionDetail
->getRemittanceInformation()
->getStructuredBlock()
->getCreditorReferenceInformation()
->getProprietary()
);

self::assertNull(
$transactionDetail
->getRemittanceInformation()
->getStructuredBlock()
->getCreditorReferenceInformation()
->getCode()
);

self::assertEquals(
'Additional Remittance Information V1',
$transactionDetail
->getRemittanceInformation()
->getStructuredBlock()
->getAdditionalRemittanceInformation()
);

break;
case 1:
self::assertEquals(
'ISR ref number V2',
$transactionDetail
->getRemittanceInformation()
->getMessage()
);

// Only one structured data block
self::assertEquals(
'ISR ref number V2',
$transactionDetail
->getRemittanceInformation()
->getUnstructuredBlock()
->getMessage()
);

// Check structured and unstructured blocks
self::assertEquals(
'ISR ref number V2',
$transactionDetail
->getRemittanceInformation()
->getStructuredBlock()
->getCreditorReferenceInformation()
->getRef()
);

self::assertEquals(
null,
$transactionDetail
->getRemittanceInformation()
->getStructuredBlock()
->getCreditorReferenceInformation()
->getProprietary()
);

self::assertEquals(
'SCOR',
$transactionDetail
->getRemittanceInformation()
->getStructuredBlock()
->getCreditorReferenceInformation()
->getCode()
);

self::assertEquals(
null,
$transactionDetail
->getRemittanceInformation()
->getStructuredBlock()
->getAdditionalRemittanceInformation()
);
break;
case 2:

// Legacy : ref number from the structured information
// because the unstructured block is not present
self::assertEquals(
'ISR ref number V2',
$transactionDetail
->getRemittanceInformation()
->getMessage()
);

// No unstructured block
self::assertCount(
0,
$transactionDetail
->getRemittanceInformation()
->getUnstructuredBlocks()
);

// Check structured and unstructured blocks
self::assertEquals(
'ISR ref number V2',
$transactionDetail
->getRemittanceInformation()
->getStructuredBlock()
->getCreditorReferenceInformation()
->getRef()
);

self::assertEquals(
'ISR Reference',
$transactionDetail
->getRemittanceInformation()
->getStructuredBlock()
->getCreditorReferenceInformation()
->getProprietary()
);

self::assertNull(
$transactionDetail
->getRemittanceInformation()
->getStructuredBlock()
->getCreditorReferenceInformation()
->getCode()
);

self::assertEquals(
'Additional Remittance Information V2',
$transactionDetail
->getRemittanceInformation()
->getStructuredBlock()
->getAdditionalRemittanceInformation()
);

break;
case 3:
// Legacy : ref number from the first unstructured block
self::assertEquals(
'Unstructured Remittance Information V3 block 1',
$transactionDetail
->getRemittanceInformation()
->getMessage()
);

// First unstructured block
self::assertEquals(
'Unstructured Remittance Information V3 block 1',
$transactionDetail
->getRemittanceInformation()
->getUnstructuredBlocks()[0]
->getMessage()
);

// Second unstructured block
self::assertEquals(
'Unstructured Remittance Information V3 block 2',
$transactionDetail
->getRemittanceInformation()
->getUnstructuredBlocks()[1]
->getMessage()
);

// Ref number from the first structured block
self::assertEquals(
'Ref number V3 block 1',
$transactionDetail
->getRemittanceInformation()
->getStructuredBlocks()[0]
->getCreditorReferenceInformation()
->getRef()
);

// Ref number from the second structured block
self::assertEquals(
'Ref number V3 block 2',
$transactionDetail
->getRemittanceInformation()
->getStructuredBlocks()[1]
->getCreditorReferenceInformation()
->getRef()
);

// Code from the first structured block
self::assertEquals(
'SCOR',
$transactionDetail
->getRemittanceInformation()
->getStructuredBlocks()[0]
->getCreditorReferenceInformation()
->getCode()
);

// Code from the second structured block
self::assertEquals(
'SCOR',
$transactionDetail
->getRemittanceInformation()
->getStructuredBlocks()[1]
->getCreditorReferenceInformation()
->getCode()
);

// Additional remittance information from the first structured block
self::assertEquals(
'Additional Remittance Information V3 block 1',
$transactionDetail
->getRemittanceInformation()
->getStructuredBlocks()[0]
->getAdditionalRemittanceInformation()
);

// Additional remittance information from the second structured block
self::assertEquals(
'Additional Remittance Information V3 block 2',
$transactionDetail
->getRemittanceInformation()
->getStructuredBlocks()[1]
->getAdditionalRemittanceInformation()
);

break;
default:
break;
}
}
}
}
}
}
6 changes: 4 additions & 2 deletions test/data/camt052.v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@
"getSubDepartment": null,
"getTownName": null
},
"getName": "Company Name"
"getName": "Company Name",
"getOrgId": "455454654"
}
},
{
Expand Down Expand Up @@ -162,7 +163,8 @@
"getSubDepartment": null,
"getTownName": null
},
"getName": "NAME NAME"
"getName": "NAME NAME",
"getOrgId": null
}
}
],
Expand Down
6 changes: 4 additions & 2 deletions test/data/camt052.v2.other-account.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@
"getSubDepartment": null,
"getTownName": null
},
"getName": "Company Name"
"getName": "Company Name",
"getOrgId": "455454654"
}
},
{
Expand Down Expand Up @@ -158,7 +159,8 @@
"getSubDepartment": null,
"getTownName": null
},
"getName": "NAME NAME"
"getName": "NAME NAME",
"getOrgId": null
}
}
],
Expand Down
Loading
Loading