-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathConfigProvider.php
More file actions
105 lines (93 loc) · 3.37 KB
/
ConfigProvider.php
File metadata and controls
105 lines (93 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/**
* Created by PhpStorm.
* User: Ion Bogatu
* Date: 5/9/2018
* Time: 4:54 PM
*/
namespace Signifyd\Connect\Model;
use Magento\Store\Model\StoreManagerInterface;
use Signifyd\Connect\Helper\ConfigHelper;
use Magento\Framework\Module\ModuleListInterface;
use Magento\Framework\Component\ComponentRegistrarInterface;
use Magento\Framework\Component\ComponentRegistrar;
use Magento\Framework\Filesystem\Directory\ReadFactory;
class ConfigProvider implements \Magento\Checkout\Model\ConfigProviderInterface
{
/**
* @var ConfigHelper
*/
protected $configHelper;
/**
* @var StoreManagerInterface
*/
protected $storeManager;
/**
* @var ModuleListInterface
*/
protected $moduleListInterface;
protected ComponentRegistrarInterface $componentRegistrar;
protected ReadFactory $readFactory;
/**
* @param ConfigHelper $configHelper
* @param StoreManagerInterface $storeManager
* @param ModuleListInterface $moduleListInterface
*/
public function __construct(
ReadFactory $readFactory,
ComponentRegistrarInterface $componentRegistrar,
ConfigHelper $configHelper,
StoreManagerInterface $storeManager,
ModuleListInterface $moduleListInterface
) {
$this->storeManager = $storeManager;
$this->moduleListInterface = $moduleListInterface;
$this->configHelper = $configHelper;
$this->componentRegistrar = $componentRegistrar;
$this->readFactory = $readFactory;
}
public function getConfig()
{
$policyName = $this->configHelper->getPolicyName(
\Magento\Store\Model\ScopeInterface::SCOPE_STORES,
$this->storeManager->getStore()->getCode()
);
$isAdyenGreaterThanEightEighteen = false;
$isAdyenGreaterThanEight = false;
$adyenModule = $this->moduleListInterface->getOne('Adyen_Payment');
if (isset($adyenModule)) {
$adyenVersion = $this->getModuleVersionFromComposer('Adyen_Payment');
$isAdyenGreaterThanEightEighteen = version_compare($adyenVersion, '8.18.0') >= 0;
$isAdyenGreaterThanEight = version_compare($adyenVersion, '8.0.0') >= 0 &&
version_compare($adyenVersion, '8.17.9') <= 0;
}
$isAdyenPreAuth = $this->configHelper->getIsPreAuth(
$policyName,
'adyen_cc',
\Magento\Store\Model\ScopeInterface::SCOPE_STORES,
$this->storeManager->getStore()->getCode()
);
return [ 'signifyd' => [
'isAdyenPreAuth' => $isAdyenPreAuth,
'isAdyenGreaterThanEightEighteen' => $isAdyenGreaterThanEightEighteen,
'isAdyenGreaterThanEight' => $isAdyenGreaterThanEight]
];
}
/**
* Get version from composer.json if it exist otherwise return empty string
* @param string $moduleName
* @return string
*/
public function getModuleVersionFromComposer(string $moduleName) : string
{
$path = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName);
$directoryRead = $this->readFactory->create($path);
$composerJsonData = $directoryRead->readFile('composer.json');
$data = json_decode($composerJsonData, true);
if (is_null($data))
{
return '';
}
return isset($data['version']) ? $data['version'] : '';
}
}