Issues (104)

Model/Config.php (6 issues)

Labels
Severity
1
<?php
2
/**
3
 * Copyright © Getnet. All rights reserved.
4
 *
5
 * @author    Bruno Elisei <[email protected]>
6
 * See LICENSE for license details.
7
 */
8
9
/**
10
 * Configuration paths storage.
11
 */
12
13
namespace Getnet\SubSellerMagento\Model;
14
15
use Magento\Framework\Serialize\Serializer\Json;
16
use Magento\Store\Model\Store;
17
18
//phpcs:disable Generic.Files.LineLength
19
20
/**
21
 * Class to set flags for sub seller display setting.
22
 *
23
 * @SuppressWarnings(PHPCS.Generic.Files.LineLength)
24
 */
25
class Config
26
{
27
    /**
28
     * Uri Production.
29
     */
30
    public const URI_PRODUCTION = 'https://api.getnet.com.br/';
31
32
    /**
33
     * Uri Homolog.
34
     */
35
    public const URI_HOMOLOG = 'https://api-homologacao.getnet.com.br/';
36
37
    /**
38
     * Uri Sandbox.
39
     */
40
    public const URI_SANDBOX = 'https://api-sandbox.getnet.com.br/';
41
42
    /**
43
     * Environment.
44
     */
45
    public const XML_PATH_GETNET_ENVIRONMENT = 'getnet_sub_seller/general/credentials/environment';
46
47
    /**
48
     * Merchant Id Production.
49
     */
50
    public const XML_PATH_GETNET_MERCHANT_ID_PRODUCTION = 'getnet_sub_seller/general/credentials/merchant_id_production';
51
52
    /**
53
     * Merchant Id Homolog.
54
     */
55
    public const XML_PATH_GETNET_MERCHANT_ID_HOMOLOG = 'getnet_sub_seller/general/credentials/merchant_id_homolog';
56
57
    /**
58
     * Merchant Id Sandbox.
59
     */
60
    public const XML_PATH_GETNET_MERCHANT_ID_SANDBOX = 'getnet_sub_seller/general/credentials/merchant_id_sandbox';
61
62
    /**
63
     * Client Id Production.
64
     */
65
    public const XML_PATH_GETNET_CLIENT_ID_PRODUCTION = 'getnet_sub_seller/general/credentials/client_id_production';
66
67
    /**
68
     * Client Id Homolog.
69
     */
70
    public const XML_PATH_GETNET_CLIENT_ID_HOMOLOG = 'getnet_sub_seller/general/credentials/client_id_homolog';
71
72
    /**
73
     * Client Id Sandbox.
74
     */
75
    public const XML_PATH_GETNET_CLIENT_ID_SANDBOX = 'getnet_sub_seller/general/credentials/client_id_sandbox';
76
77
    /**
78
     * Client Secret Production.
79
     */
80
    public const XML_PATH_GETNET_CLIENT_SECRET_PRODUCTION = 'getnet_sub_seller/general/credentials/client_secret_production';
81
82
    /**
83
     * Client Secret Homolog.
84
     */
85
    public const XML_PATH_GETNET_CLIENT_SECRET_HOMOLOG = 'getnet_sub_seller/general/credentials/client_secret_homolog';
86
87
    /**
88
     * Client Secret Sandbox.
89
     */
90
    public const XML_PATH_GETNET_CLIENT_SECRET_SANDBOX = 'getnet_sub_seller/general/credentials/client_secret_sandbox';
91
92
    /**
93
     * Auth Id Production.
94
     */
95
    public const XML_PATH_GETNET_AUTH_PRODUCTION = 'getnet_sub_seller/general/credentials/access_token_production';
96
97
    /**
98
     * Auth Id Homolog.
99
     */
100
    public const XML_PATH_GETNET_AUTH_HOMOLOG = 'getnet_sub_seller/general/credentials/access_token_homolog';
101
102
    /**
103
     * Auth Id Sandbox.
104
     */
105
    public const XML_PATH_GETNET_AUTH_SANDBOX = 'getnet_sub_seller/general/credentials/access_token_sandbox';
106
107
    /**
108
     * List Commissions.
109
     */
110
    public const XML_PATH_GETNET_LIST_COMMISSIONS = 'getnet_sub_seller/general/list_commisions/commisions';
111
112
    /**
113
     * Core store config.
114
     *
115
     * @var \Magento\Framework\App\Config\ScopeConfigInterface
116
     */
117
    protected $_scopeConfig;
118
119
    /**
120
     * Core Json.
121
     *
122
     * @var Json
123
     */
124
    protected $json;
125
126
    /**
127
     * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
128
     * @param Json                                               $json
129
     */
130
    public function __construct(
131
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
132
        Json $json
133
    ) {
134
        $this->json = $json;
135
        $this->_scopeConfig = $scopeConfig;
136
    }
137
138
    /**
139
     * Get Environment.
140
     *
141
     * @param null|string|bool|int|Store $store
142
     *
143
     * @return string
144
     */
145
    public function getEnvironment($store = null)
146
    {
147
        return $this->_scopeConfig->getValue(
148
            self::XML_PATH_GETNET_ENVIRONMENT,
149
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
150
            $store
0 ignored issues
show
It seems like $store can also be of type Magento\Store\Model\Store; however, parameter $scopeCode of Magento\Framework\App\Co...igInterface::getValue() does only seem to accept integer|null|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

150
            /** @scrutinizer ignore-type */ $store
Loading history...
151
        );
152
    }
153
154
    /**
155
     * Get Uri.
156
     *
157
     * @param null|string|bool|int|Store $store
158
     *
159
     * @return string
160
     */
161
    public function getUri($store = null)
162
    {
163
        if ($this->getEnvironment($store) === 'sandbox') {
164
            return self::URI_SANDBOX;
165
        }
166
167
        if ($this->getEnvironment($store) === 'homolog') {
168
            return self::URI_HOMOLOG;
169
        }
170
171
        return self::URI_PRODUCTION;
172
    }
173
174
    /**
175
     * Get Merchant Gateway Client Id.
176
     *
177
     * @param null|string|bool|int|Store $store
178
     *
179
     * @return string
180
     */
181
    public function getMerchantGatewayClientId($store = null)
182
    {
183
        if ($this->getEnvironment($store) === 'sandbox') {
184
            return $this->_scopeConfig->getValue(
185
                self::XML_PATH_GETNET_CLIENT_ID_SANDBOX,
186
                \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
187
                $store
0 ignored issues
show
It seems like $store can also be of type Magento\Store\Model\Store; however, parameter $scopeCode of Magento\Framework\App\Co...igInterface::getValue() does only seem to accept integer|null|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

187
                /** @scrutinizer ignore-type */ $store
Loading history...
188
            );
189
        }
190
191
        if ($this->getEnvironment($store) === 'homolog') {
192
            return $this->_scopeConfig->getValue(
193
                self::XML_PATH_GETNET_CLIENT_ID_HOMOLOG,
194
                \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
195
                $store
196
            );
197
        }
198
199
        return $this->_scopeConfig->getValue(
200
            self::XML_PATH_GETNET_CLIENT_ID_PRODUCTION,
201
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
202
            $store
203
        );
204
    }
205
206
    /**
207
     * Get Merchant Gateway Client Secret.
208
     *
209
     * @param null|string|bool|int|Store $store
210
     *
211
     * @return string
212
     */
213
    public function getMerchantGatewayClientSecret($store = null)
214
    {
215
        if ($this->getEnvironment($store) === 'sandbox') {
216
            return $this->_scopeConfig->getValue(
217
                self::XML_PATH_GETNET_CLIENT_SECRET_SANDBOX,
218
                \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
219
                $store
0 ignored issues
show
It seems like $store can also be of type Magento\Store\Model\Store; however, parameter $scopeCode of Magento\Framework\App\Co...igInterface::getValue() does only seem to accept integer|null|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

219
                /** @scrutinizer ignore-type */ $store
Loading history...
220
            );
221
        }
222
223
        if ($this->getEnvironment($store) === 'homolog') {
224
            return $this->_scopeConfig->getValue(
225
                self::XML_PATH_GETNET_CLIENT_SECRET_HOMOLOG,
226
                \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
227
                $store
228
            );
229
        }
230
231
        return $this->_scopeConfig->getValue(
232
            self::XML_PATH_GETNET_CLIENT_SECRET_PRODUCTION,
233
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
234
            $store
235
        );
236
    }
237
238
    /**
239
     * Get Uri.
240
     *
241
     * @param null|string|bool|int|Store $store
242
     *
243
     * @return string
244
     */
245
    public function getAuth($store = null)
246
    {
247
        if ($this->getEnvironment($store) === 'homolog') {
248
            return $this->_scopeConfig->getValue(
249
                self::XML_PATH_GETNET_AUTH_HOMOLOG,
250
                \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
251
                $store
0 ignored issues
show
It seems like $store can also be of type Magento\Store\Model\Store; however, parameter $scopeCode of Magento\Framework\App\Co...igInterface::getValue() does only seem to accept integer|null|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

251
                /** @scrutinizer ignore-type */ $store
Loading history...
252
            );
253
        }
254
255
        if ($this->getEnvironment($store) === 'sandbox') {
256
            return $this->_scopeConfig->getValue(
257
                self::XML_PATH_GETNET_AUTH_SANDBOX,
258
                \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
259
                $store
260
            );
261
        }
262
263
        return $this->_scopeConfig->getValue(
264
            self::XML_PATH_GETNET_AUTH_PRODUCTION,
265
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
266
            $store
267
        );
268
    }
269
270
    /**
271
     * Get Merchant Id.
272
     *
273
     * @param null|string|bool|int|Store $store
274
     *
275
     * @return string
276
     */
277
    public function getMerchantId($store = null)
278
    {
279
        if ($this->getEnvironment($store) === 'sandbox') {
280
            return $this->_scopeConfig->getValue(
281
                self::XML_PATH_GETNET_MERCHANT_ID_SANDBOX,
282
                \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
283
                $store
0 ignored issues
show
It seems like $store can also be of type Magento\Store\Model\Store; however, parameter $scopeCode of Magento\Framework\App\Co...igInterface::getValue() does only seem to accept integer|null|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

283
                /** @scrutinizer ignore-type */ $store
Loading history...
284
            );
285
        }
286
287
        if ($this->getEnvironment($store) === 'homolog') {
288
            return $this->_scopeConfig->getValue(
289
                self::XML_PATH_GETNET_MERCHANT_ID_HOMOLOG,
290
                \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
291
                $store
292
            );
293
        }
294
295
        return $this->_scopeConfig->getValue(
296
            self::XML_PATH_GETNET_MERCHANT_ID_PRODUCTION,
297
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
298
            $store
299
        );
300
    }
301
302
    /**
303
     * Get List Commissions.
304
     *
305
     * @param null|string|bool|int|Store $store
306
     *
307
     * @return array|string
308
     */
309
    public function getListCommissions($store = null)
310
    {
311
        $listCommissions = $this->_scopeConfig->getValue(
312
            self::XML_PATH_GETNET_LIST_COMMISSIONS,
313
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
314
            $store
0 ignored issues
show
It seems like $store can also be of type Magento\Store\Model\Store; however, parameter $scopeCode of Magento\Framework\App\Co...igInterface::getValue() does only seem to accept integer|null|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

314
            /** @scrutinizer ignore-type */ $store
Loading history...
315
        );
316
317
        if (is_array($listCommissions)) {
318
            return $listCommissions;
319
        }
320
321
        return $this->json->unserialize($listCommissions);
322
    }
323
}
324