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