Issues (1092)

Helper/ConfigExport.php (4 issues)

1
<?php
2
3
/**
4
 * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>.
16
 *
17
 * PHP version 5
18
 *
19
 * @category  Payone
20
 * @package   Payone_Magento2_Plugin
21
 * @author    FATCHIP GmbH <[email protected]>
22
 * @copyright 2003 - 2016 Payone GmbH
23
 * @license   <http://www.gnu.org/licenses/> GNU Lesser General Public License
24
 * @link      http://www.payone.de
25
 */
26
27
namespace Payone\Core\Helper;
28
29
/**
30
 * Helper class for the config export
31
 */
32
class ConfigExport extends \Payone\Core\Helper\Base
33
{
34
    /**
35
     * PAYONE payment helper
36
     *
37
     * @var \Payone\Core\Helper\Payment
38
     */
39
    protected $paymentHelper;
40
41
    /**
42
     * PAYONE database helper
43
     *
44
     * @var \Payone\Core\Helper\Database
45
     */
46
    protected $databaseHelper;
47
48
    /**
49
     * PAYONE config helper
50
     *
51
     * @var \Payone\Core\Helper\Config
52
     */
53
    protected $configHelper;
54
55
    /**
56
     * Constructor
57
     *
58
     * @param \Magento\Framework\App\Helper\Context      $context
59
     * @param \Magento\Store\Model\StoreManagerInterface $storeManager
60
     * @param \Payone\Core\Helper\Shop                   $shopHelper
61
     * @param \Magento\Framework\App\State               $state
62
     * @param \Payone\Core\Helper\Payment                $paymentHelper
63
     * @param \Payone\Core\Helper\Database               $databaseHelper
64
     * @param \Payone\Core\Helper\Config                 $configHelper
65
     */
66
    public function __construct(
67
        \Magento\Framework\App\Helper\Context $context,
0 ignored issues
show
The type Magento\Framework\App\Helper\Context 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...
68
        \Magento\Store\Model\StoreManagerInterface $storeManager,
0 ignored issues
show
The type Magento\Store\Model\StoreManagerInterface 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...
69
        \Payone\Core\Helper\Shop $shopHelper,
70
        \Magento\Framework\App\State $state,
0 ignored issues
show
The type Magento\Framework\App\State 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...
71
        \Payone\Core\Helper\Payment $paymentHelper,
72
        \Payone\Core\Helper\Database $databaseHelper,
73
        \Payone\Core\Helper\Config $configHelper
74
    ) {
75
        parent::__construct($context, $storeManager, $shopHelper, $state);
76
        $this->paymentHelper = $paymentHelper;
77
        $this->databaseHelper = $databaseHelper;
78
        $this->configHelper = $configHelper;
79
    }
80
81
    /**
82
     * Format module info from db
83
     *
84
     * @return array
85
     */
86
    public function getModuleInfo()
87
    {
88
        $aModules = [];
89
90
        $aResult = $this->databaseHelper->getModuleInfo();
91
        if ($aResult) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $aResult of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
92
            foreach ($aResult as $aRow) {
93
                $aModules[$aRow['module']] = $aRow['schema_version'];
94
            }
95
        }
96
        return $aModules;
97
    }
98
99
    /**
100
     * Get the configured status mappings for all payment types
101
     * for the given store
102
     *
103
     * @param  string $sStoreCode
104
     * @return array
105
     */
106
    public function getMappings($sStoreCode)
107
    {
108
        $aMappings = [];
109
110
        $aPaymentTypes = $this->paymentHelper->getAvailablePaymentTypes();
111
        foreach ($aPaymentTypes as $sPaymentCode) {
112
            $sPaymentMapping = $this->getConfigParam($sPaymentCode, 'statusmapping', 'payone_general', $sStoreCode);
113
            $aPaymentMapping = false;
114
            if (!empty($sPaymentMapping)) {
115
                $aPaymentMapping = $this->unserialize($sPaymentMapping);
116
            }
117
            if (is_array($aPaymentMapping) && !empty($aPaymentMapping)) {
118
                $aMap = [];
119
                foreach ($aPaymentMapping as $aPayMap) {
120
                    $aMap[] = [
121
                        'from' => $aPayMap['txaction'],
122
                        'to' => $aPayMap['state_status'],
123
                    ];
124
                }
125
                $aMappings[$this->paymentHelper->getPaymentAbbreviation($sPaymentCode)] = $aMap;
126
            }
127
        }
128
        return $aMappings;
129
    }
130
131
    /**
132
     * Get all configured status forwardings for the given store
133
     *
134
     * @param  string $sStoreCode
135
     * @return array
136
     */
137
    public function getForwardings($sStoreCode)
138
    {
139
        $aForwardingReturn = [];
140
        $aForwarding = $this->configHelper->getForwardingUrls($sStoreCode);
141
        foreach ($aForwarding as $aForwardEntry) {
142
            if (isset($aForwardEntry['txaction']) && !empty($aForwardEntry['txaction'])) {
143
                $aForwardingReturn[] = [
144
                    'status' => implode(',', $aForwardEntry['txaction']),
145
                    'url' => $aForwardEntry['url'],
146
                    'timeout' => (int)$aForwardEntry['timeout'],
147
                ];
148
            }
149
        }
150
        return $aForwardingReturn;
151
    }
152
153
    /**
154
     * Get config parameters of certain payment-types
155
     *
156
     * @param  string $sParam
157
     * @param  string $sPaymentCode
158
     * @param  string $sStoreCode
159
     * @param  bool   $blCheckGlobal
160
     * @return string
161
     */
162
    public function getPaymentConfig($sParam, $sPaymentCode, $sStoreCode, $blCheckGlobal = false)
163
    {
164
        $iPaymentUseGlobal = $this->getConfigParam('use_global', $sPaymentCode, 'payone_payment', $sStoreCode);
165
        if (!$blCheckGlobal || ($blCheckGlobal && $iPaymentUseGlobal == '0')) {
166
            return $this->getConfigParam($sParam, $sPaymentCode, 'payone_payment', $sStoreCode);
167
        }
168
        return $this->getConfigParam($sParam, 'global', 'payone_general', $sStoreCode);
169
    }
170
171
    /**
172
     * Get the allowed countries for a given payment type
173
     * or an empty string if all countries are allowed
174
     *
175
     * @param  string $sPaymentCode
176
     * @param  string $sStoreCode
177
     * @return string
178
     */
179
    public function getCountries($sPaymentCode, $sStoreCode)
180
    {
181
        if ($this->getPaymentConfig('allowspecific', $sPaymentCode, $sStoreCode, true) == '1') {
182
            return $this->getPaymentConfig('specificcountry', $sPaymentCode, $sStoreCode, true);
183
        }
184
        return ''; // empty return value if all countries are available
185
    }
186
}
187