Skip to content

Commit 0e853a5

Browse files
committed
Update BaseAction::ensureDone() for VOP conditions
1 parent 6460aaa commit 0e853a5

File tree

3 files changed

+68
-5
lines changed

3 files changed

+68
-5
lines changed

lib/Fhp/BaseAction.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
use Fhp\Model\TanRequest;
99
use Fhp\Model\VopConfirmationRequest;
1010
use Fhp\Protocol\ActionIncompleteException;
11+
use Fhp\Protocol\ActionPendingException;
1112
use Fhp\Protocol\BPD;
1213
use Fhp\Protocol\Message;
1314
use Fhp\Protocol\TanRequiredException;
1415
use Fhp\Protocol\UnexpectedResponseException;
1516
use Fhp\Protocol\UPD;
17+
use Fhp\Protocol\VopConfirmationRequiredException;
1618
use Fhp\Segment\BaseSegment;
1719
use Fhp\Segment\HIRMS\Rueckmeldung;
1820
use Fhp\Segment\HIRMS\Rueckmeldungscode;
@@ -171,21 +173,30 @@ public function getVopConfirmationRequest(): ?VopConfirmationRequest
171173
* Throws an exception unless this action has been successfully executed, i.e. in the following cases:
172174
* - the action has not been {@link FinTs::execute()}-d at all or the {@link FinTs::execute()} call for it threw an
173175
* exception,
174-
* - the action is awaiting a TAN/confirmation (as per {@link BaseAction::needsTan()}.
176+
* - the action is awaiting a TAN/confirmation (as per {@link BaseAction::needsTan()},
177+
* - the action is pending a long-running operation on the bank server ({@link BaseAction::needsPollingWait()}),
178+
* - the action is awaiting the user's confirmation of the Verification of Payee result (as per
179+
* {@link BaseAction::needsVopConfirmation()}).
175180
*
176181
* After executing an action, you can use this function to make sure that it succeeded. This is especially useful
177182
* for actions that don't have any results (as each result getter would call {@link ensureDone()} internally).
178183
* On the other hand, you do not need to call this function if you make sure that (1) you called
179-
* {@link FinTs::execute()} and (2) you checked {@link needsTan()} and, if it returned true, supplied a TAN by
180-
* calling {@ink FinTs::submitTan()}. Note that both exception types thrown from this method are sub-classes of
181-
* {@link \RuntimeException}, so you shouldn't need a try-catch block at the call site for this.
184+
* {@link FinTs::execute()} and (2) you checked and resolved all other special outcome states documented there.
185+
* Note that both exception types thrown from this method are sub-classes of {@link \RuntimeException}, so you
186+
* shouldn't need a try-catch block at the call site for this.
182187
* @throws ActionIncompleteException If the action hasn't even been executed.
188+
* @throws ActionPendingException If the action is pending a long-running server operation that needs polling.
189+
* @throws VopConfirmationRequiredException If the action requires the user's confirmation for VOP.
183190
* @throws TanRequiredException If the action needs a TAN.
184191
*/
185-
public function ensureDone()
192+
public function ensureDone(): void
186193
{
187194
if ($this->tanRequest !== null) {
188195
throw new TanRequiredException($this->tanRequest);
196+
} elseif ($this->pollingInfo !== null) {
197+
throw new ActionPendingException($this->pollingInfo);
198+
} elseif ($this->vopConfirmationRequest !== null) {
199+
throw new VopConfirmationRequiredException($this->vopConfirmationRequest);
189200
} elseif (!$this->isDone()) {
190201
throw new ActionIncompleteException();
191202
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/** @noinspection PhpUnused */
3+
4+
namespace Fhp\Protocol;
5+
6+
use Fhp\Model\PollingInfo;
7+
8+
/**
9+
* Thrown when an action result is read, but the action is still pending a long-running operation on the server and
10+
* requires polling to find out when it's completed.
11+
*/
12+
class ActionPendingException extends \RuntimeException
13+
{
14+
private PollingInfo $pollingInfo;
15+
16+
public function __construct(PollingInfo $pollingInfo)
17+
{
18+
parent::__construct('This action needs polling to await finishing a server-side operation.');
19+
$this->pollingInfo = $pollingInfo;
20+
}
21+
22+
public function getPollingInfo(): PollingInfo
23+
{
24+
return $this->pollingInfo;
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/** @noinspection PhpUnused */
3+
4+
namespace Fhp\Protocol;
5+
6+
use Fhp\Model\VopConfirmationRequest;
7+
8+
/**
9+
* Thrown when an action result is read, but the action is still pending the user's confirmation of the Verification of
10+
* Payee result.
11+
*/
12+
class VopConfirmationRequiredException extends \RuntimeException
13+
{
14+
private VopConfirmationRequest $vopConfirmationRequest;
15+
16+
public function __construct(VopConfirmationRequest $vopConfirmationRequest)
17+
{
18+
parent::__construct('This action needs VOP confirmation before it will be executed.');
19+
$this->vopConfirmationRequest = $vopConfirmationRequest;
20+
}
21+
22+
public function getVopConfirmationRequest(): VopConfirmationRequest
23+
{
24+
return $this->vopConfirmationRequest;
25+
}
26+
}

0 commit comments

Comments
 (0)