Skip to content

Commit c547be7

Browse files
committed
Update EDS logic. Update Timestamp format. Added SystemID support. Added Parameter to BTF. Added HAC order type. Fix Upload orders Digest.
1 parent b12f61a commit c547be7

File tree

15 files changed

+225
-47
lines changed

15 files changed

+225
-47
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
- name: Setup PHP
3939
uses: shivammathur/setup-php@v2
4040
with:
41-
php-version: '7.4'
41+
php-version: '8.1'
4242
- name: Composer Install
4343
run: composer install --no-scripts --no-progress --ansi
4444
- name: Run phpstan
@@ -60,7 +60,7 @@ jobs:
6060
- name: Setup PHP
6161
uses: shivammathur/setup-php@v2
6262
with:
63-
php-version: '7.4'
63+
php-version: '8.1'
6464
- name: Composer Install
6565
run: composer install --no-scripts --no-progress --ansi
6666
- name: Run phpcs
@@ -82,7 +82,7 @@ jobs:
8282
- name: Setup PHP
8383
uses: shivammathur/setup-php@v2
8484
with:
85-
php-version: '7.4'
85+
php-version: '8.1'
8686
- name: Composer Install
8787
run: composer install --no-scripts --no-progress --ansi
8888
- name: Prepare data

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
* Updated custom keyring details.
44
* Dynamic Orders.
5+
* Updated EDS logic.
6+
* Updated `Timestamp` format.
7+
* Added `SystemID` support.
8+
* Added `Parameter` to BTF.
9+
* Added `HAC` order type.
10+
* Fix Upload orders Digest.
511

