1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2019. Volodymyr Hryvinskyi. All rights reserved. |
4
|
|
|
* @author: <mailto:[email protected]> |
5
|
|
|
* @github: <https://github.com/hryvinskyi> |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
declare(strict_types=1); |
9
|
|
|
|
10
|
|
|
namespace Hryvinskyi\InvisibleCaptcha\Model\Provider\Failure; |
11
|
|
|
|
12
|
|
|
use Hryvinskyi\InvisibleCaptcha\Helper\Config\General; |
13
|
|
|
use Hryvinskyi\InvisibleCaptcha\Model\Provider\AbstractFailure; |
14
|
|
|
use Hryvinskyi\InvisibleCaptcha\Model\Provider\FailureInterface; |
15
|
|
|
use Hryvinskyi\InvisibleCaptcha\Model\Provider\FailureMessages; |
16
|
|
|
use Hryvinskyi\InvisibleCaptcha\Model\ReCaptcha\Response; |
17
|
|
|
use Magento\Framework\App\Action\Action; |
18
|
|
|
use Magento\Framework\App\ActionFlag; |
19
|
|
|
use Magento\Framework\App\ResponseInterface; |
20
|
|
|
use Magento\Framework\Json\EncoderInterface; |
21
|
|
|
|
22
|
|
|
class AjaxResponseFailure extends AbstractFailure |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var ActionFlag |
26
|
|
|
*/ |
27
|
|
|
private $actionFlag; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var EncoderInterface |
31
|
|
|
*/ |
32
|
|
|
private $encoder; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var General |
36
|
|
|
*/ |
37
|
|
|
private $config; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* AjaxResponseFailure constructor. |
41
|
|
|
* |
42
|
|
|
* @param ActionFlag $actionFlag |
43
|
|
|
* @param EncoderInterface $encoder |
44
|
|
|
* @param General $config |
45
|
|
|
* @param FailureMessages $failureMessages |
46
|
|
|
*/ |
47
|
|
|
public function __construct( |
48
|
|
|
ActionFlag $actionFlag, |
49
|
|
|
EncoderInterface $encoder, |
50
|
|
|
General $config, |
51
|
|
|
FailureMessages $failureMessages |
52
|
|
|
) { |
53
|
|
|
$this->actionFlag = $actionFlag; |
54
|
|
|
$this->encoder = $encoder; |
55
|
|
|
$this->config = $config; |
56
|
|
|
|
57
|
|
|
parent::__construct($failureMessages); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Handle captcha failure |
62
|
|
|
* |
63
|
|
|
* @param Response $verifyReCaptcha |
64
|
|
|
* @param ResponseInterface|null $response |
65
|
|
|
* |
66
|
|
|
* @return void |
67
|
|
|
*/ |
68
|
|
|
public function execute(Response $verifyReCaptcha, ResponseInterface $response = null) |
69
|
|
|
{ |
70
|
|
|
$this->actionFlag->set('', Action::FLAG_NO_DISPATCH, true); |
|
|
|
|
71
|
|
|
|
72
|
|
|
$jsonPayload = $this->encoder->encode([ |
73
|
|
|
'errors' => true, |
74
|
|
|
'messages' => $this->getMessagesString($verifyReCaptcha), |
75
|
|
|
]); |
76
|
|
|
|
77
|
|
|
$response->representJson($jsonPayload); |
|
|
|
|
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|