Skip to content

Commit a8acc8f

Browse files
Marko PetrovicPowerKiKi
authored andcommitted
added tests for proprietary amount (with real data received from bank) and fixed the null issue
1 parent 088e9c1 commit a8acc8f

19 files changed

+453
-36
lines changed

src/DTO/Creditor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class Creditor implements RelatedPartyTypeInterface
88
{
99
private ?Address $address = null;
10-
private ?string $orgId;
10+
private ?string $orgId = null;
1111

1212
public function __construct(private ?string $name)
1313
{
@@ -28,7 +28,7 @@ public function getName(): ?string
2828
return $this->name;
2929
}
3030

31-
public function setOrgId(?string $orgId): void
31+
public function setOrgId(string $orgId): void
3232
{
3333
$this->orgId = $orgId;
3434
}

src/DTO/Debtor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class Debtor implements RelatedPartyTypeInterface
88
{
99
private ?Address $address = null;
10-
private ?string $orgId;
10+
private ?string $orgId = null;
1111

1212
public function __construct(private ?string $name)
1313
{
@@ -28,7 +28,7 @@ public function getName(): ?string
2828
return $this->name;
2929
}
3030

31-
public function setOrgId(?string $orgId): void
31+
public function setOrgId(string $orgId): void
3232
{
3333
$this->orgId = $orgId;
3434
}

src/Decoder/EntryTransactionDetail.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ protected function addRelatedParty(DTO\EntryTransactionDetail $detail, SimpleXML
107107
$xmlRelatedPartyName = (isset($xmlPartyDetail->Nm)) ? (string) $xmlPartyDetail->Nm : null;
108108
$relatedPartyType = new $relatedPartyTypeClass($xmlRelatedPartyName);
109109
$orgId = $xmlRelatedPartyType?->Id?->OrgId?->Othr?->Id;
110-
111-
$relatedPartyType->setOrgId((string)$orgId);
110+
if (isset($orgId)) {
111+
$relatedPartyType->setOrgId((string) $orgId);
112+
}
112113
if (isset($xmlPartyDetail->PstlAdr)) {
113114
$relatedPartyType->setAddress(DTOFactory\Address::createFromXml($xmlPartyDetail->PstlAdr));
114115
}

test/Unit/Camt054/EndToEndTest.php

Lines changed: 275 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,13 @@ public function testEntries(): void
154154
public function testTransactionDetails(): void
155155
{
156156
$messages = [
157-
$this->getV2Message(),
158157
$this->getV4Message(),
159158
$this->getV8Message(),
160159
];
161160

161+
// this is because V4 and V8 don't support the structure with proprietary amount
162+
$this->testV2Message();
163+
162164
foreach ($messages as $message) {
163165
$notifications = $message->getRecords();
164166

@@ -376,4 +378,276 @@ public function testTransactionDetails(): void
376378
}
377379
}
378380
}
381+
382+
public function testV2Message(): void
383+
{
384+
$message = $this->getV2Message();
385+
386+
$notifications = $message->getRecords();
387+
388+
self::assertCount(1, $notifications);
389+
foreach ($notifications as $notification) {
390+
$entries = $notification->getEntries();
391+
392+
self::assertCount(1, $entries);
393+
foreach ($entries as $entry) {
394+
$transactionDetails = $entry->getTransactionDetails();
395+
self::assertCount(4, $transactionDetails);
396+
foreach ($transactionDetails as $index => $transactionDetail) {
397+
switch ($index) {
398+
case 0:
399+
// Legacy : The first message comes from unstructured block
400+
self::assertEquals(
401+
'Unstructured Remittance Information V1',
402+
$transactionDetail
403+
->getRemittanceInformation()
404+
->getMessage()
405+
);
406+
407+
// Only one structured data block
408+
self::assertEquals(
409+
'Unstructured Remittance Information V1',
410+
$transactionDetail
411+
->getRemittanceInformation()
412+
->getUnstructuredBlock()
413+
->getMessage()
414+
);
415+
416+
// Check structured and unstructured blocks
417+
self::assertEquals(
418+
'ISR ref number V1',
419+
$transactionDetail
420+
->getRemittanceInformation()
421+
->getStructuredBlock()
422+
->getCreditorReferenceInformation()
423+
->getRef()
424+
);
425+
426+
self::assertEquals(
427+
'ISR Reference',
428+
$transactionDetail
429+
->getRemittanceInformation()
430+
->getStructuredBlock()
431+
->getCreditorReferenceInformation()
432+
->getProprietary()
433+
);
434+
435+
self::assertNull(
436+
$transactionDetail
437+
->getRemittanceInformation()
438+
->getStructuredBlock()
439+
->getCreditorReferenceInformation()
440+
->getCode()
441+
);
442+
443+
self::assertEquals(
444+
'Additional Remittance Information V1',
445+
$transactionDetail
446+
->getRemittanceInformation()
447+
->getStructuredBlock()
448+
->getAdditionalRemittanceInformation()
449+
);
450+
451+
break;
452+
case 1:
453+
self::assertEquals(
454+
'ISR ref number V2',
455+
$transactionDetail
456+
->getRemittanceInformation()
457+
->getMessage()
458+
);
459+
460+
// Only one structured data block
461+
self::assertEquals(
462+
'ISR ref number V2',
463+
$transactionDetail
464+
->getRemittanceInformation()
465+
->getUnstructuredBlock()
466+
->getMessage()
467+
);
468+
469+
// Check structured and unstructured blocks
470+
self::assertEquals(
471+
'ISR ref number V2',
472+
$transactionDetail
473+
->getRemittanceInformation()
474+
->getStructuredBlock()
475+
->getCreditorReferenceInformation()
476+
->getRef()
477+
);
478+
479+
self::assertEquals(
480+
null,
481+
$transactionDetail
482+
->getRemittanceInformation()
483+
->getStructuredBlock()
484+
->getCreditorReferenceInformation()
485+
->getProprietary()
486+
);
487+
488+
self::assertEquals(
489+
'SCOR',
490+
$transactionDetail
491+
->getRemittanceInformation()
492+
->getStructuredBlock()
493+
->getCreditorReferenceInformation()
494+
->getCode()
495+
);
496+
497+
self::assertEquals(
498+
null,
499+
$transactionDetail
500+
->getRemittanceInformation()
501+
->getStructuredBlock()
502+
->getAdditionalRemittanceInformation()
503+
);
504+
break;
505+
case 2:
506+
507+
// Legacy : ref number from the structured information
508+
// because the unstructured block is not present
509+
self::assertEquals(
510+
'ISR ref number V2',
511+
$transactionDetail
512+
->getRemittanceInformation()
513+
->getMessage()
514+
);
515+
516+
// No unstructured block
517+
self::assertCount(
518+
0,
519+
$transactionDetail
520+
->getRemittanceInformation()
521+
->getUnstructuredBlocks()
522+
);
523+
524+
// Check structured and unstructured blocks
525+
self::assertEquals(
526+
'ISR ref number V2',
527+
$transactionDetail
528+
->getRemittanceInformation()
529+
->getStructuredBlock()
530+
->getCreditorReferenceInformation()
531+
->getRef()
532+
);
533+
534+
self::assertEquals(
535+
'ISR Reference',
536+
$transactionDetail
537+
->getRemittanceInformation()
538+
->getStructuredBlock()
539+
->getCreditorReferenceInformation()
540+
->getProprietary()
541+
);
542+
543+
self::assertNull(
544+
$transactionDetail
545+
->getRemittanceInformation()
546+
->getStructuredBlock()
547+
->getCreditorReferenceInformation()
548+
->getCode()
549+
);
550+
551+
self::assertEquals(
552+
'Additional Remittance Information V2',
553+
$transactionDetail
554+
->getRemittanceInformation()
555+
->getStructuredBlock()
556+
->getAdditionalRemittanceInformation()
557+
);
558+
559+
break;
560+
case 3:
561+
// Legacy : ref number from the first unstructured block
562+
self::assertEquals(
563+
'Unstructured Remittance Information V3 block 1',
564+
$transactionDetail
565+
->getRemittanceInformation()
566+
->getMessage()
567+
);
568+
569+
// First unstructured block
570+
self::assertEquals(
571+
'Unstructured Remittance Information V3 block 1',
572+
$transactionDetail
573+
->getRemittanceInformation()
574+
->getUnstructuredBlocks()[0]
575+
->getMessage()
576+
);
577+
578+
// Second unstructured block
579+
self::assertEquals(
580+
'Unstructured Remittance Information V3 block 2',
581+
$transactionDetail
582+
->getRemittanceInformation()
583+
->getUnstructuredBlocks()[1]
584+
->getMessage()
585+
);
586+
587+
// Ref number from the first structured block
588+
self::assertEquals(
589+
'Ref number V3 block 1',
590+
$transactionDetail
591+
->getRemittanceInformation()
592+
->getStructuredBlocks()[0]
593+
->getCreditorReferenceInformation()
594+
->getRef()
595+
);
596+
597+
// Ref number from the second structured block
598+
self::assertEquals(
599+
'Ref number V3 block 2',
600+
$transactionDetail
601+
->getRemittanceInformation()
602+
->getStructuredBlocks()[1]
603+
->getCreditorReferenceInformation()
604+
->getRef()
605+
);
606+
607+
// Code from the first structured block
608+
self::assertEquals(
609+
'SCOR',
610+
$transactionDetail
611+
->getRemittanceInformation()
612+
->getStructuredBlocks()[0]
613+
->getCreditorReferenceInformation()
614+
->getCode()
615+
);
616+
617+
// Code from the second structured block
618+
self::assertEquals(
619+
'SCOR',
620+
$transactionDetail
621+
->getRemittanceInformation()
622+
->getStructuredBlocks()[1]
623+
->getCreditorReferenceInformation()
624+
->getCode()
625+
);
626+
627+
// Additional remittance information from the first structured block
628+
self::assertEquals(
629+
'Additional Remittance Information V3 block 1',
630+
$transactionDetail
631+
->getRemittanceInformation()
632+
->getStructuredBlocks()[0]
633+
->getAdditionalRemittanceInformation()
634+
);
635+
636+
// Additional remittance information from the second structured block
637+
self::assertEquals(
638+
'Additional Remittance Information V3 block 2',
639+
$transactionDetail
640+
->getRemittanceInformation()
641+
->getStructuredBlocks()[1]
642+
->getAdditionalRemittanceInformation()
643+
);
644+
645+
break;
646+
default:
647+
break;
648+
}
649+
}
650+
}
651+
}
652+
}
379653
}

test/data/camt052.v2.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
"getTownName": null
165165
},
166166
"getName": "NAME NAME",
167-
"getOrgId": ""
167+
"getOrgId": null
168168
}
169169
}
170170
],

test/data/camt052.v2.other-account.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
"getTownName": null
161161
},
162162
"getName": "NAME NAME",
163-
"getOrgId": ""
163+
"getOrgId": null
164164
}
165165
}
166166
],

test/data/camt052.v4.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@
192192
"__CLASS__": "Genkgo\\Camt\\DTO\\Creditor",
193193
"getAddress": null,
194194
"getName": "UNIFITS GmbH",
195-
"getOrgId": ""
195+
"getOrgId": null
196196
}
197197
},
198198
{
@@ -220,7 +220,7 @@
220220
"getTownName": "Example Creditor Town 4 - V1"
221221
},
222222
"getName": "Example Creditor 4 - V1",
223-
"getOrgId": ""
223+
"getOrgId": null
224224
}
225225
}
226226
],

test/data/camt052.v6.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@
192192
"__CLASS__": "Genkgo\\Camt\\DTO\\Creditor",
193193
"getAddress": null,
194194
"getName": "UNIFITS GmbH",
195-
"getOrgId": ""
195+
"getOrgId": null
196196
}
197197
},
198198
{
@@ -220,7 +220,7 @@
220220
"getTownName": "Example Creditor Town 6 - V1"
221221
},
222222
"getName": "Example Creditor 6 - V1",
223-
"getOrgId": ""
223+
"getOrgId": null
224224
}
225225
}
226226
],

0 commit comments

Comments
 (0)