Skip to content

Commit 8f8c98a

Browse files
Merge pull request #221 from linushstge/master
Fix of wrong NbOfTxs and CtrlSum and add custom EndToEndId with purposeCode
2 parents a1e4ef5 + 34c7f0c commit 8f8c98a

File tree

1 file changed

+50
-14
lines changed

1 file changed

+50
-14
lines changed

src/Builders/CustomerCreditTransfer/CustomerCreditTransferBuilder.php

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,15 @@ private function createCreditTransferTransactionElement(
243243
$xmlCtrlSum = DOMHelper::safeItem($ctrlSumList);
244244
$xmlCtrlSum->nodeValue = number_format($ctrlSum + $amount, 2, '.', '');
245245

246+
//update PmtInf
247+
$nbOfTxsList = $xpath->query('//CstmrCdtTrfInitn/PmtInf/NbOfTxs');
248+
$xmlNbOfTxs = DOMHelper::safeItem($nbOfTxsList);
249+
$xmlNbOfTxs->nodeValue = (string) $nbOfTxs;
250+
251+
$ctrlSumList = $xpath->query('//CstmrCdtTrfInitn/PmtInf/CtrlSum');
252+
$xmlCtrlSum = DOMHelper::safeItem($ctrlSumList);
253+
$xmlCtrlSum->nodeValue = number_format($ctrlSum + $amount, 2, '.', '');
254+
246255
return $xmlCdtTrfTxInf;
247256
}
248257

@@ -263,7 +272,8 @@ private function addCreditor(
263272
string $creditorIBAN,
264273
string $creditorName,
265274
?PostalAddressInterface $postalAddress,
266-
?string $purpose = null
275+
?string $purposeText = null,
276+
?string $purposeCode = null
267277
): void {
268278
//agent
269279
if ($creditorFinInstBIC !== null) {
@@ -301,13 +311,23 @@ private function addCreditor(
301311
$xmlIBAN->nodeValue = str_replace(' ', '', $creditorIBAN);
302312
$xmlId->appendChild($xmlIBAN);
303313

304-
// Purpose
305-
if ($purpose !== null) {
314+
// Purpose - Code
315+
if ($purposeCode) {
316+
$xmlPurp = $this->instance->createElement('Purp');
317+
$xmlCdtTrfTxInf->appendChild($xmlPurp);
318+
319+
$xmlCd = $this->instance->createElement('Cd');
320+
$xmlCd->nodeValue = $purposeCode;
321+
$xmlPurp->appendChild($xmlCd);
322+
}
323+
324+
// Purpose - Text
325+
if ($purposeText !== null) {
306326
$xmlRmtInf = $this->instance->createElement('RmtInf');
307327
$xmlCdtTrfTxInf->appendChild($xmlRmtInf);
308328

309329
$xmlUstrd = $this->instance->createElement('Ustrd');
310-
$xmlUstrd->nodeValue = $purpose;
330+
$xmlUstrd->nodeValue = $purposeText;
311331
$xmlRmtInf->appendChild($xmlUstrd);
312332
}
313333
}
@@ -318,17 +338,27 @@ public function addBankTransaction(
318338
?PostalAddressInterface $postalAddress,
319339
float $amount,
320340
string $currency,
321-
?string $purpose = null
341+
?string $purposeText = null,
342+
?string $endToEndId = null,
343+
?string $purposeCode = null,
322344
): CustomerCreditTransferBuilder {
323345
if ($currency !== 'EUR') {
324346
throw new InvalidArgumentException('The SEPA transaction is restricted to EUR currency.');
325347
}
326348

327-
$xmlCdtTrfTxInf = $this->createCreditTransferTransactionElement($amount);
349+
$xmlCdtTrfTxInf = $this->createCreditTransferTransactionElement($amount, null, $endToEndId);
328350

329351
$this->addAmountElement($xmlCdtTrfTxInf, $amount, $currency);
330352

331-
$this->addCreditor($xmlCdtTrfTxInf, null, $creditorIBAN, $creditorName, $postalAddress, $purpose);
353+
$this->addCreditor(
354+
$xmlCdtTrfTxInf,
355+
null,
356+
$creditorIBAN,
357+
$creditorName,
358+
$postalAddress,
359+
$purposeText,
360+
$purposeCode
361+
);
332362

333363
return $this;
334364
}
@@ -340,14 +370,16 @@ public function addSEPATransaction(
340370
?PostalAddressInterface $postalAddress,
341371
float $amount,
342372
string $currency,
343-
?string $purpose = null,
344-
?string $chargeBearer = null
373+
?string $purposeText = null,
374+
?string $chargeBearer = null,
375+
?string $endToEndId = null,
376+
?string $purposeCode = null
345377
): CustomerCreditTransferBuilder {
346378
if ($currency !== 'EUR') {
347379
throw new InvalidArgumentException('The SEPA transaction is restricted to EUR currency.');
348380
}
349381

350-
$xmlCdtTrfTxInf = $this->createCreditTransferTransactionElement($amount);
382+
$xmlCdtTrfTxInf = $this->createCreditTransferTransactionElement($amount, null, $endToEndId);
351383

352384
// Payment Type Information
353385
$xmlPmtTpInf = $this->instance->createElement('PmtTpInf');
@@ -376,7 +408,8 @@ public function addSEPATransaction(
376408
$creditorIBAN,
377409
$creditorName,
378410
$postalAddress,
379-
$purpose
411+
$purposeText,
412+
$purposeCode,
380413
);
381414

382415
return $this;
@@ -389,9 +422,11 @@ public function addForeignTransaction(
389422
?PostalAddressInterface $postalAddress,
390423
float $amount,
391424
string $currency,
392-
?string $purpose = null
425+
?string $purposeText = null,
426+
?string $endToEndId = null,
427+
?string $purposeCode = null
393428
): CustomerCreditTransferBuilder {
394-
$xmlCdtTrfTxInf = $this->createCreditTransferTransactionElement($amount);
429+
$xmlCdtTrfTxInf = $this->createCreditTransferTransactionElement($amount, null, $endToEndId);
395430

396431
$this->addAmountElement($xmlCdtTrfTxInf, $amount, $currency);
397432

@@ -401,7 +436,8 @@ public function addForeignTransaction(
401436
$creditorIBAN,
402437
$creditorName,
403438
$postalAddress,
404-
$purpose
439+
$purposeText,
440+
$purposeCode,
405441
);
406442

407443
return $this;

0 commit comments

Comments
 (0)