612
## 2.5
713

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ try {
157157
| HKD | Download customer's customer and subscriber information. |
158158
| HTD | Download subscriber's customer and subscriber information. |
159159
| HAA | Download Bank available order types. |
160-
| PTK | Download transaction status. |
160+
| PTK | Download transaction status (Plain text). |
161+
| HAC | Download transaction status (XML). |
161162
| FDL | Download the files from the bank. |
162163
| FUL | Upload the files to the bank. |
163164
| BTD | Download request files of any BTF structure. |

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
],
2222
"license": "MIT",
2323
"require": {
24-
"php": "^7.4 || ^8",
24+
"php": "^8.1",
2525
"ext-bcmath": "*",
2626
"ext-curl": "*",
2727
"ext-dom": "*",
@@ -34,13 +34,13 @@
3434
"require-dev": {
3535
"ebics-api/cfonb-php": "^1.0",
3636
"ebics-api/mt942-php": "^1.0",
37-
"phpseclib/phpseclib": "~2.0.35",
38-
"phpstan/phpstan": "~1.9.17",
39-
"phpunit/phpunit": "~9.6.3",
37+
"phpseclib/phpseclib": "~2.0.48",
38+
"phpstan/phpstan": "~1.9.18",
39+
"phpunit/phpunit": "~9.6.24",
4040
"psr/http-client": "^1.0",
4141
"psr/http-factory": "^1.0",
4242
"setasign/fpdf": "^1.8",
43-
"squizlabs/php_codesniffer": "~3.7.1"
43+
"squizlabs/php_codesniffer": "~3.7.2"
4444
},
4545
"autoload": {
4646
"psr-4": {

src/Builders/Request/DataEncryptionInfoBuilder.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,15 @@ public function addEncryptionPubKeyDigest(Keyring $keyring, string $algorithm =
5151
if (!($signatureE = $keyring->getBankSignatureE())) {
5252
throw new SignatureEbicsException('Bank Certificate E is empty.');
5353
}
54-
$certificateEDigest = $this->cryptService->calculateDigest($signatureE, $algorithm);
54+
55+
if ($signatureE->getCertificateContent()) {
56+
$certificateEDigest = $this->cryptService->calculateCertificateFingerprint(
57+
$signatureE->getCertificateContent(),
58+
$algorithm
59+
);
60+
} else {
61+
$certificateEDigest = $this->cryptService->calculatePublicKeyDigest($signatureE, $algorithm);
62+
}
5563
$encryptionPubKeyDigestNodeValue = base64_encode($certificateEDigest);
5664

5765
$this->appendElementTo('EncryptionPubKeyDigest', $encryptionPubKeyDigestNodeValue, $this->instance, [

src/Builders/Request/StaticBuilder.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ public function addRandomNonce(): StaticBuilder
5151

5252
public function addTimestamp(DateTimeInterface $dateTime): StaticBuilder
5353
{
54-
$this->appendElementTo('Timestamp', $dateTime->format('Y-m-d\TH:i:s\Z'), $this->instance);
54+
$milliseconds = (int)($dateTime->format('u') / 1000);
55+
56+
$formatted = $dateTime->format('Y-m-d\TH:i:s') . sprintf('.%03dZ', $milliseconds);
57+
58+
$this->appendElementTo('Timestamp', $formatted, $this->instance);
5559

5660
return $this;
5761
}
@@ -70,6 +74,13 @@ public function addUserId(string $userId): StaticBuilder
7074
return $this;
7175
}
7276

77+
public function addSystemId(string $systemId): StaticBuilder
78+
{
79+
$this->appendElementTo('SystemID', $systemId, $this->instance);
80+
81+
return $this;
82+
}
83+
7384
public function addProduct(string $product, string $language): StaticBuilder
7485
{
7586
$this->appendElementTo('Product', $product, $this->instance, ['Language' => $language]);

src/Contexts/BTFContext.php

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,17 @@
1010
*/
1111
abstract class BTFContext extends ServiceContext
1212
{
13-
private bool $signatureFlag = false;
14-
private bool $signatureFlagEds = false;
13+
private array $parameters = [];
1514

16-
public function setSignatureFlag(bool $signatureFlag): self
15+
public function setParameter(string $name, string $value): self
1716
{
18-
$this->signatureFlag = $signatureFlag;
17+
$this->parameters[$name] = $value;
1918

2019
return $this;
2120
}
2221

23-
public function getSignatureFlag(): bool
22+
public function getParameters(): array
2423
{
25-
return $this->signatureFlag;
26-
}
27-
28-
public function setSignatureFlagEds(bool $signatureFlagEds): self
29-
{
30-
$this->signatureFlagEds = $signatureFlagEds;
31-
32-
return $this;
33-
}
34-
35-
public function getSignatureFlagEds(): bool
36-
{
37-
return $this->signatureFlagEds;
24+
return $this->parameters;
3825
}
3926
}

src/Orders/BTD.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,5 +168,7 @@ private function addBTDOrderParams(
168168
);
169169
$xmlBTDOrderParams->appendChild($xmlDateRange);
170170
}
171+
172+
$orderDetailsBuilder->addParameters($xmlBTDOrderParams, $this->btdContext->getParameters());
171173
}
172174
}

src/Orders/BTU.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ private function buildRequest(): Request
120120
->addDataDigest(
121121
$this->context->getSignatureVersion(),
122122
$this->context->getDataDigest()
123-
)
124-
->addAdditionalOrderInfo();
123+
);
125124
});
126125
});
127126
})
@@ -164,12 +163,12 @@ private function addBTUOrderParams(OrderDetailsBuilder $orderDetailsBuilder): vo
164163
$xmlMsgName->setAttribute('format', $this->btuContext->getMsgNameFormat());
165164
}
166165

167-
if (true === $this->btuContext->getSignatureFlag()) {
166+
if ($this->context->getWithES()) {
168167
$xmlSignatureFlag = $orderDetailsBuilder->appendEmptyElementTo('SignatureFlag', $xmlBTUOrderParams);
169168

170-
if (true === $this->btuContext->getSignatureFlagEds()) {
171-
$xmlSignatureFlag->setAttribute('requestEDS', 'true');
172-
}
169+
$xmlSignatureFlag->setAttribute('requestEDS', 'true');
173170
}
171+
172+
$orderDetailsBuilder->addParameters($xmlBTUOrderParams, $this->btuContext->getParameters());
174173
}
175174
}

