Passed
Push[email protected] ( c856d5...27c8fa )
by Bruno
03:10
created

Config::getSplitValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 8
rs 10
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\Gateway\Config;
10
11
use Magento\Framework\App\Config\ScopeConfigInterface;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\App\Config\ScopeConfigInterface was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Magento\Store\Model\ScopeInterface;
0 ignored issues
show
Bug introduced by
The type Magento\Store\Model\ScopeInterface was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
14
/**
15
 * Class Config - Returns form of payment configuration properties.
16
 */
17
class Config extends \Magento\Payment\Gateway\Config\Config
0 ignored issues
show
Bug introduced by
The type Magento\Payment\Gateway\Config\Config was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
{
19
    /**
20
     * Method code - Base.
21
     *
22
     * @const string
23
     */
24
    const METHOD = 'moip_magento2';
25
26
    /**
27
     * Round up -  Used to define float in integers.
28
     *
29
     * @const int
30
     */
31
    const ROUND_UP = 100;
32
33
    /**
34
     * endpoint of production.
35
     *
36
     * @const string
37
     */
38
    const ENDPOINT_PRODUCTION = 'https://api.moip.com.br/v2/';
39
40
    /**
41
     * environment mode production.
42
     *
43
     * @const string
44
     */
45
    const ENVIRONMENT_PRODUCTION = 'production';
46
47
    /**
48
     * endpoint of sandbox.
49
     *
50
     * @const string
51
     */
52
    const ENDPOINT_SANDBOX = 'https://sandbox.moip.com.br/v2/';
53
54
    /**
55
     * environment mode sandbox.
56
     *
57
     * @const string
58
     */
59
    const ENVIRONMENT_SANDBOX = 'sandbox';
60
61
    /**
62
     * Client name.
63
     *
64
     * @const string
65
     * */
66
    const CLIENT = 'Magento2';
67
68
    /**
69
     * Client Version - API version.
70
     *
71
     * @const string
72
     */
73
    const CLIENT_VERSION = '2.0.0';
74
75
    /**
76
     * Config Pattern for Atribute.
77
     *
78
     * @const string
79
     */
80
    const PATTERN_FOR_ATTRIBUTES = 'moip_magento2';
81
82
    /**
83
     * Config Pattern for Credentials.
84
     *
85
     * @const string
86
     */
87
    const PATTERN_FOR_CREDENTIALS = 'moip_credentials';
88
89
    /**
90
     * URI For Oauth.
91
     *
92
     * @const string
93
     */
94
    const OAUTH_URI = 'http://moip.o2ti.com/magento/redirect/';
95
96
    /**
97
     * Scope App.
98
     *
99
     * @const string
100
     */
101
    const OAUTH_SCOPE = 'RECEIVE_FUNDS,REFUND,MANAGE_ACCOUNT_INFO,DEFINE_PREFERENCES,RETRIEVE_FINANCIAL_INFO';
102
103
    /**
104
     * Token App - Sandbox.
105
     *
106
     * @const string
107
     */
108
    const OAUTH_TOKEN_SANDBOX = '8OKLQFT5XQZXU7CKXX43GPJOMIJPMSMF';
109
110
    /**
111
     * Key App - Sandbox.
112
     *
113
     * @const string
114
     */
115
    const OAUTH_KEY_SANDBOX = 'NT0UKOXS4ALNSVOXJVNXVKRLEOQCITHI5HDKW3LI';
116
117
    /**
118
     * URI For Keys - Sandbox.
119
     *
120
     * @const string
121
     */
122
    const URL_KEY_SANDBOX = 'https://sandbox.moip.com.br/v2/keys/';
123
124
    /**
125
     * Endpoint For Oauth - Sandbox.
126
     *
127
     * @const string
128
     */
129
    const ENDPOINT_OAUTH_SANDBOX = 'https://connect-sandbox.moip.com.br/oauth/authorize';
130
131
    /**
132
     * Endpoint For Get Token Oauth - Sandbox.
133
     *
134
     * @const string
135
     */
136
    const ENDPOINT_OAUTH_TOKEN_SANDBOX = 'https://connect-sandbox.moip.com.br/oauth/token';
137
138
    /**
139
     * Endpoint For Preferences - Sandbox.
140
     *
141
     * @const string
142
     */
143
    const ENDPOINT_PREFERENCES_SANDBOX = 'https://sandbox.moip.com.br/v2/preferences/notifications/';
144
145
    /**
146
     * URI App Id - Sandbox.
147
     *
148
     * @const string
149
     */
150
    const APP_ID_SANDBOX = 'APP-9MUFQ39Y4CQU';
151
152
    /**
153
     * Secrect For Oauth - Sandbox.
154
     *
155
     * @const string
156
     */
157
    const CLIENT_SECRECT_SANDBOX = '26xa86dbc7mhdyqq2w69vscvhz47cri';
158
159
    /**
160
     * Endpoint For Oauth - Sandbox.
161
     *
162
     * @const string
163
     */
164
    const ENDPOINT_OAUTH_PRODUCTION = 'https://connect.moip.com.br/oauth/authorize';
165
166
    /**
167
     * Endpoint For Get Token Oauth - Sandbox.
168
     *
169
     * @const string
170
     */
171
    const ENDPOINT_OAUTH_TOKEN_PRODUCTION = 'https://connect.moip.com.br/oauth/token';
172
173
    /**
174
     * Token App - Sandbox.
175
     *
176
     * @const string
177
     */
178
    const OAUTH_TOKEN_PPRODUCTION = 'EVCHBAUMKM0U4EE4YXIA8VMC0KBEPKN2';
179
180
    /**
181
     * Key App - Sandbox.
182
     *
183
     * @const string
184
     */
185
    const OAUTH_KEY_PRODUCTION = '4NECP62EKI8HRSMN3FGYOZNVYZOMBDY0EQHK9MHO';
186
187
    /**
188
     * URI For Keys - Production.
189
     *
190
     * @const string
191
     */
192
    const URL_KEY_PRODUCTION = 'https://api.moip.com.br/v2/keys/';
193
194
    /**
195
     * Endpoint For Preferences - Sandbox.
196
     *
197
     * @const string
198
     */
199
    const ENDPOINT_PREFERENCES_PRODUCTION = 'https://api.moip.com.br/v2/preferences/notifications/';
200
201
    /**
202
     * URI App Id - Production.
203
     *
204
     * @const string
205
     */
206
    const APP_ID_PRODUCTION = 'APP-AKYBMMVU1FL1';
207
208
    /**
209
     * Secrect For Oauth - Production.
210
     *
211
     * @const string
212
     */
213
    const CLIENT_SECRECT_PRODUCTION = 'db9pavx8542khvsyn3s0tpxyu2gom2m';
214
215
    /**
216
     * @var ScopeConfigInterface
217
     */
218
    private $scopeConfig;
219
220
    /**
221
     * @param ScopeConfigInterface $scopeConfig
222
     */
223
    public function __construct(
224
        ScopeConfigInterface $scopeConfig,
225
        $methodCode = null
226
    ) {
227
        \Magento\Payment\Gateway\Config\Config::__construct($scopeConfig, $methodCode);
228
        $this->scopeConfig = $scopeConfig;
229
    }
230
231
    /**
232
     * Formant Price.
233
     *
234
     * @param int $amount
235
     *
236
     * @return int
237
     */
238
    public function formatPrice($amount)
239
    {
240
        return $amount * self::ROUND_UP;
241
    }
242
243
    /**
244
     * Gets the API endpoint URL.
245
     *
246
     * @param int|null $storeId
247
     *
248
     * @return string
249
     */
250
    public function getApiUrl($storeId = null)
251
    {
252
        $environment = $this->getEnvironmentMode($storeId);
253
254
        return $environment === 'sandbox'
255
            ? self::ENDPOINT_SANDBOX
256
            : self::ENDPOINT_PRODUCTION;
257
    }
258
259
    /**
260
     * Gets the Environment Mode.
261
     *
262
     * @param int|null $storeId
263
     *
264
     * @return string
265
     */
266
    public function getEnvironmentMode($storeId = null): string
267
    {
268
        $pathPattern = 'payment/%s/%s';
269
270
        $environment = $this->scopeConfig->getValue(
271
            sprintf($pathPattern, self::METHOD, 'environment'),
272
            ScopeInterface::SCOPE_STORE,
273
            $storeId
274
        );
275
276
        return $environment === 'sandbox'
277
            ? self::ENVIRONMENT_SANDBOX
278
            : self::ENVIRONMENT_PRODUCTION;
279
    }
280
281
    /**
282
     * Gets the Merchant Gateway OAuth.
283
     *
284
     * @param int|null $storeId
285
     *
286
     * @return string
287
     */
288
    public function getMerchantGatewayOauth($storeId = null): string
289
    {
290
        $pathPattern = 'payment/%s/%s';
291
292
        $oauth = $this->scopeConfig->getValue(
293
            sprintf($pathPattern, self::METHOD, 'oauth_production'),
294
            ScopeInterface::SCOPE_STORE,
295
            $storeId
296
        );
297
298
        $environment = $this->getEnvironmentMode($storeId);
299
300
        if ($environment === 'sandbox') {
301
            $oauth = $this->scopeConfig->getValue(
302
                sprintf($pathPattern, self::METHOD, 'oauth_sandbox'),
303
                ScopeInterface::SCOPE_STORE,
304
                $storeId
305
            );
306
        }
307
308
        return $oauth;
309
    }
310
311
    /**
312
     * Gets the Merchant Gateway Key Public.
313
     *
314
     * @param int|null $storeId
315
     *
316
     * @return string
317
     */
318
    public function getMerchantGatewayKeyPublic($storeId = null): string
319
    {
320
        $pathPattern = 'payment/%s/%s';
321
322
        $environment = $this->getEnvironmentMode($storeId);
323
324
        $keyPublic = $this->scopeConfig->getValue(
325
            sprintf($pathPattern, self::METHOD, 'key_public_production'),
326
            ScopeInterface::SCOPE_STORE,
327
            $storeId
328
        );
329
        if ($environment === 'sandbox') {
330
            $keyPublic = $this->scopeConfig->getValue(
331
                sprintf($pathPattern, self::METHOD, 'key_public_sandbox'),
332
                ScopeInterface::SCOPE_STORE,
333
                $storeId
334
            );
335
        }
336
337
        return $keyPublic;
338
    }
339
340
    /**
341
     * Gets the Merchant Gateway Capture Token.
342
     *
343
     * @param int|null $storeId
344
     *
345
     * @return string
346
     */
347
    public function getMerchantGatewayCaptureToken($storeId = null): string
348
    {
349
        $pathPattern = 'payment/%s/%s';
350
351
        $keyPublic = $this->scopeConfig->getValue(
352
            sprintf($pathPattern, self::METHOD, 'capture_token_production'),
353
            ScopeInterface::SCOPE_STORE,
354
            $storeId
355
        );
356
357
        $environment = $this->getEnvironmentMode($storeId);
358
359
        if ($environment === 'sandbox') {
360
            $keyPublic = $this->scopeConfig->getValue(
361
                sprintf($pathPattern, self::METHOD, 'capture_token_sandbox'),
362
                ScopeInterface::SCOPE_STORE,
363
                $storeId
364
            );
365
        }
366
367
        return $keyPublic;
368
    }
369
370
    /**
371
     * Gets the Merchant Gateway Cancel Token.
372
     *
373
     * @param int|null $storeId
374
     *
375
     * @return string
376
     */
377
    public function getMerchantGatewayCancelToken($storeId = null): string
378
    {
379
        $pathPattern = 'payment/%s/%s';
380
381
        $keyPublic = $this->scopeConfig->getValue(
382
            sprintf($pathPattern, self::METHOD, 'cancel_token_production'),
383
            ScopeInterface::SCOPE_STORE,
384
            $storeId
385
        );
386
387
        $environment = $this->getEnvironmentMode($storeId);
388
389
        if ($environment === 'sandbox') {
390
            $keyPublic = $this->scopeConfig->getValue(
391
                sprintf($pathPattern, self::METHOD, 'cancel_token_sandbox'),
392
                ScopeInterface::SCOPE_STORE,
393
                $storeId
394
            );
395
        }
396
397
        return $keyPublic;
398
    }
399
400
    /**
401
     * Gets the Merchant Gateway Refund Token.
402
     *
403
     * @param int|null $storeId
404
     *
405
     * @return string
406
     */
407
    public function getMerchantGatewayRefundToken($storeId = null): string
408
    {
409
        $pathPattern = 'payment/%s/%s';
410
411
        $keyPublic = $this->scopeConfig->getValue(
412
            sprintf($pathPattern, self::METHOD, 'refund_token_production'),
413
            ScopeInterface::SCOPE_STORE,
414
            $storeId
415
        );
416
417
        $environment = $this->getEnvironmentMode($storeId);
418
419
        if ($environment === 'sandbox') {
420
            $keyPublic = $this->scopeConfig->getValue(
421
                sprintf($pathPattern, self::METHOD, 'refund_token_sandbox'),
422
                ScopeInterface::SCOPE_STORE,
423
                $storeId
424
            );
425
        }
426
427
        return $keyPublic;
428
    }
429
430
    /**
431
     * Gets the Merchant Gateway Username.
432
     *
433
     * @param int|null $storeId
434
     *
435
     * @return string
436
     */
437
    public function getMerchantGatewayUsername($storeId = null): string
438
    {
439
        $environment = $this->getEnvironmentMode($storeId);
440
441
        if ($environment === 'sandbox') {
442
            return  $this->getAddtionalValue('merchant_gateway_username_sandbox', $storeId);
443
        } else {
444
            return  $this->getAddtionalValue('merchant_gateway_username', $storeId);
445
        }
446
    }
447
448
    public function getStatementDescriptor($storeId = null)
449
    {
450
        return  $this->getAddtionalValue('statement_descriptor', $storeId);
451
    }
452
453
    /**
454
     * Cc Mapper.
455
     *
456
     * @return array
457
     */
458
    public function getCcTypesMapper($storeId = null): array
459
    {
460
        $ccTypesMapper = $this->scopeConfig->getValue(
461
            'payment/moip_magento2_cc/cctypes_moip_magento2_cc_mapper',
462
            ScopeInterface::SCOPE_STORE,
463
            $storeId
464
        );
465
        $result = json_decode($ccTypesMapper, true);
466
467
        return is_array($result) ? $result : [];
468
    }
469
470
    /**
471
     * Gets the AddtionalValues.
472
     *
473
     * @param string   $typePattern
474
     * @param string   $field
475
     * @param int|null $storeId
476
     *
477
     * @return string
478
     */
479
    public function getAddtionalValue($field, $storeId = null): string
480
    {
481
        $pathPattern = 'payment/%s/%s';
482
483
        return $this->scopeConfig->getValue(
484
            sprintf($pathPattern, self::METHOD, $field),
485
            ScopeInterface::SCOPE_STORE,
486
            $storeId
487
        );
488
    }
489
490
    /**
491
     * Gets the SlipValue.
492
     *
493
     * @param string   $typePattern
494
     * @param string   $field
495
     * @param int|null $storeId
496
     *
497
     * @return string
498
     */
499
    public function getSplitValue($field, $storeId = null): string
500
    {
501
        $pathPattern = 'payment/%s/%s';
502
503
        return $this->scopeConfig->getValue(
504
            sprintf($pathPattern, self::METHOD, $field),
505
            ScopeInterface::SCOPE_STORE,
506
            $storeId
507
        );
508
    }
509
}
510