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
|
|
|
declare(strict_types=1); |
10
|
|
|
|
11
|
|
|
namespace Moip\Magento2\Model\Console\Command\Preference; |
12
|
|
|
|
13
|
|
|
use Exception; |
14
|
|
|
use Magento\Framework\App\Config\ScopeConfigInterface; |
|
|
|
|
15
|
|
|
use Magento\Framework\App\State; |
|
|
|
|
16
|
|
|
use Magento\Framework\HTTP\ZendClient; |
|
|
|
|
17
|
|
|
use Magento\Framework\HTTP\ZendClientFactory; |
|
|
|
|
18
|
|
|
use Magento\Framework\Serialize\Serializer\Json; |
|
|
|
|
19
|
|
|
use Moip\Magento2\Gateway\Config\Config as MoipConfig; |
20
|
|
|
use Moip\Magento2\Model\Console\Command\AbstractModel; |
21
|
|
|
use Psr\Log\LoggerInterface; |
|
|
|
|
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class All Preference Webhook. |
25
|
|
|
*/ |
26
|
|
|
class All extends AbstractModel |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* State. |
30
|
|
|
* |
31
|
|
|
* @var \Magento\Framework\App\State |
32
|
|
|
*/ |
33
|
|
|
private $state; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* ScopeConfigInterface. |
37
|
|
|
* |
38
|
|
|
* @var \Magento\Framework\App\Config\ScopeConfigInterface |
39
|
|
|
*/ |
40
|
|
|
protected $scopeConfig; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* moipConfig. |
44
|
|
|
* |
45
|
|
|
* @var Moip\Magento2\Gateway\Config\Config |
|
|
|
|
46
|
|
|
*/ |
47
|
|
|
private $moipConfig; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* ZendClientFactory. |
51
|
|
|
* |
52
|
|
|
* @var \Magento\Framework\HTTP\ZendClientFactory |
53
|
|
|
*/ |
54
|
|
|
private $httpClientFactory; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Json. |
58
|
|
|
* |
59
|
|
|
* @var \Magento\Framework\Serialize\Serializer\Json |
60
|
|
|
*/ |
61
|
|
|
private $json; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* All constructor. |
65
|
|
|
* |
66
|
|
|
* @param LoggerInterface $logger |
67
|
|
|
* @param ScopeConfigInterface $scopeConfig |
68
|
|
|
* @param State $state |
69
|
|
|
* @param MoipConfig $moipConfig |
70
|
|
|
* @param Json $json |
71
|
|
|
* @param ZendClientFactory $httpClientFactory |
72
|
|
|
*/ |
73
|
|
|
public function __construct( |
74
|
|
|
LoggerInterface $logger, |
75
|
|
|
ScopeConfigInterface $scopeConfig, |
76
|
|
|
State $state, |
77
|
|
|
MoipConfig $moipConfig, |
78
|
|
|
Json $json, |
79
|
|
|
ZendClientFactory $httpClientFactory |
80
|
|
|
) { |
81
|
|
|
parent::__construct( |
82
|
|
|
$logger |
83
|
|
|
); |
84
|
|
|
$this->state = $state; |
85
|
|
|
$this->scopeConfig = $scopeConfig; |
86
|
|
|
$this->moipConfig = $moipConfig; |
87
|
|
|
$this->json = $json; |
88
|
|
|
$this->httpClientFactory = $httpClientFactory; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* {@inheritdoc} |
93
|
|
|
*/ |
94
|
|
|
public function all() |
95
|
|
|
{ |
96
|
|
|
$this->writeln('List All Preference'); |
97
|
|
|
$preference = $this->getPreferenceWebhooks(); |
98
|
|
|
if (!$preference) { |
99
|
|
|
$this->writeln(__('<error>Error %1</error>', $preference['error'])); |
|
|
|
|
100
|
|
|
|
101
|
|
|
return $this; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
foreach ($preference['preference'] as $webhooks) { |
105
|
|
|
if (isset($webhooks['id'])) { |
106
|
|
|
$this->writeln(__('<info>Preference ID: %1 Target Uri: %2</info>', $webhooks['id'], $webhooks['target'])); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
$this->writeln(__('Finished')); |
110
|
|
|
|
111
|
|
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/* |
115
|
|
|
* List All Preference Webhooks |
116
|
|
|
* |
117
|
|
|
* @return array |
118
|
|
|
*/ |
119
|
|
|
private function getPreferenceWebhooks(): array |
120
|
|
|
{ |
121
|
|
|
$uri = $this->moipConfig->getApiUrl(); |
122
|
|
|
$apiBearer = $this->moipConfig->getMerchantGatewayOauth(); |
123
|
|
|
$client = $this->httpClientFactory->create(); |
124
|
|
|
|
125
|
|
|
$client->setUri($uri.'preferences/notifications'); |
126
|
|
|
$client->setConfig(['maxredirects' => 0, 'timeout' => 30]); |
127
|
|
|
$client->setHeaders('Authorization', 'Bearer '.$apiBearer); |
128
|
|
|
$client->setMethod(ZendClient::GET); |
129
|
|
|
|
130
|
|
|
try { |
131
|
|
|
$result = $client->request()->getBody(); |
132
|
|
|
|
133
|
|
|
return [ |
134
|
|
|
'success' => true, |
135
|
|
|
'preference' => $this->json->unserialize($result), |
136
|
|
|
]; |
137
|
|
|
} catch (Exception $e) { |
138
|
|
|
return ['success' => true, 'error' => $e->getMessage()]; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
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