From 32dc9b280193c9a190c5728c004eca23d0cb05f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BCrk?= Date: Thu, 25 May 2023 10:15:34 +0200 Subject: [PATCH] [FEATURE] Add `CreditDebitIdentifier` to entry transaction detail The credit-debit-identifier (CrdDbtInd) have been used for several details, e.g. amount, to proper represent values. The information itself is not added. As it could not be reliable retrieved from subvalues what the original state was, this change now adds that detail directly to the transaction details and the entry itself. Test fixture files are updated to contain the added fields. Resolves: #146 Related: #116 --- src/DTO/Entry.php | 12 ++++++++++++ src/DTO/EntryTransactionDetail.php | 12 ++++++++++++ src/Decoder/Entry.php | 1 + src/Decoder/EntryTransactionDetail.php | 9 +++++++++ src/Decoder/Record.php | 4 ++++ test/data/camt052.v1.json | 1 + test/data/camt052.v2.json | 2 ++ test/data/camt052.v2.other-account.json | 2 ++ test/data/camt052.v4.json | 2 ++ test/data/camt052.v6.json | 2 ++ test/data/camt052.v8.json | 1 + test/data/camt053.v2.five.decimals.json | 2 ++ test/data/camt053.v2.minimal.json | 2 ++ test/data/camt053.v2.minimal.ultimate.json | 2 ++ test/data/camt053.v2.multi.statement.json | 2 ++ test/data/camt053.v3.json | 2 ++ test/data/camt053.v4.json | 2 ++ test/data/camt053.v8.json | 2 ++ test/data/camt054.v2.json | 4 ++++ test/data/camt054.v4.json | 4 ++++ test/data/camt054.v8-with-UETR.json | 2 ++ test/data/camt054.v8-with-financial-institution.json | 2 ++ test/data/camt054.v8.json | 4 ++++ 23 files changed, 78 insertions(+) diff --git a/src/DTO/Entry.php b/src/DTO/Entry.php index 9f7acfa..4dff2d2 100644 --- a/src/DTO/Entry.php +++ b/src/DTO/Entry.php @@ -40,6 +40,8 @@ class Entry private ?string $status = null; + private ?string $creditDebitIndicator = null; + public function __construct(Record $record, int $index, Money $amount) { $this->record = $record; @@ -186,4 +188,14 @@ public function setStatus(?string $status): void { $this->status = $status; } + + public function getCreditDebitIndicator(): ?string + { + return $this->creditDebitIndicator; + } + + public function setCreditDebitIndicator(?string $creditDebitIndicator): void + { + $this->creditDebitIndicator = $creditDebitIndicator; + } } diff --git a/src/DTO/EntryTransactionDetail.php b/src/DTO/EntryTransactionDetail.php index 028e477..27a186f 100644 --- a/src/DTO/EntryTransactionDetail.php +++ b/src/DTO/EntryTransactionDetail.php @@ -36,6 +36,8 @@ class EntryTransactionDetail private ?Money $amount = null; + private ?string $creditDebitIndicator = null; + public function setReference(?Reference $reference): void { $this->reference = $reference; @@ -169,4 +171,14 @@ public function setAmount(?Money $amount): void { $this->amount = $amount; } + + public function getCreditDebitIndicator(): ?string + { + return $this->creditDebitIndicator; + } + + public function setCreditDebitIndicator(?string $creditDebitIndicator): void + { + $this->creditDebitIndicator = $creditDebitIndicator; + } } diff --git a/src/Decoder/Entry.php b/src/Decoder/Entry.php index 33b86ef..9e03673 100644 --- a/src/Decoder/Entry.php +++ b/src/Decoder/Entry.php @@ -23,6 +23,7 @@ public function addTransactionDetails(DTO\Entry $entry, SimpleXMLElement $xmlEnt if ($xmlDetails !== null) { foreach ($xmlDetails as $xmlDetail) { $detail = new DTO\EntryTransactionDetail(); + $this->entryTransactionDetailDecoder->addCreditDebitIdentifier($detail, $xmlEntry->CdtDbtInd); $this->entryTransactionDetailDecoder->addReference($detail, $xmlDetail); $this->entryTransactionDetailDecoder->addRelatedParties($detail, $xmlDetail); $this->entryTransactionDetailDecoder->addRelatedAgents($detail, $xmlDetail); diff --git a/src/Decoder/EntryTransactionDetail.php b/src/Decoder/EntryTransactionDetail.php index 2f4f369..6bbfa03 100644 --- a/src/Decoder/EntryTransactionDetail.php +++ b/src/Decoder/EntryTransactionDetail.php @@ -26,6 +26,15 @@ public function __construct(DateDecoderInterface $dateDecoder) $this->moneyFactory = new MoneyFactory(); } + public function addCreditDebitIdentifier(DTO\EntryTransactionDetail $detail, SimpleXMLElement $CdtDbtInd): void + { + $creditDebitIdentifier = (string) $CdtDbtInd; + $creditDebitIdentifier = in_array($creditDebitIdentifier, ['CRDT', 'DBIT'], true) + ? $creditDebitIdentifier + : null; + $detail->setCreditDebitIndicator($creditDebitIdentifier); + } + public function addReference(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail): void { if (false === isset($xmlDetail->Refs)) { diff --git a/src/Decoder/Record.php b/src/Decoder/Record.php index 2e5fe42..b468aa4 100644 --- a/src/Decoder/Record.php +++ b/src/Decoder/Record.php @@ -121,6 +121,10 @@ public function addEntries(DTO\Record $record, SimpleXMLElement $xmlRecord): voi $entry->setBatchPaymentId((string) $xmlEntry->NtryDtls->TxDtls->Refs->PmtInfId); } + if (isset($xmlEntry->CdtDbtInd) && in_array((string) $xmlEntry->CdtDbtInd, ['CRDT', 'DBIT'], true)) { + $entry->setCreditDebitIndicator((string) $xmlEntry->CdtDbtInd); + } + $entry->setStatus($this->readStatus($xmlEntry)); if (isset($xmlEntry->BkTxCd)) { diff --git a/test/data/camt052.v1.json b/test/data/camt052.v1.json index 3b43659..1ea3d02 100644 --- a/test/data/camt052.v1.json +++ b/test/data/camt052.v1.json @@ -32,6 +32,7 @@ "0": "2007-10-18T09:15:00+00:00" }, "getCharges": null, + "getCreditDebitIndicator": "DBIT", "getIndex": 0, "getRecord": { "__CLASS__": "Genkgo\\Camt\\Camt052\\DTO\\Report", diff --git a/test/data/camt052.v2.json b/test/data/camt052.v2.json index 4fac33f..f8cdaa8 100644 --- a/test/data/camt052.v2.json +++ b/test/data/camt052.v2.json @@ -36,6 +36,7 @@ "0": "2007-10-18T09:15:00+00:00" }, "getCharges": null, + "getCreditDebitIndicator": "DBIT", "getIndex": 0, "getRecord": { "__CLASS__": "Genkgo\\Camt\\Camt052\\DTO\\Report", @@ -86,6 +87,7 @@ } }, "getCharges": null, + "getCreditDebitIndicator": "DBIT", "getReference": null, "getRelatedAgent": { "__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent", diff --git a/test/data/camt052.v2.other-account.json b/test/data/camt052.v2.other-account.json index 7917f8b..f7f5443 100644 --- a/test/data/camt052.v2.other-account.json +++ b/test/data/camt052.v2.other-account.json @@ -36,6 +36,7 @@ "0": "2007-10-18T09:15:00+00:00" }, "getCharges": null, + "getCreditDebitIndicator": "DBIT", "getIndex": 0, "getRecord": { "__CLASS__": "Genkgo\\Camt\\Camt052\\DTO\\Report", @@ -86,6 +87,7 @@ } }, "getCharges": null, + "getCreditDebitIndicator": "DBIT", "getReference": null, "getRelatedAgent": { "__CLASS__": "Genkgo\\Camt\\DTO\\RelatedAgent", diff --git a/test/data/camt052.v4.json b/test/data/camt052.v4.json index b772760..71a7b92 100644 --- a/test/data/camt052.v4.json +++ b/test/data/camt052.v4.json @@ -36,6 +36,7 @@ "0": "2007-10-18T00:00:00+00:00" }, "getCharges": null, + "getCreditDebitIndicator": "DBIT", "getIndex": 0, "getRecord": { "__CLASS__": "Genkgo\\Camt\\Camt052\\DTO\\Report", @@ -139,6 +140,7 @@ } } }, + "getCreditDebitIndicator": "DBIT", "getReference": { "__CLASS__": "Genkgo\\Camt\\DTO\\Reference", "getAccountOwnerTransactionId": null, diff --git a/test/data/camt052.v6.json b/test/data/camt052.v6.json index 4bd6bf0..0879fe5 100644 --- a/test/data/camt052.v6.json +++ b/test/data/camt052.v6.json @@ -36,6 +36,7 @@ "0": "2007-10-18T00:00:00+00:00" }, "getCharges": null, + "getCreditDebitIndicator": "DBIT", "getIndex": 0, "getRecord": { "__CLASS__": "Genkgo\\Camt\\Camt052\\DTO\\Report", @@ -139,6 +140,7 @@ } } }, + "getCreditDebitIndicator": "DBIT", "getReference": { "__CLASS__": "Genkgo\\Camt\\DTO\\Reference", "getAccountOwnerTransactionId": null, diff --git a/test/data/camt052.v8.json b/test/data/camt052.v8.json index d95b33d..b901bb7 100644 --- a/test/data/camt052.v8.json +++ b/test/data/camt052.v8.json @@ -32,6 +32,7 @@ "0": "2007-10-18T09:15:00+00:00" }, "getCharges": null, + "getCreditDebitIndicator": "DBIT", "getIndex": 0, "getRecord": { "__CLASS__": "Genkgo\\Camt\\Camt052\\DTO\\Report", diff --git a/test/data/camt053.v2.five.decimals.json b/test/data/camt053.v2.five.decimals.json index 2b5eb4a..d8f6981 100644 --- a/test/data/camt053.v2.five.decimals.json +++ b/test/data/camt053.v2.five.decimals.json @@ -28,6 +28,7 @@ "0": "2014-12-31T00:00:00+00:00" }, "getCharges": null, + "getCreditDebitIndicator": "CRDT", "getIndex": 0, "getRecord": { "__CLASS__": "Genkgo\\Camt\\Camt053\\DTO\\Statement", @@ -107,6 +108,7 @@ } }, "getCharges": null, + "getCreditDebitIndicator": "CRDT", "getReference": { "__CLASS__": "Genkgo\\Camt\\DTO\\Reference", "getAccountOwnerTransactionId": null, diff --git a/test/data/camt053.v2.minimal.json b/test/data/camt053.v2.minimal.json index a7ac52d..cbe15a0 100644 --- a/test/data/camt053.v2.minimal.json +++ b/test/data/camt053.v2.minimal.json @@ -28,6 +28,7 @@ "0": "2014-12-31T00:00:00+00:00" }, "getCharges": null, + "getCreditDebitIndicator": "CRDT", "getIndex": 0, "getRecord": { "__CLASS__": "Genkgo\\Camt\\Camt053\\DTO\\Statement", @@ -145,6 +146,7 @@ } }, "getCharges": null, + "getCreditDebitIndicator": "CRDT", "getReference": { "__CLASS__": "Genkgo\\Camt\\DTO\\Reference", "getAccountOwnerTransactionId": null, diff --git a/test/data/camt053.v2.minimal.ultimate.json b/test/data/camt053.v2.minimal.ultimate.json index 3937683..4480113 100644 --- a/test/data/camt053.v2.minimal.ultimate.json +++ b/test/data/camt053.v2.minimal.ultimate.json @@ -28,6 +28,7 @@ "0": "2014-12-31T00:00:00+00:00" }, "getCharges": null, + "getCreditDebitIndicator": "CRDT", "getIndex": 0, "getRecord": { "__CLASS__": "Genkgo\\Camt\\Camt053\\DTO\\Statement", @@ -145,6 +146,7 @@ } }, "getCharges": null, + "getCreditDebitIndicator": "CRDT", "getReference": { "__CLASS__": "Genkgo\\Camt\\DTO\\Reference", "getAccountOwnerTransactionId": null, diff --git a/test/data/camt053.v2.multi.statement.json b/test/data/camt053.v2.multi.statement.json index 57660b7..a911ef3 100644 --- a/test/data/camt053.v2.multi.statement.json +++ b/test/data/camt053.v2.multi.statement.json @@ -28,6 +28,7 @@ "0": "2014-12-31T00:00:00+00:00" }, "getCharges": null, + "getCreditDebitIndicator": "DBIT", "getIndex": 0, "getRecord": { "__CLASS__": "Genkgo\\Camt\\Camt053\\DTO\\Statement", @@ -107,6 +108,7 @@ } }, "getCharges": null, + "getCreditDebitIndicator": "DBIT", "getReference": { "__CLASS__": "Genkgo\\Camt\\DTO\\Reference", "getAccountOwnerTransactionId": null, diff --git a/test/data/camt053.v3.json b/test/data/camt053.v3.json index 840ac4d..e983811 100644 --- a/test/data/camt053.v3.json +++ b/test/data/camt053.v3.json @@ -36,6 +36,7 @@ "0": "2014-12-31T00:00:00+00:00" }, "getCharges": null, + "getCreditDebitIndicator": "CRDT", "getIndex": 0, "getRecord": { "__CLASS__": "Genkgo\\Camt\\Camt053\\DTO\\Statement", @@ -154,6 +155,7 @@ "getProprietary": null }, "getCharges": null, + "getCreditDebitIndicator": "CRDT", "getReference": { "__CLASS__": "Genkgo\\Camt\\DTO\\Reference", "getAccountOwnerTransactionId": null, diff --git a/test/data/camt053.v4.json b/test/data/camt053.v4.json index 5c1ee9f..0a7cfb3 100644 --- a/test/data/camt053.v4.json +++ b/test/data/camt053.v4.json @@ -32,6 +32,7 @@ "0": "2014-12-31T00:00:00+00:00" }, "getCharges": null, + "getCreditDebitIndicator": "CRDT", "getIndex": 0, "getRecord": { "__CLASS__": "Genkgo\\Camt\\Camt053\\DTO\\Statement", @@ -153,6 +154,7 @@ "getProprietary": null }, "getCharges": null, + "getCreditDebitIndicator": "CRDT", "getReference": { "__CLASS__": "Genkgo\\Camt\\DTO\\Reference", "getAccountOwnerTransactionId": null, diff --git a/test/data/camt053.v8.json b/test/data/camt053.v8.json index f7a03ed..a847bbc 100644 --- a/test/data/camt053.v8.json +++ b/test/data/camt053.v8.json @@ -32,6 +32,7 @@ "0": "2014-12-31T12:15:00+00:00" }, "getCharges": null, + "getCreditDebitIndicator": "CRDT", "getIndex": 0, "getRecord": { "__CLASS__": "Genkgo\\Camt\\Camt053\\DTO\\Statement", @@ -153,6 +154,7 @@ "getProprietary": null }, "getCharges": null, + "getCreditDebitIndicator": "CRDT", "getReference": { "__CLASS__": "Genkgo\\Camt\\DTO\\Reference", "getAccountOwnerTransactionId": null, diff --git a/test/data/camt054.v2.json b/test/data/camt054.v2.json index 71813ab..b1e0b35 100644 --- a/test/data/camt054.v2.json +++ b/test/data/camt054.v2.json @@ -32,6 +32,7 @@ "0": "2007-10-18T12:15:00+00:00" }, "getCharges": null, + "getCreditDebitIndicator": "DBIT", "getIndex": 0, "getRecord": { "__CLASS__": "Genkgo\\Camt\\Camt054\\DTO\\Notification", @@ -77,6 +78,7 @@ "getProprietary": null }, "getCharges": null, + "getCreditDebitIndicator": "DBIT", "getReference": { "__CLASS__": "Genkgo\\Camt\\DTO\\Reference", "getAccountOwnerTransactionId": null, @@ -150,6 +152,7 @@ "getProprietary": null }, "getCharges": null, + "getCreditDebitIndicator": "DBIT", "getReference": { "__CLASS__": "Genkgo\\Camt\\DTO\\Reference", "getAccountOwnerTransactionId": null, @@ -216,6 +219,7 @@ "getProprietary": null }, "getCharges": null, + "getCreditDebitIndicator": "DBIT", "getReference": { "__CLASS__": "Genkgo\\Camt\\DTO\\Reference", "getAccountOwnerTransactionId": null, diff --git a/test/data/camt054.v4.json b/test/data/camt054.v4.json index 3341e45..bfea1e3 100644 --- a/test/data/camt054.v4.json +++ b/test/data/camt054.v4.json @@ -36,6 +36,7 @@ "0": "2007-10-18T00:00:00+00:00" }, "getCharges": null, + "getCreditDebitIndicator": "DBIT", "getIndex": 0, "getRecord": { "__CLASS__": "Genkgo\\Camt\\Camt054\\DTO\\Notification", @@ -112,6 +113,7 @@ } }, "getCharges": null, + "getCreditDebitIndicator": "DBIT", "getReference": { "__CLASS__": "Genkgo\\Camt\\DTO\\Reference", "getAccountOwnerTransactionId": null, @@ -262,6 +264,7 @@ } }, "getCharges": null, + "getCreditDebitIndicator": "DBIT", "getReference": { "__CLASS__": "Genkgo\\Camt\\DTO\\Reference", "getAccountOwnerTransactionId": null, @@ -405,6 +408,7 @@ } }, "getCharges": null, + "getCreditDebitIndicator": "DBIT", "getReference": { "__CLASS__": "Genkgo\\Camt\\DTO\\Reference", "getAccountOwnerTransactionId": null, diff --git a/test/data/camt054.v8-with-UETR.json b/test/data/camt054.v8-with-UETR.json index 037d47c..e219721 100644 --- a/test/data/camt054.v8-with-UETR.json +++ b/test/data/camt054.v8-with-UETR.json @@ -21,6 +21,7 @@ "getBatchPaymentId": null, "getBookingDate": null, "getCharges": null, + "getCreditDebitIndicator": "DBIT", "getIndex": 0, "getRecord": { "__CLASS__": "Genkgo\\Camt\\Camt054\\DTO\\Notification", @@ -62,6 +63,7 @@ "getProprietary": null }, "getCharges": null, + "getCreditDebitIndicator": "DBIT", "getReference": { "__CLASS__": "Genkgo\\Camt\\DTO\\Reference", "getAccountOwnerTransactionId": null, diff --git a/test/data/camt054.v8-with-financial-institution.json b/test/data/camt054.v8-with-financial-institution.json index a9b2863..947ae78 100644 --- a/test/data/camt054.v8-with-financial-institution.json +++ b/test/data/camt054.v8-with-financial-institution.json @@ -21,6 +21,7 @@ "getBatchPaymentId": null, "getBookingDate": null, "getCharges": null, + "getCreditDebitIndicator": "DBIT", "getIndex": 0, "getRecord": { "__CLASS__": "Genkgo\\Camt\\Camt054\\DTO\\Notification", @@ -62,6 +63,7 @@ "getProprietary": null }, "getCharges": null, + "getCreditDebitIndicator": "DBIT", "getReference": null, "getRelatedAgent": null, "getRelatedAgents": [], diff --git a/test/data/camt054.v8.json b/test/data/camt054.v8.json index 3341e45..bfea1e3 100644 --- a/test/data/camt054.v8.json +++ b/test/data/camt054.v8.json @@ -36,6 +36,7 @@ "0": "2007-10-18T00:00:00+00:00" }, "getCharges": null, + "getCreditDebitIndicator": "DBIT", "getIndex": 0, "getRecord": { "__CLASS__": "Genkgo\\Camt\\Camt054\\DTO\\Notification", @@ -112,6 +113,7 @@ } }, "getCharges": null, + "getCreditDebitIndicator": "DBIT", "getReference": { "__CLASS__": "Genkgo\\Camt\\DTO\\Reference", "getAccountOwnerTransactionId": null, @@ -262,6 +264,7 @@ } }, "getCharges": null, + "getCreditDebitIndicator": "DBIT", "getReference": { "__CLASS__": "Genkgo\\Camt\\DTO\\Reference", "getAccountOwnerTransactionId": null, @@ -405,6 +408,7 @@ } }, "getCharges": null, + "getCreditDebitIndicator": "DBIT", "getReference": { "__CLASS__": "Genkgo\\Camt\\DTO\\Reference", "getAccountOwnerTransactionId": null,