src/Orders/HAC.php

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
3+
namespace EbicsApi\Ebics\Orders;
4+
5+
use DateTimeInterface;
6+
use EbicsApi\Ebics\Builders\Request\HeaderBuilder;
7+
use EbicsApi\Ebics\Builders\Request\MutableBuilder;
8+
use EbicsApi\Ebics\Builders\Request\OrderDetailsBuilder;
9+
use EbicsApi\Ebics\Builders\Request\RootBuilder;
10+
use EbicsApi\Ebics\Builders\Request\StaticBuilder;
11+
use EbicsApi\Ebics\Contexts\RequestContext;
12+
use EbicsApi\Ebics\Contracts\EbicsClientInterface;
13+
use EbicsApi\Ebics\Exceptions\MethodNotImplemented;
14+
use EbicsApi\Ebics\Models\Http\Request;
15+
use EbicsApi\Ebics\Models\Keyring;
16+
use EbicsApi\Ebics\Models\Order\DownloadOrder;
17+
18+
/**
19+
* Download transaction status (XML).
20+
*
21+
* @license http://www.opensource.org/licenses/mit-license.html MIT License
22+
* @author Andrew Svirin
23+
*/
24+
final class HAC extends DownloadOrder
25+
{
26+
private ?DateTimeInterface $startDateTime;
27+
28+
private ?DateTimeInterface $endDateTime;
29+
30+
public function __construct(
31+
?DateTimeInterface $startDateTime = null,
32+
?DateTimeInterface $endDateTime = null,
33+
?RequestContext $context = null
34+
) {
35+
$this->startDateTime = $startDateTime;
36+
$this->endDateTime = $endDateTime;
37+
$this->context = $context;
38+
}
39+
40+
public function prepareContext(): void
41+
{
42+
parent::prepareContext();
43+
$this->context
44+
->setStartDateTime($this->startDateTime)
45+
->setEndDateTime($this->endDateTime);
46+
}
47+
48+
public function createRequest(): Request
49+
{
50+
return $this->buildRequest();
51+
}
52+
53+
public function getParserFormat(): string
54+
{
55+
return EbicsClientInterface::FILE_PARSER_FORMAT_TEXT;
56+
}
57+
58+
private function buildRequest(): Request
59+
{
60+
$this->context
61+
->setOrderType('HAC');
62+
63+
return $this
64+
->requestFactory->createRequestBuilderInstance()
65+
->addContainerSecured(function (RootBuilder $builder) {
66+
$builder->addHeader(function (HeaderBuilder $builder) {
67+
$builder->addStatic(function (StaticBuilder $builder) {
68+
$builder
69+
->addHostId($this->context->getBank()->getHostId())
70+
->addRandomNonce()
71+
->addTimestamp($this->context->getDateTime())
72+
->addPartnerId($this->context->getUser()->getPartnerId())
73+
->addUserId($this->context->getUser()->getUserId())
74+
->addProduct($this->context->getProduct(), $this->context->getLanguage())
75+
->addOrderDetails(function (OrderDetailsBuilder $orderDetailsBuilder) {
76+
$this->requestFactory
77+
->addOrderType(
78+
$orderDetailsBuilder,
79+
$this->context->getOrderType(),
80+
$this->context->getWithES() ?
81+
OrderDetailsBuilder::ORDER_ATTRIBUTE_OZHNN :
82+
OrderDetailsBuilder::ORDER_ATTRIBUTE_DZHNN
83+
)
84+
->addStandardOrderParams(
85+
$this->context->getStartDateTime(),
86+
$this->context->getEndDateTime()
87+
);
88+
})
89+
->addBankPubKeyDigests(
90+
$this->context->getKeyring()->getBankSignatureXVersion(),
91+
$this->requestFactory->signDigest($this->context->getKeyring()->getBankSignatureX()),
92+
$this->context->getKeyring()->getBankSignatureEVersion(),
93+
$this->requestFactory->signDigest($this->context->getKeyring()->getBankSignatureE())
94+
)
95+
->addSecurityMedium(StaticBuilder::SECURITY_MEDIUM_0000);
96+
})->addMutable(function (MutableBuilder $builder) {
97+
$builder
98+
->addTransactionPhase(MutableBuilder::PHASE_INITIALIZATION);
99+
});
100+
})->addBody();
101+
})
102+
->popInstance();
103+
}
104+
}

0 commit comments

Comments
 (0)