Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
crefopay
Magento 2
Commits
07361e75
Commit
07361e75
authored
Oct 30, 2019
by
Vincent Mrose
💬
Browse files
Fixes
#10
- Magento errors no longer trigger reloads via this module
Signed-off-by:
Vincent Mrose
<
v.mrose@crefopay.de
>
parent
d7fc7c95
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/code/Trilix/CrefoPay/Gateway/Command/Reserve.php
View file @
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
()])
);
...
...
app/code/Trilix/CrefoPay/Test/Unit/Gateway/Command/ReserveTest.php
View file @
07361e75
...
...
@@ -308,7 +308,7 @@ class ReserveTest extends \PHPUnit\Framework\TestCase
$this
->
transportMock
->
expects
(
$this
->
once
())
->
method
(
'sendRequest'
)
->
with
(
$this
->
reserveRequestMock
)
->
will
(
$this
->
t
hrowException
(
new
\
Exception
())
)
;
->
will
T
hrowException
(
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
);
}
...
...
app/code/Trilix/CrefoPay/view/frontend/web/js/model/error-processor.js
View file @
07361e75
...
...
@@ -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_e
rror
'
)
{
if
(
isCrefopayE
rror
)
{
response
.
responseText
=
JSON
.
stringify
(
{
"
message
"
:
$
.
mage
.
__
(
'
Transaction has been declined. Please try again later.
'
),
"
trace
"
:
JSON
.
parse
(
response
.
response
Text
)
.
trace
"
trace
"
:
response
.
response
JSON
.
trace
}
);
}
original
(
response
,
messageContainer
);
window
.
location
.
reload
();
if
(
isCrefopayError
)
{
window
.
location
.
reload
();
}
});
targetModule
.
process
=
processWrapper
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment