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 | use Payone\Core\Model\PayoneConfig; |
||
30 | use Payone\Core\Model\Source\CreditcardTypes; |
||
31 | |||
32 | /** |
||
33 | * Helper class for everything that has to do with hosted Iframe |
||
34 | */ |
||
35 | class HostedIframe extends \Payone\Core\Helper\Base |
||
36 | { |
||
37 | /** |
||
38 | * Configuration params for the hosted Iframe creditcard implementation |
||
39 | * |
||
40 | * @var array |
||
41 | */ |
||
42 | protected $aHostedParams = null; |
||
43 | |||
44 | /** |
||
45 | * PAYONE payment helper |
||
46 | * |
||
47 | * @var \Payone\Core\Helper\Payment |
||
48 | */ |
||
49 | protected $paymentHelper; |
||
50 | |||
51 | /** |
||
52 | * PAYONE toolkit helper |
||
53 | * |
||
54 | * @var \Payone\Core\Helper\Toolkit |
||
55 | */ |
||
56 | protected $toolkitHelper; |
||
57 | |||
58 | /** |
||
59 | * Constructor |
||
60 | * |
||
61 | * @param \Magento\Framework\App\Helper\Context $context |
||
62 | * @param \Magento\Store\Model\StoreManagerInterface $storeManager |
||
63 | * @param \Payone\Core\Helper\Shop $shopHelper |
||
64 | * @param \Magento\Framework\App\State $state |
||
65 | * @param \Payone\Core\Helper\Payment $paymentHelper |
||
66 | */ |
||
67 | public function __construct( |
||
68 | \Magento\Framework\App\Helper\Context $context, |
||
69 | \Magento\Store\Model\StoreManagerInterface $storeManager, |
||
70 | \Payone\Core\Helper\Shop $shopHelper, |
||
71 | \Magento\Framework\App\State $state, |
||
0 ignored issues
–
show
|
|||
72 | \Payone\Core\Helper\Payment $paymentHelper |
||
73 | ) { |
||
74 | parent::__construct($context, $storeManager, $shopHelper, $state); |
||
75 | $this->paymentHelper = $paymentHelper; |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * Get hosted params configuration |
||
80 | * |
||
81 | * @return array |
||
82 | */ |
||
83 | protected function getHostedParams() |
||
84 | { |
||
85 | if ($this->aHostedParams === null) { |
||
86 | $this->aHostedParams = []; |
||
87 | $sHostedParams = $this->getConfigParam('cc_template', 'creditcard'); // get params from config |
||
88 | if ($sHostedParams) { // params set in config? |
||
89 | $aHostedParams = $this->unserialize($sHostedParams); // array from serialized string |
||
90 | if (is_array($aHostedParams) && !empty($aHostedParams)) { |
||
91 | $this->aHostedParams = $aHostedParams; |
||
92 | } |
||
93 | } |
||
94 | } |
||
95 | return $this->aHostedParams; |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * Get the field config for one field type for hosted Iframe implementation |
||
100 | * |
||
101 | * @param string $sName |
||
102 | * @param string $sParamPrefix |
||
103 | * @return array |
||
104 | */ |
||
105 | protected function getFieldConfigField($sName, $sParamPrefix) |
||
106 | { |
||
107 | $aHostedParams = $this->getHostedParams(); |
||
108 | |||
109 | $aField = []; |
||
110 | if (!empty($aHostedParams)) { |
||
111 | $aField['selector'] = $sName; |
||
112 | $aField['type'] = $aHostedParams[$sParamPrefix.'_type']; |
||
113 | $aField['size'] = $aHostedParams[$sParamPrefix.'_count']; |
||
114 | $aField['maxlength'] = $aHostedParams[$sParamPrefix.'_max']; |
||
115 | if ($aHostedParams[$sParamPrefix.'_style'] == "custom") { |
||
116 | $aField['style'] = $aHostedParams[$sParamPrefix.'_css']; |
||
117 | } |
||
118 | if ($aHostedParams[$sParamPrefix.'_iframe'] == "custom") { |
||
119 | $aField['iframe'] = [ |
||
120 | 'width' => $aHostedParams[$sParamPrefix.'_width'], |
||
121 | 'height' => $aHostedParams[$sParamPrefix.'_height'], |
||
122 | ]; |
||
123 | } |
||
124 | } |
||
125 | return $aField; |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * Create field config array |
||
130 | * |
||
131 | * @return array |
||
132 | */ |
||
133 | protected function getFieldConfig() |
||
134 | { |
||
135 | $aFields = []; |
||
136 | $aFields['cardpan'] = $this->getFieldConfigField('cardpan', 'Number'); |
||
137 | if ($this->paymentHelper->isCheckCvcActive() === true) { // cvc field activated? |
||
138 | $aFields['cardcvc2'] = $this->getFieldConfigField('cardcvc2', 'CVC'); |
||
139 | $aFields['cardcvc2']['length'] = $this->getCvcMaxLengths(); |
||
140 | } |
||
141 | $aFields['cardexpiremonth'] = $this->getFieldConfigField('cardexpiremonth', 'Month'); |
||
142 | $aFields['cardexpireyear'] = $this->getFieldConfigField('cardexpireyear', 'Year'); |
||
143 | return $aFields; |
||
144 | } |
||
145 | |||
146 | /** |
||
147 | * Return array with the cvc length of all creditcard types |
||
148 | * |
||
149 | * @return array |
||
150 | */ |
||
151 | protected function getCvcMaxLengths() |
||
152 | { |
||
153 | $aLenghts = []; |
||
154 | foreach (CreditcardTypes::getCreditcardTypes() as $sType => $aType) { |
||
155 | $aLenghts[$aType['cardtype']] = $aType['cvc_length']; |
||
156 | } |
||
157 | return $aLenghts; |
||
158 | } |
||
159 | |||
160 | /** |
||
161 | * Create default style array |
||
162 | * |
||
163 | * @param array $aHostedParams |
||
164 | * @return array |
||
165 | */ |
||
166 | protected function getDefaultStyles($aHostedParams) |
||
167 | { |
||
168 | $aDefaultStyle = []; |
||
169 | $aDefaultStyle['input'] = $aHostedParams['Standard_input']; |
||
170 | $aDefaultStyle['select'] = $aHostedParams['Standard_selection']; |
||
171 | $aDefaultStyle['iframe'] = [ |
||
172 | 'width' => $aHostedParams['Iframe_width'], |
||
173 | 'height' => $aHostedParams['Iframe_height'], |
||
174 | ]; |
||
175 | return $aDefaultStyle; |
||
176 | } |
||
177 | |||
178 | /** |
||
179 | * Returns the auto cardtype detection config. |
||
180 | * |
||
181 | * @return array|null The auto cardtype detection config or null if auto cardtype detection is disabled. |
||
182 | */ |
||
183 | protected function getAutoCardtypeDetectionConfig() |
||
184 | { |
||
185 | // Get enabled state of auto cardtype detection. |
||
186 | $autoCcDetection = $this->getConfigParam('auto_cardtype_detection', PayoneConfig::METHOD_CREDITCARD, 'payment') === '1'; |
||
187 | |||
188 | if ($autoCcDetection) { |
||
189 | // Get a flat CC type array like (e.g. ["V", "M", "J", "U", "P"]). |
||
190 | $availableCcTypes = array_map(function ($type) { return $type['id']; }, $this->paymentHelper->getAvailableCreditcardTypes()); |
||
191 | |||
192 | // Return the auto cardtype detection config with enabled CC types. |
||
193 | return [ |
||
194 | 'supportedCardtypes' => $availableCcTypes, |
||
195 | |||
196 | // This is just a placeholder and will be set in JS code later. |
||
197 | 'callback' => false, |
||
198 | ]; |
||
199 | } |
||
200 | |||
201 | // Indicates disabled auto-detection setting. |
||
202 | return null; |
||
203 | } |
||
204 | |||
205 | /** |
||
206 | * Generate the complete hosted iframe configuration |
||
207 | * |
||
208 | * @return array |
||
209 | */ |
||
210 | public function getHostedFieldConfig() |
||
211 | { |
||
212 | $aHostedParams = $this->getHostedParams(); // get hosted params from config |
||
213 | |||
214 | $aFieldConfig = []; |
||
215 | if (!empty($aHostedParams)) { // hosted iframe config existing? |
||
216 | $aFieldConfig['fields'] = $this->getFieldConfig(); // generate config for all field types |
||
217 | $aFieldConfig['defaultStyle'] = $this->getDefaultStyles($aHostedParams); |
||
218 | |||
219 | // Add auto cardtype detection config (if enabled in the settings). |
||
220 | $autoCardtypeDetectionConfig = $this->getAutoCardtypeDetectionConfig(); |
||
221 | if ($autoCardtypeDetectionConfig) { |
||
222 | $aFieldConfig['autoCardtypeDetection'] = $autoCardtypeDetectionConfig; |
||
223 | } |
||
224 | |||
225 | if ($aHostedParams['Errors_active'] == "true") { |
||
226 | $aFieldConfig['error'] = 'errorOutput'; // area to display error-messages (optional) |
||
227 | $aFieldConfig['language'] = $aHostedParams['Errors_lang']; // has to be defined in javascript |
||
228 | } |
||
229 | } |
||
230 | return $aFieldConfig; |
||
231 | } |
||
232 | } |
||
233 |
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