Skip to content

Commit 3909ec5

Browse files
committed
Refactoring for CCT Builder
1 parent ec50802 commit 3909ec5

8 files changed

Lines changed: 538 additions & 538 deletions

src/Builders/CustomerCreditTransfer/CustomerCreditTransferBuilder.php

Lines changed: 0 additions & 453 deletions
This file was deleted.

src/Builders/Document/CustomerCreditTransferBuilder.php

Lines changed: 330 additions & 69 deletions
Large diffs are not rendered by default.

src/Builders/CustomerDirectDebit/CustomerDirectDebitBuilder.php renamed to src/Builders/Document/CustomerDirectDebitBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace EbicsApi\Ebics\Builders\CustomerDirectDebit;
3+
namespace EbicsApi\Ebics\Builders\Document;
44

55
use DateTime;
66
use EbicsApi\Ebics\Handlers\Traits\XPathTrait;

src/Builders/CustomerCreditTransfer/CustomerInstantCreditTransferBuilder.php renamed to src/Builders/Document/CustomerInstantCreditTransferBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace EbicsApi\Ebics\Builders\CustomerCreditTransfer;
3+
namespace EbicsApi\Ebics\Builders\Document;
44

55
use DateTime;
66
use EbicsApi\Ebics\Handlers\Traits\XPathTrait;

src/Builders/CustomerCreditTransfer/CustomerSwissCreditTransferBuilder.php renamed to src/Builders/Document/CustomerSwissCreditTransferBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace EbicsApi\Ebics\Builders\CustomerCreditTransfer;
3+
namespace EbicsApi\Ebics\Builders\Document;
44

