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