Commit 519c5a62 authored by Vincent Mrose's avatar Vincent Mrose 💬
Browse files

Merge branch 'hotfix/issue-10' into 'master'

Fixes #10 - Magento errors no longer trigger reloads via this module

Closes #10

See merge request !8
parents d7fc7c95 07361e75
......@@ -91,6 +91,16 @@ class Reserve implements CommandInterface
* @param array $commandSubject
*
* @return void
* @throws CommandException
* @throws \Upg\Library\Api\Exception\CurlError
* @throws \Upg\Library\Api\Exception\InvalidHttpResponseCode
* @throws \Upg\Library\Api\Exception\InvalidUrl
* @throws \Upg\Library\Api\Exception\JsonDecode
* @throws \Upg\Library\Api\Exception\MacValidation
* @throws \Upg\Library\Api\Exception\RequestNotSet
* @throws \Upg\Library\Api\Exception\Validation
* @throws \Upg\Library\Mac\Exception\MacInvalid
* @throws \Upg\Library\Serializer\Exception\VisitorCouldNotBeFound
*/
public function execute(array $commandSubject)
{
......@@ -102,27 +112,28 @@ class Reserve implements CommandInterface
);
$response = $this->transport->sendRequest($request);
} catch (\Exception $e) {
$this->processErrors($commandSubject, $e);
}
// move to handler
$this->transactionService->addTransaction($paymentDO, $request, $response);
// move to handler
$this->transactionService->addTransaction($paymentDO, $request, $response);
if ($this->handler) {
$this->handler->handle(
$commandSubject,
[]
);
if ($this->handler) {
$this->handler->handle(
$commandSubject,
[]
);
}
} catch (ApiError $e) {
$this->handleApiException($commandSubject, $e);
}
}
/**
* @param array $commandSubject
* @param \Exception $e
* @param array $commandSubject
* @param ApiError $e
*
* @throws CommandException
*/
private function processErrors(array $commandSubject, \Exception $e)
private function handleApiException(array $commandSubject, ApiError $e)
{
$exception = new CommandException(
!empty($e->getMessage())
......@@ -130,7 +141,7 @@ class Reserve implements CommandInterface
: __('Transaction has been declined. Please try again later.')
);
if ($e instanceof ApiError && ($this->validator !== null)) {
if ($this->validator !== null) {
$result = $this->validator->validate(
array_merge($commandSubject, ['response' => $e->getParsedResponse()])
);
......
......@@ -308,7 +308,7 @@ class ReserveTest extends \PHPUnit\Framework\TestCase
$this->transportMock->expects($this->once())
->method('sendRequest')
->with($this->reserveRequestMock)
->will($this->throwException(new \Exception()));
->willThrowException(new \Exception());
$this->validatorMock->expects($this->never())
->method('validate');
......@@ -316,8 +316,7 @@ class ReserveTest extends \PHPUnit\Framework\TestCase
$this->transactionServiceMock->expects($this->never())
->method('addTransaction');
$this->expectException(CommandException::class);
$this->expectExceptionMessage('Transaction has been declined. Please try again later.');
$this->expectException(\Exception::class);
$reserveCommand->execute($commandSubject);
}
......
......@@ -10,19 +10,22 @@ define([
return function (targetModule) {
var func = targetModule.process;
var processWrapper = wrapper.wrap(func, function (original, response, messageContainer) {
var isCrefopayError = response.responseJSON.message === 'crefopay_reserve_error';
if (JSON.parse(response.responseText).message === 'crefopay_reserve_error') {
if (isCrefopayError) {
response.responseText = JSON.stringify(
{
"message": $.mage.__('Transaction has been declined. Please try again later.'),
"trace": JSON.parse(response.responseText).trace
"trace": response.responseJSON.trace
}
);
}
original(response, messageContainer);
window.location.reload();
if (isCrefopayError) {
window.location.reload();
}
});
targetModule.process = processWrapper;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment