Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/Handlers/ResponseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ public function retrieveH000ReportText(DOMDocument $xml): string
public function extractInitializationSegment(Response $response, Keyring $keyring): InitializationSegment
{
$transactionKeyEncoded = $this->retrieveH00XTransactionKey($response);

if (null === $transactionKeyEncoded) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Transaction key for some requests is not present, but for these requests extractInitializationSegment() should not be applied. This is more wrong usage exception here. I would say, that transactionKeyEncoded is required in this place and can be thrown appropriate exception if no transactionKeyEncoded.

throw new \RuntimeException('EBICS initialization segment is missing TransactionKey. Response may be truncated.');
}

$transactionKey = $this->base64Service->decode($transactionKeyEncoded);
$orderDataEncrypted = $this->base64Service->decode($this->retrieveH00XOrderData($response));

Expand All @@ -148,7 +153,10 @@ public function extractDownloadSegment(Response $response): DownloadSegment
$transactionId = $this->retrieveH00XTransactionId($response);
$transactionPhase = $this->retrieveH00XTransactionPhase($response);
$transactionKeyEncoded = $this->retrieveH00XTransactionKey($response);
$transactionKey = $this->base64Service->decode($transactionKeyEncoded);

$transactionKey = null !== $transactionKeyEncoded
? $this->base64Service->decode($transactionKeyEncoded)
: null;
$numSegments = $this->retrieveH00XNumSegments($response);
$segmentNumber = $this->retrieveH00XSegmentNumber($response);
$orderDataEncrypted = $this->retrieveH00XOrderData($response);
Expand Down
6 changes: 3 additions & 3 deletions src/Models/DownloadSegment.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class DownloadSegment extends Segment
{
private string $transactionId;
private ?string $transactionPhase;
private string $transactionKey;
private ?string $transactionKey;
private ?int $segmentNumber;
private ?int $numSegments;
private string $orderData;
Expand All @@ -37,12 +37,12 @@ public function setTransactionPhase(?string $phase): void
$this->transactionPhase = $phase;
}

public function getTransactionKey(): string
public function getTransactionKey(): ?string
{
return $this->transactionKey;
}

public function setTransactionKey(string $transactionKey): void
public function setTransactionKey(?string $transactionKey): void

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure that it should be possible have not transactionKey for DownloadSegment.

{
$this->transactionKey = $transactionKey;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Models/Segment.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
*/
abstract class Segment
{
private string $transactionKey;
private ?string $transactionKey;
private Response $response;

public function getTransactionKey(): string
public function getTransactionKey(): ?string
{
return $this->transactionKey;
}

public function setTransactionKey(string $transactionKey): void
public function setTransactionKey(?string $transactionKey): void

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not happen

{
$this->transactionKey = $transactionKey;
}
Expand Down
6 changes: 5 additions & 1 deletion src/Services/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ protected function createResponse(string $contents): Response
}

$response = new Response();
$response->loadXML($contents);
$loaded = @$response->loadXML($contents);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. But I really do not like supression for functions. I think better try, catch or something like error handler. So see real message in line 53.


if (false === $loaded) {
throw new RuntimeException('Failed to parse EBICS XML response. Response may be truncated or malformed.');
}

return $response;
}
Expand Down
Loading