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 Magento\Framework\Phrase; |
||||
0 ignored issues
–
show
|
|||||
31 | use Payone\Core\Model\Source\CreditcardTypes; |
||||
32 | |||||
33 | /** |
||||
34 | * Helper class for everything that has to do with payment |
||||
35 | */ |
||||
36 | class Payment extends \Payone\Core\Helper\Base |
||||
37 | { |
||||
38 | /** |
||||
39 | * List of all currently available PAYONE payment types |
||||
40 | * |
||||
41 | * @var array |
||||
42 | */ |
||||
43 | protected $aAvailablePayments = [ |
||||
44 | PayoneConfig::METHOD_CREDITCARD, |
||||
45 | PayoneConfig::METHOD_DEBIT, |
||||
46 | PayoneConfig::METHOD_PAYPAL, |
||||
47 | PayoneConfig::METHOD_PAYPALV2, |
||||
48 | PayoneConfig::METHOD_CASH_ON_DELIVERY, |
||||
49 | PayoneConfig::METHOD_ADVANCE_PAYMENT, |
||||
50 | PayoneConfig::METHOD_INVOICE, |
||||
51 | PayoneConfig::METHOD_OBT_SOFORTUEBERWEISUNG, |
||||
52 | PayoneConfig::METHOD_OBT_EPS, |
||||
53 | PayoneConfig::METHOD_OBT_POSTFINANCE_EFINANCE, |
||||
54 | PayoneConfig::METHOD_OBT_POSTFINANCE_CARD, |
||||
55 | PayoneConfig::METHOD_OBT_IDEAL, |
||||
56 | PayoneConfig::METHOD_OBT_PRZELEWY, |
||||
57 | PayoneConfig::METHOD_SAFE_INVOICE, |
||||
58 | PayoneConfig::METHOD_PAYOLUTION_INVOICE, |
||||
59 | PayoneConfig::METHOD_PAYOLUTION_DEBIT, |
||||
60 | PayoneConfig::METHOD_PAYOLUTION_INSTALLMENT, |
||||
61 | PayoneConfig::METHOD_ALIPAY, |
||||
62 | PayoneConfig::METHOD_AMAZONPAY, |
||||
63 | PayoneConfig::METHOD_AMAZONPAYV2, |
||||
64 | PayoneConfig::METHOD_KLARNA_BASE, |
||||
65 | PayoneConfig::METHOD_KLARNA_DEBIT, |
||||
66 | PayoneConfig::METHOD_KLARNA_INVOICE, |
||||
67 | PayoneConfig::METHOD_KLARNA_INSTALLMENT, |
||||
68 | PayoneConfig::METHOD_WECHATPAY, |
||||
69 | PayoneConfig::METHOD_RATEPAY_INVOICE, |
||||
70 | PayoneConfig::METHOD_APPLEPAY, |
||||
71 | PayoneConfig::METHOD_BANCONTACT, |
||||
72 | PayoneConfig::METHOD_BNPL_INVOICE, |
||||
73 | PayoneConfig::METHOD_BNPL_INSTALLMENT, |
||||
74 | PayoneConfig::METHOD_BNPL_DEBIT, |
||||
75 | PayoneConfig::METHOD_GOOGLE_PAY, |
||||
76 | ]; |
||||
77 | |||||
78 | /** |
||||
79 | * Mapping of payment method code to payment abbreviation |
||||
80 | * |
||||
81 | * @var array |
||||
82 | */ |
||||
83 | protected $aPaymentAbbreviation = [ |
||||
84 | PayoneConfig::METHOD_CREDITCARD => 'cc', |
||||
85 | PayoneConfig::METHOD_CASH_ON_DELIVERY => 'cod', |
||||
86 | PayoneConfig::METHOD_DEBIT => 'elv', |
||||
87 | PayoneConfig::METHOD_ADVANCE_PAYMENT => 'vor', |
||||
88 | PayoneConfig::METHOD_INVOICE => 'rec', |
||||
89 | PayoneConfig::METHOD_OBT_SOFORTUEBERWEISUNG => 'sb', |
||||
90 | PayoneConfig::METHOD_OBT_EPS => 'sb', |
||||
91 | PayoneConfig::METHOD_OBT_POSTFINANCE_EFINANCE => 'sb', |
||||
92 | PayoneConfig::METHOD_OBT_POSTFINANCE_CARD => 'sb', |
||||
93 | PayoneConfig::METHOD_OBT_IDEAL => 'sb', |
||||
94 | PayoneConfig::METHOD_OBT_PRZELEWY => 'sb', |
||||
95 | PayoneConfig::METHOD_PAYPAL => 'wlt', |
||||
96 | PayoneConfig::METHOD_PAYPALV2 => 'wlt', |
||||
97 | PayoneConfig::METHOD_SAFE_INVOICE => 'rec', |
||||
98 | PayoneConfig::METHOD_PAYOLUTION_INVOICE => 'fnc', |
||||
99 | PayoneConfig::METHOD_PAYOLUTION_DEBIT => 'fnc', |
||||
100 | PayoneConfig::METHOD_PAYOLUTION_INSTALLMENT => 'fnc', |
||||
101 | PayoneConfig::METHOD_ALIPAY => 'wlt', |
||||
102 | PayoneConfig::METHOD_AMAZONPAY => 'wlt', |
||||
103 | PayoneConfig::METHOD_AMAZONPAYV2 => 'wlt', |
||||
104 | PayoneConfig::METHOD_KLARNA_BASE => 'wlt', |
||||
105 | PayoneConfig::METHOD_KLARNA_DEBIT => 'wlt', |
||||
106 | PayoneConfig::METHOD_KLARNA_INVOICE => 'wlt', |
||||
107 | PayoneConfig::METHOD_KLARNA_INSTALLMENT => 'wlt', |
||||
108 | PayoneConfig::METHOD_WECHATPAY => 'wlt', |
||||
109 | PayoneConfig::METHOD_RATEPAY_INVOICE => 'fnc', |
||||
110 | PayoneConfig::METHOD_APPLEPAY => 'wlt', |
||||
111 | PayoneConfig::METHOD_BANCONTACT => 'sb', |
||||
112 | PayoneConfig::METHOD_GOOGLE_PAY => 'wlt', |
||||
113 | ]; |
||||
114 | |||||
115 | /** |
||||
116 | * Return available payment types |
||||
117 | * |
||||
118 | * @return array |
||||
119 | */ |
||||
120 | public function getAvailablePaymentTypes() |
||||
121 | { |
||||
122 | return $this->aAvailablePayments; |
||||
123 | } |
||||
124 | |||||
125 | /** |
||||
126 | * Get all activated creditcard types |
||||
127 | * |
||||
128 | * @return array |
||||
129 | */ |
||||
130 | public function getAvailableCreditcardTypes() |
||||
131 | { |
||||
132 | $aReturn = []; |
||||
133 | |||||
134 | $sCreditcardTypes = $this->getConfigParam('types', PayoneConfig::METHOD_CREDITCARD, 'payone_payment'); |
||||
135 | if ($sCreditcardTypes) { |
||||
136 | $aAllTypes = CreditcardTypes::getCreditcardTypes(); |
||||
137 | |||||
138 | $aCreditcardTypes = explode(',', $sCreditcardTypes); |
||||
139 | foreach ($aCreditcardTypes as $sTypeId) { |
||||
140 | if (!isset($aAllTypes[$sTypeId])) { |
||||
141 | continue; |
||||
142 | } |
||||
143 | $aReturn[] = [ |
||||
144 | 'id' => $aAllTypes[$sTypeId]['cardtype'], |
||||
145 | 'title' => $aAllTypes[$sTypeId]['name'], |
||||
146 | 'cvc_length' => $aAllTypes[$sTypeId]['cvc_length'], |
||||
147 | ]; |
||||
148 | } |
||||
149 | } |
||||
150 | return $aReturn; |
||||
151 | } |
||||
152 | |||||
153 | /** |
||||
154 | * Returns configured available apple pay types |
||||
155 | * |
||||
156 | * @return array |
||||
157 | */ |
||||
158 | public function getAvailableApplePayTypes() |
||||
159 | { |
||||
160 | $aReturn = []; |
||||
161 | |||||
162 | $sApplePayTypes = $this->getConfigParam('types', PayoneConfig::METHOD_APPLEPAY, 'payone_payment'); |
||||
163 | if ($sApplePayTypes) { |
||||
164 | return explode(',', $sApplePayTypes); |
||||
165 | } |
||||
166 | return $aReturn; |
||||
167 | } |
||||
168 | |||||
169 | /** |
||||
170 | * Return if cvc has to be checked |
||||
171 | * |
||||
172 | * @return bool |
||||
173 | */ |
||||
174 | public function isCheckCvcActive() |
||||
175 | { |
||||
176 | return (bool)$this->getConfigParam('check_cvc', PayoneConfig::METHOD_CREDITCARD, 'payone_payment'); |
||||
177 | } |
||||
178 | |||||
179 | /** |
||||
180 | * Return if mandate management is activated |
||||
181 | * |
||||
182 | * @return bool |
||||
183 | */ |
||||
184 | public function isMandateManagementActive() |
||||
185 | { |
||||
186 | return (bool)$this->getConfigParam('sepa_mandate_enabled', PayoneConfig::METHOD_DEBIT, 'payone_payment'); |
||||
187 | } |
||||
188 | |||||
189 | /** |
||||
190 | * Return if mandate download is activated |
||||
191 | * |
||||
192 | * @return bool |
||||
193 | */ |
||||
194 | public function isMandateManagementDownloadActive() |
||||
195 | { |
||||
196 | return (bool)$this->getConfigParam('sepa_mandate_download_enabled', PayoneConfig::METHOD_DEBIT, 'payone_payment'); |
||||
197 | } |
||||
198 | |||||
199 | /** |
||||
200 | * Get status mapping configuration for given payment type |
||||
201 | * |
||||
202 | * @param string $sPaymentCode |
||||
203 | * @return array |
||||
204 | */ |
||||
205 | public function getStatusMappingByCode($sPaymentCode) |
||||
206 | { |
||||
207 | $sStatusMapping = $this->getConfigParam($sPaymentCode, 'statusmapping'); |
||||
208 | $aStatusMapping = $this->unserialize($sStatusMapping); |
||||
209 | $aCleanMapping = []; |
||||
210 | if ($aStatusMapping) { |
||||
211 | foreach ($aStatusMapping as $aMap) { |
||||
212 | if (isset($aMap['txaction']) && isset($aMap['state_status'])) { |
||||
213 | $aCleanMapping[$aMap['txaction']] = $aMap['state_status']; |
||||
214 | } |
||||
215 | } |
||||
216 | } |
||||
217 | return $aCleanMapping; |
||||
218 | } |
||||
219 | |||||
220 | /** |
||||
221 | * Return display-message for the case that the bankaccount check |
||||
222 | * returned, that the given bankaccount was blocked |
||||
223 | * |
||||
224 | * @return Phrase |
||||
225 | */ |
||||
226 | public function getBankaccountCheckBlockedMessage() |
||||
227 | { |
||||
228 | $sMessage = $this->getConfigParam('message_response_blocked', PayoneConfig::METHOD_DEBIT, 'payone_payment'); |
||||
229 | if (empty($sMessage)) { |
||||
230 | $sMessage = 'Bankdata invalid.'; |
||||
231 | } |
||||
232 | return __($sMessage); |
||||
0 ignored issues
–
show
The function
__ was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
233 | } |
||||
234 | |||||
235 | /** |
||||
236 | * Return is PayPal Express is activated in the configuration |
||||
237 | * |
||||
238 | * @return bool |
||||
239 | */ |
||||
240 | public function isPayPalExpressActive() |
||||
241 | { |
||||
242 | return (bool)$this->getConfigParam('express_active', PayoneConfig::METHOD_PAYPAL, 'payone_payment') && $this->isPaymentMethodActive(PayoneConfig::METHOD_PAYPAL); |
||||
243 | } |
||||
244 | |||||
245 | /** |
||||
246 | * Return is PayPal Express V2 is activated in the configuration |
||||
247 | * |
||||
248 | * @return bool |
||||
249 | */ |
||||
250 | public function isPayPalExpressV2Active() |
||||
251 | { |
||||
252 | return (bool)$this->getConfigParam('express_active', PayoneConfig::METHOD_PAYPALV2, 'payone_payment') && $this->isPaymentMethodActive(PayoneConfig::METHOD_PAYPALV2); |
||||
253 | } |
||||
254 | |||||
255 | /** |
||||
256 | * Get abbreviation for the given payment type |
||||
257 | * |
||||
258 | * @param string $sPaymentCode |
||||
259 | * @return string |
||||
260 | */ |
||||
261 | public function getPaymentAbbreviation($sPaymentCode) |
||||
262 | { |
||||
263 | if (isset($this->aPaymentAbbreviation[$sPaymentCode])) { |
||||
264 | return $this->aPaymentAbbreviation[$sPaymentCode]; |
||||
265 | } |
||||
266 | return 'unknown'; |
||||
267 | } |
||||
268 | |||||
269 | /** |
||||
270 | * Collect the Klarna store ids from the config and format it for frontend-use |
||||
271 | * |
||||
272 | * @return array |
||||
273 | */ |
||||
274 | public function getKlarnaStoreIds() |
||||
275 | { |
||||
276 | $aStoreIds = []; |
||||
277 | $aKlarnaConfig = $this->unserialize($this->getConfigParam('klarna_config', PayoneConfig::METHOD_KLARNA, 'payone_payment')); |
||||
278 | if (!is_array($aKlarnaConfig)) { |
||||
279 | return $aStoreIds; |
||||
280 | } |
||||
281 | |||||
282 | foreach ($aKlarnaConfig as $aItem) { |
||||
283 | if (!empty($aItem['store_id']) && isset($aItem['countries'])) { |
||||
284 | foreach ($aItem['countries'] as $sCountry) { |
||||
285 | $aStoreIds[$sCountry] = $aItem['store_id']; |
||||
286 | } |
||||
287 | } |
||||
288 | } |
||||
289 | return $aStoreIds; |
||||
290 | } |
||||
291 | |||||
292 | /** |
||||
293 | * Check if given payment method is activated |
||||
294 | * |
||||
295 | * @param string $sMethodCode |
||||
296 | * @return bool |
||||
297 | */ |
||||
298 | public function isPaymentMethodActive($sMethodCode) |
||||
299 | { |
||||
300 | return (bool)$this->getConfigParam('active', $sMethodCode, 'payment'); |
||||
301 | } |
||||
302 | |||||
303 | /** |
||||
304 | * Get amazon widget url depending on the mode |
||||
305 | * |
||||
306 | * @return string |
||||
307 | */ |
||||
308 | public function getAmazonPayWidgetUrl() |
||||
309 | { |
||||
310 | $sSandbox = ''; |
||||
311 | if ('test' == $this->getConfigParam('mode', PayoneConfig::METHOD_AMAZONPAY, 'payone_payment')) { |
||||
312 | $sSandbox = '/sandbox'; |
||||
313 | } |
||||
314 | return "https://static-eu.payments-amazon.com/OffAmazonPayments/eur".$sSandbox."/lpa/js/Widgets.js"; |
||||
315 | } |
||||
316 | |||||
317 | /** |
||||
318 | * Returns method titles of Klarna payment methods |
||||
319 | */ |
||||
320 | public function getKlarnaMethodTitles() |
||||
321 | { |
||||
322 | return [ |
||||
323 | PayoneConfig::METHOD_KLARNA_INVOICE => $this->getConfigParam('title', PayoneConfig::METHOD_KLARNA_INVOICE, 'payment'), |
||||
324 | PayoneConfig::METHOD_KLARNA_DEBIT => $this->getConfigParam('title', PayoneConfig::METHOD_KLARNA_DEBIT, 'payment'), |
||||
325 | PayoneConfig::METHOD_KLARNA_INSTALLMENT => $this->getConfigParam('title', PayoneConfig::METHOD_KLARNA_INSTALLMENT, 'payment'), |
||||
326 | ]; |
||||
327 | } |
||||
328 | |||||
329 | /** |
||||
330 | * Check for non global custom configuration |
||||
331 | * |
||||
332 | * @param string $sParam |
||||
333 | * @param string $sMethodCode |
||||
334 | * @param string|null $sStoreCode |
||||
335 | * @return string |
||||
336 | */ |
||||
337 | public function getCustomConfigParam($sParam, $sMethodCode, $sStoreCode = null) |
||||
338 | { |
||||
339 | $blUseGlobal = (bool)$this->getConfigParam('use_global', $sMethodCode, 'payone_payment', $sStoreCode); |
||||
340 | $sCustomValue = $this->getConfigParam($sParam, $sMethodCode, 'payone_payment', $sStoreCode); |
||||
341 | if ($blUseGlobal === false && !empty($sCustomValue)) { |
||||
342 | return $sCustomValue; |
||||
343 | } |
||||
344 | return $this->getConfigParam($sParam, 'global', 'payone_general', $sStoreCode);; |
||||
345 | } |
||||
346 | } |
||||
347 |
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