Skip to content

Commit 166fb7e

Browse files
committed
feat: Handle unexpected driver exceptions which occur during the SCA proicess
1 parent e95a8da commit 166fb7e

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

src/Factory/ScaRequest.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
use Nails\Common\Exception\ModelException;
1717
use Nails\Factory;
1818
use Nails\Invoice\Constants;
19-
use Nails\Invoice\Exception\ChargeRequestException;
2019
use Nails\Invoice\Exception\RequestException;
2120
use Nails\Invoice\Exception\ScaRequestException;
21+
use Throwable;
2222

2323
/**
2424
* Class ScaRequest
@@ -52,11 +52,28 @@ public function execute(): ScaResponse
5252
);
5353

5454
} else {
55-
$oScaResponse = $this->oDriver->sca(
56-
$oScaResponse,
57-
$this->oPayment->sca_data,
58-
$oChargeRequest::compileScaUrl($this->oPayment, $this->oPayment->sca_data)
59-
);
55+
try {
56+
$oScaResponse = $this->oDriver->sca(
57+
$oScaResponse,
58+
$this->oPayment->sca_data,
59+
$oChargeRequest::compileScaUrl($this->oPayment, $this->oPayment->sca_data)
60+
);
61+
} catch (Throwable $e) {
62+
/**
63+
* Something unexpected happened within the driver, we do not want this error reaching
64+
* the user. Ensure that we gracefully handle the exception so the user sees something
65+
* which isn't a 500. Log the real exception for debugging purposes.
66+
*/
67+
$oScaResponse->setStatusFailed(
68+
$oScaResponse->getErrorMessage(),
69+
$oScaResponse->getErrorCode(),
70+
'Failed to authorise the payment.'
71+
);
72+
$this->setPaymentFailed(
73+
$oScaResponse->getErrorMessage(),
74+
$oScaResponse->getErrorCode()
75+
);
76+
}
6077
}
6178

6279
$oScaResponse->lock();

0 commit comments

Comments
 (0)