1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright © Wirecard Brasil. All rights reserved. |
4
|
|
|
* |
5
|
|
|
* @author Bruno Elisei <[email protected]> |
6
|
|
|
* See COPYING.txt for license details. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Moip\Magento2\Block\Adminhtml\System\Config; |
10
|
|
|
|
11
|
|
|
use Magento\Backend\Block\Template\Context; |
|
|
|
|
12
|
|
|
use Magento\Config\Block\System\Config\Form\Field; |
|
|
|
|
13
|
|
|
use Magento\Framework\Data\Form\Element\AbstractElement; |
|
|
|
|
14
|
|
|
use Moip\Magento2\Gateway\Config\Config; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class Oauth - Defines oAuth session actions. |
18
|
|
|
*/ |
19
|
|
|
class Oauth extends Field |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var template |
|
|
|
|
23
|
|
|
*/ |
24
|
|
|
protected $_template = 'Moip_Magento2::system/config/oauth.phtml'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var config |
28
|
|
|
*/ |
29
|
|
|
protected $config; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param Config |
33
|
|
|
* @param Context |
34
|
|
|
*/ |
35
|
|
|
public function __construct( |
36
|
|
|
Config $config, |
37
|
|
|
Context $context |
38
|
|
|
) { |
39
|
|
|
$this->config = $config; |
40
|
|
|
parent::__construct($context); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/* |
44
|
|
|
* Render |
45
|
|
|
* |
46
|
|
|
* @param $element |
47
|
|
|
* |
48
|
|
|
* @return string |
49
|
|
|
*/ |
50
|
|
|
public function render(AbstractElement $element) |
51
|
|
|
{ |
52
|
|
|
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue(); |
53
|
|
|
|
54
|
|
|
return parent::render($element); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/* |
58
|
|
|
* Elment Html |
59
|
|
|
* |
60
|
|
|
* @param $element |
61
|
|
|
* |
62
|
|
|
* @return string |
63
|
|
|
*/ |
64
|
|
|
protected function _getElementHtml(AbstractElement $element) |
65
|
|
|
{ |
66
|
|
|
return $this->_toHtml(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/* |
70
|
|
|
* Ajax Url |
71
|
|
|
* |
72
|
|
|
* @return url |
|
|
|
|
73
|
|
|
*/ |
74
|
|
|
public function getAjaxUrl() |
75
|
|
|
{ |
76
|
|
|
return $this->getUrl('moip/system_config/logout'); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/* |
80
|
|
|
* Url Authorize |
81
|
|
|
* |
82
|
|
|
* @return url |
83
|
|
|
*/ |
84
|
|
|
public function getUrlAuthorize() |
85
|
|
|
{ |
86
|
|
|
$baseUri = Config::OAUTH_URI; |
87
|
|
|
$storeUri = $this->getUrl('moip/system_config/oauth'); |
88
|
|
|
|
89
|
|
|
return $baseUri.'?client_id='.$storeUri; |
|
|
|
|
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/* |
93
|
|
|
* Button Html |
94
|
|
|
* |
95
|
|
|
* @return string |
96
|
|
|
*/ |
97
|
|
|
public function getButtonHtml() |
98
|
|
|
{ |
99
|
|
|
$button = $this->getLayout()->createBlock( |
100
|
|
|
\Magento\Backend\Block\Widget\Button::class |
|
|
|
|
101
|
|
|
)->setData( |
102
|
|
|
[ |
103
|
|
|
'id' => 'oauth', |
104
|
|
|
'label' => __($this->getInfoTextBtn()), |
|
|
|
|
105
|
|
|
] |
106
|
|
|
); |
107
|
|
|
|
108
|
|
|
return $button->toHtml(); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/* |
112
|
|
|
* Info Text Button |
113
|
|
|
* |
114
|
|
|
* @return string |
115
|
|
|
*/ |
116
|
|
|
public function getInfoTextBtn() |
117
|
|
|
{ |
118
|
|
|
$environment = $this->config->getEnvironmentMode(); |
119
|
|
|
$oauth = $this->config->getMerchantGatewayOauth(); |
120
|
|
|
$label = __('Production'); |
|
|
|
|
121
|
|
|
|
122
|
|
|
if ($environment === Config::ENVIRONMENT_SANDBOX) { |
123
|
|
|
$label = __('Environment for tests'); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
$text = sprintf(__('Authorize in %s'), $label); |
127
|
|
|
|
128
|
|
|
if ($oauth) { |
129
|
|
|
$text = sprintf(__('Disallow in %s'), $label); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
return $text; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/* |
136
|
|
|
* Type Js |
137
|
|
|
* |
138
|
|
|
* @return string |
139
|
|
|
*/ |
140
|
|
|
public function getTypeJs() |
141
|
|
|
{ |
142
|
|
|
if ($this->config->getMerchantGatewayOauth()) { |
143
|
|
|
return 'clear'; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
return 'getautorization'; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/* |
150
|
|
|
* Url to connect |
151
|
|
|
* |
152
|
|
|
* @return string |
153
|
|
|
*/ |
154
|
|
|
public function getUrlToConnect() |
155
|
|
|
{ |
156
|
|
|
$redirectUri = $this->getUrlAuthorize(); |
157
|
|
|
$endpointOauth = Config::ENDPOINT_OAUTH_PRODUCTION; |
158
|
|
|
$appId = Config::APP_ID_PRODUCTION; |
159
|
|
|
$scope = Config::OAUTH_SCOPE; |
160
|
|
|
$responseType = 'code'; |
161
|
|
|
|
162
|
|
|
if ($this->config->getEnvironmentMode() === Config::ENVIRONMENT_SANDBOX) { |
163
|
|
|
$endpointOauth = Config::ENDPOINT_OAUTH_SANDBOX; |
164
|
|
|
$appId = Config::APP_ID_SANDBOX; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
$link = $endpointOauth; |
168
|
|
|
$link .= '?response_type='.$responseType; |
169
|
|
|
$link .= '&client_id='.$appId; |
170
|
|
|
$link .= '&redirect_uri='.$redirectUri; |
171
|
|
|
$link .= '&scope='.$scope; |
172
|
|
|
|
173
|
|
|
return $link; |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths