|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Genkgo\TestCamt\Unit\Camt054; |
|
6
|
|
|
|
|
7
|
|
|
use DateTimeImmutable; |
|
8
|
|
|
use DOMDocument; |
|
9
|
|
|
use Genkgo\Camt\Camt054\DTO as Camt054DTO; |
|
10
|
|
|
use Genkgo\Camt\Camt054\DTO\V04\GroupHeader; |
|
11
|
|
|
use Genkgo\Camt\Camt054\MessageFormat; |
|
12
|
|
|
use Genkgo\Camt\DTO; |
|
13
|
|
|
use Genkgo\Camt\DTO\Message; |
|
14
|
|
|
use Genkgo\Camt\DTO\OrganisationIdentification; |
|
15
|
|
|
use PHPUnit\Framework; |
|
16
|
|
|
|
|
17
|
|
|
class EndToEndTest extends Framework\TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
protected function getV2Message(): Message |
|
20
|
|
|
{ |
|
21
|
|
|
$dom = new DOMDocument('1.0', 'UTF-8'); |
|
22
|
|
|
$dom->load('test/data/camt054.v2.xml'); |
|
23
|
|
|
|
|
24
|
|
|
return (new MessageFormat\V02())->getDecoder()->decode($dom); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
protected function getV4Message(): Message |
|
28
|
|
|
{ |
|
29
|
|
|
$dom = new DOMDocument('1.0', 'UTF-8'); |
|
30
|
|
|
$dom->load('test/data/camt054.v4.xml'); |
|
31
|
|
|
|
|
32
|
|
|
return (new MessageFormat\V04())->getDecoder()->decode($dom); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
protected function getv8Message(): Message |
|
36
|
|
|
{ |
|
37
|
|
|
$dom = new DOMDocument('1.0', 'UTF-8'); |
|
38
|
|
|
$dom->load('test/data/camt054.v8.xml'); |
|
39
|
|
|
|
|
40
|
|
|
return (new MessageFormat\V08())->getDecoder()->decode($dom); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testGroupHeader(): void |
|
44
|
|
|
{ |
|
45
|
|
|
$messages = [ |
|
46
|
|
|
$this->getV2Message(), |
|
47
|
|
|
$this->getV4Message(), |
|
48
|
|
|
$this->getV8Message(), |
|
49
|
|
|
]; |
|
50
|
|
|
|
|
51
|
|
|
/** @var Message $message */ |
|
52
|
|
|
foreach ($messages as $message) { |
|
53
|
|
|
$groupHeader = $message->getGroupHeader(); |
|
54
|
|
|
|
|
55
|
|
|
self::assertInstanceOf(DTO\GroupHeader::class, $groupHeader); |
|
56
|
|
|
self::assertEquals('AAAASESS-FP-ACCR001', $groupHeader->getMessageId()); |
|
57
|
|
|
self::assertEquals(new DateTimeImmutable('2007-10-18T12:30:00+01:00'), $groupHeader->getCreatedOn()); |
|
58
|
|
|
self::assertEquals('Group header additional information', $groupHeader->getAdditionalInformation()); |
|
59
|
|
|
self::assertInstanceOf(DTO\Pagination::class, $groupHeader->getPagination()); |
|
60
|
|
|
self::assertEquals('1', $groupHeader->getPagination()->getPageNumber()); |
|
61
|
|
|
self::assertTrue($groupHeader->getPagination()->isLastPage()); |
|
62
|
|
|
$msgRecipient = $groupHeader->getMessageRecipient(); |
|
63
|
|
|
self::assertInstanceOf(DTO\Recipient::class, $msgRecipient); |
|
64
|
|
|
self::assertEquals('COMPANY BVBA', $msgRecipient->getName()); |
|
65
|
|
|
self::assertEquals('NL', $msgRecipient->getCountryOfResidence()); |
|
66
|
|
|
self::assertInstanceOf(DTO\Address::class, $msgRecipient->getAddress()); |
|
67
|
|
|
self::assertEquals('12 Oxford Street', $msgRecipient->getAddress()->getStreetName()); |
|
68
|
|
|
self::assertEquals('UK', $msgRecipient->getAddress()->getCountry()); |
|
69
|
|
|
|
|
70
|
|
|
/** @var OrganisationIdentification $identification */ |
|
71
|
|
|
$identification = $msgRecipient->getIdentification(); |
|
72
|
|
|
self::assertInstanceOf(DTO\Identification::class, $identification); |
|
73
|
|
|
self::assertEquals('DABAIE2D', $identification->getBic()); |
|
74
|
|
|
self::assertEquals('Some other Id', $identification->getOtherId()); |
|
75
|
|
|
self::assertEquals('Some other Issuer', $identification->getOtherIssuer()); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** @var GroupHeader $groupHeaderV4 */ |
|
79
|
|
|
$groupHeaderV4 = $messages[1]->getGroupHeader(); |
|
80
|
|
|
self::assertInstanceOf(GroupHeader::class, $groupHeaderV4); |
|
81
|
|
|
self::assertInstanceOf(Camt054DTO\V04\OriginalBusinessQuery::class, $groupHeaderV4->getOriginalBusinessQuery()); |
|
82
|
|
|
self::assertEquals('SomeMessageId', $groupHeaderV4->getOriginalBusinessQuery()->getMessageId()); |
|
83
|
|
|
self::assertEquals( |
|
84
|
|
|
'SomeMessageNameId', |
|
85
|
|
|
$groupHeaderV4->getOriginalBusinessQuery()->getMessageNameId() |
|
86
|
|
|
); |
|
87
|
|
|
self::assertEquals( |
|
88
|
|
|
new DateTimeImmutable('2010-10-18T12:30:00+01:00'), |
|
89
|
|
|
$groupHeaderV4->getOriginalBusinessQuery()->getCreatedOn() |
|
90
|
|
|
); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function testNotifications(): void |
|
94
|
|
|
{ |
|
95
|
|
|
$messages = [ |
|
96
|
|
|
$this->getV2Message(), |
|
97
|
|
|
$this->getV4Message(), |
|
98
|
|
|
$this->getV8Message(), |
|
99
|
|
|
]; |
|
100
|
|
|
|
|
101
|
|
|
foreach ($messages as $message) { |
|
102
|
|
|
$notifications = $message->getRecords(); |
|
103
|
|
|
|
|
104
|
|
|
self::assertCount(1, $notifications); |
|
105
|
|
|
foreach ($notifications as $notification) { |
|
106
|
|
|
self::assertInstanceOf(Camt054DTO\Notification::class, $notification); |
|
107
|
|
|
self::assertEquals('AAAASESS-FP-ACCR001', $notification->getId()); |
|
108
|
|
|
self::assertEquals('CH2801234000123456789', $notification->getAccount()->getIdentification()); |
|
109
|
|
|
self::assertEquals(new DateTimeImmutable('2007-10-18T12:30:00+01:00'), $notification->getCreatedOn()); |
|
110
|
|
|
self::assertEquals('12312', $notification->getElectronicSequenceNumber()); |
|
111
|
|
|
self::assertEquals('12312', $notification->getLegalSequenceNumber()); |
|
112
|
|
|
self::assertEquals('CODU', $notification->getCopyDuplicateIndicator()); |
|
113
|
|
|
self::assertEquals(new DateTimeImmutable('2007-10-18T08:00:00+01:00'), $notification->getFromDate()); |
|
114
|
|
|
self::assertEquals(new DateTimeImmutable('2007-10-18T12:30:00+01:00'), $notification->getToDate()); |
|
115
|
|
|
self::assertEquals('Additional Information', $notification->getAdditionalInformation()); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
$notificationV4 = $messages[1]->getRecords()[0]; |
|
120
|
|
|
self::assertInstanceOf(DTO\Pagination::class, $notificationV4->getPagination()); |
|
121
|
|
|
self::assertEquals('2', $notificationV4->getPagination()->getPageNumber()); |
|
122
|
|
|
self::assertTrue($notificationV4->getPagination()->isLastPage()); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public function testEntries(): void |
|
126
|
|
|
{ |
|
127
|
|
|
$messages = [ |
|
128
|
|
|
$this->getV2Message(), |
|
129
|
|
|
$this->getV4Message(), |
|
130
|
|
|
$this->getV8Message(), |
|
131
|
|
|
]; |
|
132
|
|
|
|
|
133
|
|
|
foreach ($messages as $message) { |
|
134
|
|
|
$notifications = $message->getRecords(); |
|
135
|
|
|
|
|
136
|
|
|
self::assertCount(1, $notifications); |
|
137
|
|
|
foreach ($notifications as $notification) { |
|
138
|
|
|
$entries = $notification->getEntries(); |
|
139
|
|
|
self::assertCount(1, $entries); |
|
140
|
|
|
|
|
141
|
|
|
foreach ($entries as $entry) { |
|
142
|
|
|
self::assertEquals(-20000000, $entry->getAmount()->getAmount()); |
|
143
|
|
|
self::assertEquals('SEK', $entry->getAmount()->getCurrency()->getCode()); |
|
144
|
|
|
self::assertEquals('2007-10-18', $entry->getBookingDate()->format('Y-m-d')); |
|
145
|
|
|
self::assertEquals('2007-10-18', $entry->getValueDate()->format('Y-m-d')); |
|
146
|
|
|
self::assertEquals('PMNT', $entry->getBankTransactionCode()->getDomain()->getCode()); |
|
147
|
|
|
self::assertEquals('ICDT', $entry->getBankTransactionCode()->getDomain()->getFamily()->getCode()); |
|
148
|
|
|
self::assertEquals('DMCT', $entry->getBankTransactionCode()->getDomain()->getFamily()->getSubFamilyCode()); |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
public function testTransactionDetails(): void |
|
155
|
|
|
{ |
|
156
|
|
|
$messages = [ |
|
157
|
|
|
$this->getV2Message(), |
|
158
|
|
|
$this->getV4Message(), |
|
159
|
|
|
$this->getV8Message(), |
|
160
|
|
|
]; |
|
161
|
|
|
|
|
162
|
|
|
foreach ($messages as $message) { |
|
163
|
|
|
$notifications = $message->getRecords(); |
|
164
|
|
|
|
|
165
|
|
|
self::assertCount(1, $notifications); |
|
166
|
|
|
foreach ($notifications as $notification) { |
|
167
|
|
|
$entries = $notification->getEntries(); |
|
168
|
|
|
|
|
169
|
|
|
self::assertCount(1, $entries); |
|
170
|
|
|
foreach ($entries as $entry) { |
|
171
|
|
|
$transactionDetails = $entry->getTransactionDetails(); |
|
172
|
|
|
|
|
173
|
|
|
self::assertCount(3, $transactionDetails); |
|
174
|
|
|
foreach ($transactionDetails as $index => $transactionDetail) { |
|
175
|
|
|
switch ($index) { |
|
176
|
|
|
case 0: |
|
177
|
|
|
// Legacy : The first message comes from unstructured block |
|
178
|
|
|
self::assertEquals( |
|
179
|
|
|
'Unstructured Remittance Information V1', |
|
180
|
|
|
$transactionDetail |
|
181
|
|
|
->getRemittanceInformation() |
|
182
|
|
|
->getMessage() |
|
183
|
|
|
); |
|
184
|
|
|
|
|
185
|
|
|
// Only one structured data block |
|
186
|
|
|
self::assertEquals( |
|
187
|
|
|
'Unstructured Remittance Information V1', |
|
188
|
|
|
$transactionDetail |
|
189
|
|
|
->getRemittanceInformation() |
|
190
|
|
|
->getUnstructuredBlock() |
|
191
|
|
|
->getMessage() |
|
192
|
|
|
); |
|
193
|
|
|
|
|
194
|
|
|
// Check structured and unstructured blocks |
|
195
|
|
|
self::assertEquals( |
|
196
|
|
|
'ISR ref number V1', |
|
197
|
|
|
$transactionDetail |
|
198
|
|
|
->getRemittanceInformation() |
|
199
|
|
|
->getStructuredBlock() |
|
200
|
|
|
->getCreditorReferenceInformation() |
|
201
|
|
|
->getRef() |
|
202
|
|
|
); |
|
203
|
|
|
|
|
204
|
|
|
self::assertEquals( |
|
205
|
|
|
'ISR Reference', |
|
206
|
|
|
$transactionDetail |
|
207
|
|
|
->getRemittanceInformation() |
|
208
|
|
|
->getStructuredBlock() |
|
209
|
|
|
->getCreditorReferenceInformation() |
|
210
|
|
|
->getProprietary() |
|
211
|
|
|
); |
|
212
|
|
|
|
|
213
|
|
|
self::assertNull( |
|
214
|
|
|
$transactionDetail |
|
215
|
|
|
->getRemittanceInformation() |
|
216
|
|
|
->getStructuredBlock() |
|
217
|
|
|
->getCreditorReferenceInformation() |
|
218
|
|
|
->getCode() |
|
219
|
|
|
); |
|
220
|
|
|
|
|
221
|
|
|
self::assertEquals( |
|
222
|
|
|
'Additional Remittance Information V1', |
|
223
|
|
|
$transactionDetail |
|
224
|
|
|
->getRemittanceInformation() |
|
225
|
|
|
->getStructuredBlock() |
|
226
|
|
|
->getAdditionalRemittanceInformation() |
|
227
|
|
|
); |
|
228
|
|
|
|
|
229
|
|
|
break; |
|
230
|
|
|
case 1: |
|
231
|
|
|
|
|
232
|
|
|
// Legacy : ref number from the structured information |
|
233
|
|
|
// because the unstructured block is not present |
|
234
|
|
|
self::assertEquals( |
|
235
|
|
|
'ISR ref number V2', |
|
236
|
|
|
$transactionDetail |
|
237
|
|
|
->getRemittanceInformation() |
|
238
|
|
|
->getMessage() |
|
239
|
|
|
); |
|
240
|
|
|
|
|
241
|
|
|
// No unstructured block |
|
242
|
|
|
self::assertCount( |
|
243
|
|
|
0, |
|
244
|
|
|
$transactionDetail |
|
245
|
|
|
->getRemittanceInformation() |
|
246
|
|
|
->getUnstructuredBlocks() |
|
247
|
|
|
); |
|
248
|
|
|
|
|
249
|
|
|
// Check structured and unstructured blocks |
|
250
|
|
|
self::assertEquals( |
|
251
|
|
|
'ISR ref number V2', |
|
252
|
|
|
$transactionDetail |
|
253
|
|
|
->getRemittanceInformation() |
|
254
|
|
|
->getStructuredBlock() |
|
255
|
|
|
->getCreditorReferenceInformation() |
|
256
|
|
|
->getRef() |
|
257
|
|
|
); |
|
258
|
|
|
|
|
259
|
|
|
self::assertEquals( |
|
260
|
|
|
'ISR Reference', |
|
261
|
|
|
$transactionDetail |
|
262
|
|
|
->getRemittanceInformation() |
|
263
|
|
|
->getStructuredBlock() |
|
264
|
|
|
->getCreditorReferenceInformation() |
|
265
|
|
|
->getProprietary() |
|
266
|
|
|
); |
|
267
|
|
|
|
|
268
|
|
|
self::assertNull( |
|
269
|
|
|
$transactionDetail |
|
270
|
|
|
->getRemittanceInformation() |
|
271
|
|
|
->getStructuredBlock() |
|
272
|
|
|
->getCreditorReferenceInformation() |
|
273
|
|
|
->getCode() |
|
274
|
|
|
); |
|
275
|
|
|
|
|
276
|
|
|
self::assertEquals( |
|
277
|
|
|
'Additional Remittance Information V2', |
|
278
|
|
|
$transactionDetail |
|
279
|
|
|
->getRemittanceInformation() |
|
280
|
|
|
->getStructuredBlock() |
|
281
|
|
|
->getAdditionalRemittanceInformation() |
|
282
|
|
|
); |
|
283
|
|
|
|
|
284
|
|
|
break; |
|
285
|
|
|
case 2: |
|
286
|
|
|
// Legacy : ref number from the first unstructured block |
|
287
|
|
|
self::assertEquals( |
|
288
|
|
|
'Unstructured Remittance Information V3 block 1', |
|
289
|
|
|
$transactionDetail |
|
290
|
|
|
->getRemittanceInformation() |
|
291
|
|
|
->getMessage() |
|
292
|
|
|
); |
|
293
|
|
|
|
|
294
|
|
|
// First unstructured block |
|
295
|
|
|
self::assertEquals( |
|
296
|
|
|
'Unstructured Remittance Information V3 block 1', |
|
297
|
|
|
$transactionDetail |
|
298
|
|
|
->getRemittanceInformation() |
|
299
|
|
|
->getUnstructuredBlocks()[0] |
|
300
|
|
|
->getMessage() |
|
301
|
|
|
); |
|
302
|
|
|
|
|
303
|
|
|
// Second unstructured block |
|
304
|
|
|
self::assertEquals( |
|
305
|
|
|
'Unstructured Remittance Information V3 block 2', |
|
306
|
|
|
$transactionDetail |
|
307
|
|
|
->getRemittanceInformation() |
|
308
|
|
|
->getUnstructuredBlocks()[1] |
|
309
|
|
|
->getMessage() |
|
310
|
|
|
); |
|
311
|
|
|
|
|
312
|
|
|
// Ref number from the first structured block |
|
313
|
|
|
self::assertEquals( |
|
314
|
|
|
'Ref number V3 block 1', |
|
315
|
|
|
$transactionDetail |
|
316
|
|
|
->getRemittanceInformation() |
|
317
|
|
|
->getStructuredBlocks()[0] |
|
318
|
|
|
->getCreditorReferenceInformation() |
|
319
|
|
|
->getRef() |
|
320
|
|
|
); |
|
321
|
|
|
|
|
322
|
|
|
// Ref number from the second structured block |
|
323
|
|
|
self::assertEquals( |
|
324
|
|
|
'Ref number V3 block 2', |
|
325
|
|
|
$transactionDetail |
|
326
|
|
|
->getRemittanceInformation() |
|
327
|
|
|
->getStructuredBlocks()[1] |
|
328
|
|
|
->getCreditorReferenceInformation() |
|
329
|
|
|
->getRef() |
|
330
|
|
|
); |
|
331
|
|
|
|
|
332
|
|
|
// Code from the first structured block |
|
333
|
|
|
self::assertEquals( |
|
334
|
|
|
'SCOR', |
|
335
|
|
|
$transactionDetail |
|
336
|
|
|
->getRemittanceInformation() |
|
337
|
|
|
->getStructuredBlocks()[0] |
|
338
|
|
|
->getCreditorReferenceInformation() |
|
339
|
|
|
->getCode() |
|
340
|
|
|
); |
|
341
|
|
|
|
|
342
|
|
|
// Code from the second structured block |
|
343
|
|
|
self::assertEquals( |
|
344
|
|
|
'SCOR', |
|
345
|
|
|
$transactionDetail |
|
346
|
|
|
->getRemittanceInformation() |
|
347
|
|
|
->getStructuredBlocks()[1] |
|
348
|
|
|
->getCreditorReferenceInformation() |
|
349
|
|
|
->getCode() |
|
350
|
|
|
); |
|
351
|
|
|
|
|
352
|
|
|
// Additional remittance information from the first structured block |
|
353
|
|
|
self::assertEquals( |
|
354
|
|
|
'Additional Remittance Information V3 block 1', |
|
355
|
|
|
$transactionDetail |
|
356
|
|
|
->getRemittanceInformation() |
|
357
|
|
|
->getStructuredBlocks()[0] |
|
358
|
|
|
->getAdditionalRemittanceInformation() |
|
359
|
|
|
); |
|
360
|
|
|
|
|
361
|
|
|
// Additional remittance information from the second structured block |
|
362
|
|
|
self::assertEquals( |
|
363
|
|
|
'Additional Remittance Information V3 block 2', |
|
364
|
|
|
$transactionDetail |
|
365
|
|
|
->getRemittanceInformation() |
|
366
|
|
|
->getStructuredBlocks()[1] |
|
367
|
|
|
->getAdditionalRemittanceInformation() |
|
368
|
|
|
); |
|
369
|
|
|
|
|
370
|
|
|
break; |
|
371
|
|
|
default: |
|
372
|
|
|
break; |
|
373
|
|
|
} |
|
374
|
|
|
} |
|
375
|
|
|
} |
|
376
|
|
|
} |
|
377
|
|
|
} |
|
378
|
|
|
} |
|
379
|
|
|
} |
|
380
|
|
|
|