55
use DateTime;
66
use DOMElement;
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace EbicsApi\Ebics\Builders\Document;
4+
5+
use DateTime;
6+
use EbicsApi\Ebics\Contracts\PostalAddressInterface;
7+
use EbicsApi\Ebics\Models\CustomerCreditTransfer;
8+
use InvalidArgumentException;
9+
10+
/**
11+
* CustomerCreditTransferBuilder
12+
* Corresponds to EbicsApi\Ebics\Builders\CustomerCreditTransfer\CustomerCreditTransferBuilder but with namespaces
13+
*
14+
* @license http://www.opensource.org/licenses/mit-license.html MIT License
15+
* @author Jan-Philipp Georg (moori)
16+
*/
17+
final class CustomerUrgentCreditTransferBuilder extends DocumentBuilder
18+
{
19+
public function createInstance(
20+
string $debitorFinInstBIC,
21+
string $debitorIBAN,
22+
string $debitorName,
23+
?DateTime $executionDate = null,
24+
bool $batchBooking = true,
25+
?string $msgId = null,
26+
?string $paymentReference = null,
27+
?string $chargeBearer = null
28+
): self {
29+
$this->instance = new CustomerCreditTransfer();
30+
$now = new DateTime();
31+
32+
$doc = $this->el('Document');
33+
$doc->setAttributeNS(
34+
'http://www.w3.org/2000/xmlns/',
35+
'xmlns:xsi',
36+
'http://www.w3.org/2001/XMLSchema-instance'
37+
);
38+
$doc->setAttributeNS(
39+
'http://www.w3.org/2001/XMLSchema-instance',
40+
'xsi:schemaLocation',
41+
$this->schemaLocation()
42+
);
43+
$this->instance->appendChild($doc);
44+
45+
$ccti = $this->el('CstmrCdtTrfInitn');
46+
$doc->appendChild($ccti);
47+
48+
$grpHdr = $this->el('GrpHdr');
49+
$ccti->appendChild($grpHdr);
50+
$grpHdr->appendChild(
51+
$this->el('MsgId', $msgId ?: $this->randomService->uniqueIdWithDate('msg'))
52+
);
53+
$grpHdr->appendChild($this->el('CreDtTm', $now->format('Y-m-d\TH:i:s\Z')));
54+
$grpHdr->appendChild($this->el('NbOfTxs', '0'));
55+
$grpHdr->appendChild($this->el('CtrlSum', '0'));
56+
57+
$initg = $this->el('InitgPty');
58+
$initg->appendChild($this->el('Nm', $debitorName));
59+
$grpHdr->appendChild($initg);
60+
61+
$pmtInf = $this->el('PmtInf');
62+
$ccti->appendChild($pmtInf);
63+
64+
$pmtInf->appendChild(
65+
$this->el('PmtInfId', $paymentReference ?: $this->randomService->uniqueIdWithDate('pmt'))
66+
);
67+
$pmtInf->appendChild($this->el('PmtMtd', 'TRF'));
68+
$pmtInf->appendChild($this->el('BtchBookg', $batchBooking ? 'true' : 'false'));
69+
$pmtInf->appendChild($this->el('NbOfTxs', '0'));
70+
$pmtInf->appendChild($this->el('CtrlSum', '0'));
71+
72+
$pmtTpInf = $this->el('PmtTpInf');
73+
$svcLvl = $this->el('SvcLvl');
74+
$svcLvl->appendChild($this->el('Cd', 'SEPA'));
75+
$pmtTpInf->appendChild($svcLvl);
76+
$pmtInf->appendChild($pmtTpInf);
77+
78+
$pmtInf->appendChild($this->buildReqdExctnDt($executionDate ?: $now));
79+
80+
$dbtr = $this->el('Dbtr');
81+
$dbtr->appendChild($this->el('Nm', $debitorName));
82+
$pmtInf->appendChild($dbtr);
83+
84+
$dbtrAcct = $this->el('DbtrAcct');
85+
$id = $this->el('Id');
86+
$id->appendChild($this->el('IBAN', $debitorIBAN));
87+
$dbtrAcct->appendChild($id);
88+
$pmtInf->appendChild($dbtrAcct);
89+
90+
$dbtrAgt = $this->el('DbtrAgt');
91+
$fin = $this->el('FinInstnId');
92+
$fin->appendChild($this->el('BICFI', $debitorFinInstBIC));
93+
$dbtrAgt->appendChild($fin);
94+
$pmtInf->appendChild($dbtrAgt);
95+
96+
$pmtInf->appendChild($this->el('ChrgBr', $chargeBearer ?: 'SLEV'));
97+
98+
return $this;
99+
}
100+
101+
public function addBankTransaction(
102+
string $creditorIBAN,
103+
string $creditorName,
104+
?PostalAddressInterface $postalAddress,
105+
float $amount,
106+
string $currency,
107+
?string $purposeText = null,
108+
?string $endToEndId = null,
109+
?string $purposeCode = null
110+
): self {
111+
if ($currency !== 'EUR') {
112+
throw new InvalidArgumentException('The SEPA transaction is restricted to EUR currency.');
113+
}
114+
115+
$tx = $this->createCreditTransferTransactionElement($amount, null, $endToEndId);
116+
$this->addAmountElement($tx, $amount, $currency);
117+
$this->addCreditor(
118+
$tx,
119+
null,
120+
$creditorIBAN,
121+
$creditorName,
122+
$postalAddress,
123+
$purposeText,
124+
$purposeCode
125+
);
126+
127+
return $this;
128+
}
129+
130+
public function addSEPATransaction(
131+
string $creditorFinInstBIC,
132+
string $creditorIBAN,
133+
string $creditorName,
134+
?PostalAddressInterface $postalAddress,
135+
float $amount,
136+
string $currency,
137+
?string $purposeText = null,
138+
?string $chargeBearer = null,
139+
?string $endToEndId = null,
140+
?string $purposeCode = null
141+
): self {
142+
if ($currency !== 'EUR') {
143+
throw new InvalidArgumentException('The SEPA transaction is restricted to EUR currency.');
144+
}
145+
146+
$tx = $this->createCreditTransferTransactionElement($amount, null, $endToEndId);
147+
148+
$this->addAmountElement($tx, $amount, $currency);
149+
150+
if ($chargeBearer !== null) {
151+
$tx->appendChild($this->el('ChrgBr', $chargeBearer));
152+
}
153+
154+
$this->addCreditor(
155+
$tx,
156+
$creditorFinInstBIC,
157+
$creditorIBAN,
158+
$creditorName,
159+
$postalAddress,
160+
$purposeText,
161+
$purposeCode
162+
);
163+
164+
return $this;
165+
}
166+
167+
public function addForeignTransaction(
168+
string $creditorFinInstBIC,
169+
string $creditorIBAN,
170+
string $creditorName,
171+
?PostalAddressInterface $postalAddress,
172+
float $amount,
173+
string $currency,
174+
?string $purposeText = null,
175+
?string $endToEndId = null,
176+
?string $purposeCode = null
177+
): self {
178+
$tx = $this->createCreditTransferTransactionElement($amount, null, $endToEndId);
179+
$this->addAmountElement($tx, $amount, $currency);
180+
$this->addCreditor(
181+
$tx,
182+
$creditorFinInstBIC,
183+
$creditorIBAN,
184+
$creditorName,
185+
$postalAddress,
186+
$purposeText,
187+
$purposeCode
188+
);
189+
190+
return $this;
191+
}
192+
}

src/Builders/Request/BodyBuilder.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,10 @@ public function addPreValidation(string $signatureVersion, ?string $digest = nul
5454

5555
$this->instance->appendChild($preValidation);
5656

57-
$xmlDataDigest = $this->appendEmptyElementTo('DataDigest', $preValidation, [
58-
'SignatureVersion' => $signatureVersion,
59-
]);
60-
6157
if (null !== $digest) {
62-
$xmlDataDigest->nodeValue = base64_encode($digest);
58+
$this->appendElementTo('DataDigest', base64_encode($digest), $preValidation, [
59+
'SignatureVersion' => $signatureVersion,
60+
]);
6361
}
6462

6563
return $this;

tests/AbstractEbicsTestCase.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace EbicsApi\Ebics\Tests;
44

5-
use EbicsApi\Ebics\Builders\CustomerCreditTransfer\CustomerCreditTransferBuilder;
6-
use EbicsApi\Ebics\Builders\CustomerDirectDebit\CustomerDirectDebitBuilder;
5+
use DOMException;
6+
use EbicsApi\Ebics\Builders\Document\CustomerCreditTransferBuilder;
7+
use EbicsApi\Ebics\Builders\Document\CustomerDirectDebitBuilder;
8+
use EbicsApi\Ebics\Builders\Document\CustomerUrgentCreditTransferBuilder;
79
use EbicsApi\Ebics\Contracts\EbicsClientInterface;
810
use EbicsApi\Ebics\Contracts\OrderDataInterface;
911
use EbicsApi\Ebics\Contracts\X509GeneratorInterface;
@@ -16,6 +18,7 @@
1618
use EbicsApi\Ebics\Models\Crypt\RSA;
1719
use EbicsApi\Ebics\Models\CustomerCreditTransfer;
1820
use EbicsApi\Ebics\Models\CustomerDirectDebit;
21+
use EbicsApi\Ebics\Models\DOMDocument;
1922
use EbicsApi\Ebics\Models\Keyring;
2023
use EbicsApi\Ebics\Models\StructuredPostalAddress;
2124
use EbicsApi\Ebics\Models\UnstructuredPostalAddress;
@@ -244,14 +247,13 @@ public function credentialsDataProvider(int $credentialsId): array
244247
* @param string $schema
245248
*
246249
* @return OrderDataInterface
247-
* @throws \DOMException
250+
* @throws DOMException
248251
*/
249-
protected function buildCustomerCreditTransferV2(string $schema): OrderDataInterface
252+
protected function buildCustomerCreditTransferV2(string $schema): DOMDocument
250253
{
251-
$builder = new \EbicsApi\Ebics\Builders\Document\CustomerCreditTransferBuilder($schema);
254+
$builder = new CustomerUrgentCreditTransferBuilder($schema);
252255
$customerCreditTransfer = $builder
253256
->createInstance(
254-
$schema,
255257
'ZKBKCHZZ80A',
256258
'SE7500800000000000001123',
257259
'Debitor Name'
@@ -293,7 +295,7 @@ protected function buildCustomerCreditTransferV2(string $schema): OrderDataInter
293295
* @param string $schema
294296
*
295297
* @return CustomerCreditTransfer
296-
* @throws \DOMException
298+
* @throws DOMException
297299
*/
298300
protected function buildCustomerCreditTransfer(string $schema): CustomerCreditTransfer
299301
{
@@ -342,7 +344,7 @@ protected function buildCustomerCreditTransfer(string $schema): CustomerCreditTr
342344
* @param string $schema
343345
*
344346
* @return CustomerDirectDebit
345-
* @throws \DOMException
347+
* @throws DOMException
346348
*/
347349
protected function buildCustomerDirectDebit(string $schema): CustomerDirectDebit
348350
{

0 commit comments

Comments
 (0)