Skip to content

Commit 4b52bce

Browse files
committed
Factor out a FinTs::processServerResponse() helper
Currently it has only one call site -- calling it from submitTan or checkDecoupledSubmission doesn't seem to work out of the box, because it falsely believes that a TAN request is needed (again). But maybe the TAN request recognition can be fixed in the future so that it can also be used for those. That said, it's not an issue as long as the TAN request is always the last thing that happens (strictly after VoP polling and confirmation). This will be used by the future VoP functions in FinTs.
1 parent 1e80407 commit 4b52bce

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

lib/Fhp/FinTs.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,28 +310,45 @@ public function execute(BaseAction $action): void
310310
throw new \RuntimeException('Need to login (DialogInitialization) before executing other actions');
311311
}
312312

313+
// Add the action's main request segments.
313314
$requestSegments = $action->getNextRequest($this->bpd, $this->upd);
314-
315315
if (count($requestSegments) === 0) {
316316
return; // No request needed.
317317
}
318+
$message = MessageBuilder::create()->add($requestSegments);
318319

319-
// Construct the full request message.
320-
$message = MessageBuilder::create()->add($requestSegments); // This fills in the segment numbers.
320+
// Add HKTAN for authentication if necessary.
321321
if (!($this->getSelectedTanMode() instanceof NoPsd2TanMode)) {
322322
if (($needTanForSegment = $action->getNeedTanForSegment()) !== null) {
323323
$message->add(HKTANFactory::createProzessvariante2Step1(
324324
$this->requireTanMode(), $this->selectedTanMedium, $needTanForSegment));
325325
}
326326
}
327-
$request = $this->buildMessage($message, $this->getSelectedTanMode());
327+
328+
// Construct the request and tell the action about the segment numbers that were assigned.
329+
$request = $this->buildMessage($message, $this->getSelectedTanMode()); // This fills in the segment numbers.
328330
$action->setRequestSegmentNumbers(array_map(function ($segment) {
329331
/* @var BaseSegment $segment */
330332
return $segment->getSegmentNumber();
331333
}, $requestSegments));
332334

333335
// Execute the request.
334336
$response = $this->sendMessage($request);
337+
$this->processServerResponse($action, $response);
338+
}
339+
340+
/**
341+
* Updates the state of this FinTs instance and of the `$action` based on the server's response.
342+
* See {@link execute()} for more documentation on the possible outcomes.
343+
* @param BaseAction $action The action for which the request was sent.
344+
* @param Message $response The response we just got from the server.
345+
* @throws CurlException When the connection fails in a layer below the FinTS protocol.
346+
* @throws UnexpectedResponseException When the server responds with a valid but unexpected message.
347+
* @throws ServerException When the server responds with a (FinTS-encoded) error message, which includes most things
348+
* that can go wrong with the action itself, like wrong credentials, invalid IBANs, locked accounts, etc.
349+
*/
350+
private function processServerResponse(BaseAction $action, Message $response): void
351+
{
335352
$this->readBPD($response);
336353

337354
// Detect if the bank wants a TAN.

0 commit comments

Comments
 (0)