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\Model\Methods; |
28
|
|
|
|
29
|
|
|
use Payone\Core\Model\PayoneConfig; |
30
|
|
|
use Magento\Payment\Model\InfoInterface; |
|
|
|
|
31
|
|
|
use Magento\Payment\Model\Method\AbstractMethod; |
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Abstract model for all the PAYONE payment methods |
35
|
|
|
* |
36
|
|
|
* @category Payone |
37
|
|
|
* @package Payone_Magento2_Plugin |
38
|
|
|
* @author FATCHIP GmbH <[email protected]> |
39
|
|
|
* @copyright 2003 - 2016 Payone GmbH |
40
|
|
|
* @license <http://www.gnu.org/licenses/> GNU Lesser General Public License |
41
|
|
|
* @link http://www.payone.de |
42
|
|
|
*/ |
43
|
|
|
abstract class BaseMethod extends AbstractMethod |
44
|
|
|
{ |
45
|
|
|
/** |
46
|
|
|
* Info instructions block path |
47
|
|
|
* |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
protected $_infoBlockType = 'Payone\Core\Block\Info\Basic'; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Form block path |
54
|
|
|
* |
55
|
|
|
* @var string |
56
|
|
|
*/ |
57
|
|
|
protected $_formBlockType = 'Payone\Core\Block\Form\Base'; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Availability option |
61
|
|
|
* |
62
|
|
|
* @var bool |
63
|
|
|
*/ |
64
|
|
|
protected $_isOffline = false; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Payment Method feature |
68
|
|
|
* |
69
|
|
|
* @var bool |
70
|
|
|
*/ |
71
|
|
|
protected $_canAuthorize = true; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Determines if payment type can use refund mechanism |
75
|
|
|
* |
76
|
|
|
* @var bool |
77
|
|
|
*/ |
78
|
|
|
protected $_canRefund = true; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Determines if payment type can use capture mechanism |
82
|
|
|
* |
83
|
|
|
* @var bool |
84
|
|
|
*/ |
85
|
|
|
protected $_canCapture = true; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Determines if payment type can use partial captures |
89
|
|
|
* Is true for all PAYONE Payment Methods |
90
|
|
|
* |
91
|
|
|
* @var bool |
92
|
|
|
*/ |
93
|
|
|
protected $_canCapturePartial = true; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Determines if payment type can use partial refunds |
97
|
|
|
* |
98
|
|
|
* @var bool |
99
|
|
|
*/ |
100
|
|
|
protected $_canRefundInvoicePartial = true; |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Clearingtype for PAYONE authorization request |
104
|
|
|
* |
105
|
|
|
* @var string|bool |
106
|
|
|
*/ |
107
|
|
|
protected $sClearingtype = false; |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Wallettype for PAYONE requests |
111
|
|
|
* |
112
|
|
|
* @var string|bool |
113
|
|
|
*/ |
114
|
|
|
protected $sWallettype = false; |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Determines if the redirect-parameters have to be added |
118
|
|
|
* to the authorization-request |
119
|
|
|
* |
120
|
|
|
* @var bool |
121
|
|
|
*/ |
122
|
|
|
protected $blNeedsRedirectUrls = false; |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Determines if the transaction_param-parameter has to be added to the authorization-request |
126
|
|
|
* |
127
|
|
|
* @var bool |
128
|
|
|
*/ |
129
|
|
|
protected $blNeedsTransactionParam = false; |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Determines if the invoice information has to be added |
133
|
|
|
* to the authorization-request |
134
|
|
|
* |
135
|
|
|
* @var bool |
136
|
|
|
*/ |
137
|
|
|
protected $blNeedsProductInfo = false; |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Determines if the bank data has to be added to the debit-request |
141
|
|
|
* |
142
|
|
|
* @var bool |
143
|
|
|
*/ |
144
|
|
|
protected $blNeedsSepaDataOnDebit = false; |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Max length for narrative text parameter |
148
|
|
|
* |
149
|
|
|
* @var int |
150
|
|
|
*/ |
151
|
|
|
protected $iNarrativeTextMax = 81; |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* PAYONE toolkit helper |
155
|
|
|
* |
156
|
|
|
* @var \Payone\Core\Helper\Toolkit |
157
|
|
|
*/ |
158
|
|
|
protected $toolkitHelper; |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* PAYONE shop helper |
162
|
|
|
* |
163
|
|
|
* @var \Payone\Core\Helper\Shop |
164
|
|
|
*/ |
165
|
|
|
protected $shopHelper; |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* URL helper |
169
|
|
|
* |
170
|
|
|
* @var \Magento\Framework\Url |
|
|
|
|
171
|
|
|
*/ |
172
|
|
|
protected $url; |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Checkout session model |
176
|
|
|
* |
177
|
|
|
* @var \Magento\Checkout\Model\Session |
|
|
|
|
178
|
|
|
*/ |
179
|
|
|
protected $checkoutSession; |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Payment method group identifier |
183
|
|
|
* |
184
|
|
|
* @var string|bool |
185
|
|
|
*/ |
186
|
|
|
protected $sGroupName = false; |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Payment method sub type |
190
|
|
|
* |
191
|
|
|
* @var string|bool |
192
|
|
|
*/ |
193
|
|
|
protected $sSubType = false; |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* PAYONE debit request model |
197
|
|
|
* |
198
|
|
|
* @var \Payone\Core\Model\Api\Request\Debit |
199
|
|
|
*/ |
200
|
|
|
protected $debitRequest; |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* PAYONE capture request model |
204
|
|
|
* |
205
|
|
|
* @var \Payone\Core\Model\Api\Request\Capture |
206
|
|
|
*/ |
207
|
|
|
protected $captureRequest; |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* PAYONE authorization request model |
211
|
|
|
* |
212
|
|
|
* @var \Payone\Core\Model\Api\Request\Authorization |
213
|
|
|
*/ |
214
|
|
|
protected $authorizationRequest; |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* Resource model for saved payment data |
218
|
|
|
* |
219
|
|
|
* @var \Payone\Core\Model\ResourceModel\SavedPaymentData |
220
|
|
|
*/ |
221
|
|
|
protected $savedPaymentData; |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* Constructor |
225
|
|
|
* |
226
|
|
|
* @param \Magento\Framework\Model\Context $context |
227
|
|
|
* @param \Magento\Framework\Registry $registry |
228
|
|
|
* @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory |
229
|
|
|
* @param \Magento\Framework\Api\AttributeValueFactory $customAttrFactory |
230
|
|
|
* @param \Magento\Payment\Helper\Data $paymentData |
231
|
|
|
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig |
232
|
|
|
* @param \Magento\Payment\Model\Method\Logger $logger |
233
|
|
|
* @param \Payone\Core\Helper\Toolkit $toolkitHelper |
234
|
|
|
* @param \Payone\Core\Helper\Shop $shopHelper |
235
|
|
|
* @param \Magento\Framework\Url $url |
236
|
|
|
* @param \Magento\Checkout\Model\Session $checkoutSession |
237
|
|
|
* @param \Payone\Core\Model\Api\Request\Debit $debitRequest |
238
|
|
|
* @param \Payone\Core\Model\Api\Request\Capture $captureRequest |
239
|
|
|
* @param \Payone\Core\Model\Api\Request\Authorization $authorizationRequest |
240
|
|
|
* @param \Payone\Core\Model\ResourceModel\SavedPaymentData $savedPaymentData |
241
|
|
|
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource |
242
|
|
|
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection |
243
|
|
|
* @param array $data |
244
|
|
|
*/ |
245
|
|
|
public function __construct( |
246
|
|
|
\Magento\Framework\Model\Context $context, |
|
|
|
|
247
|
|
|
\Magento\Framework\Registry $registry, |
|
|
|
|
248
|
|
|
\Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, |
|
|
|
|
249
|
|
|
\Magento\Framework\Api\AttributeValueFactory $customAttrFactory, |
|
|
|
|
250
|
|
|
\Magento\Payment\Helper\Data $paymentData, |
|
|
|
|
251
|
|
|
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, |
|
|
|
|
252
|
|
|
\Magento\Payment\Model\Method\Logger $logger, |
|
|
|
|
253
|
|
|
\Payone\Core\Helper\Toolkit $toolkitHelper, |
254
|
|
|
\Payone\Core\Helper\Shop $shopHelper, |
255
|
|
|
\Magento\Framework\Url $url, |
256
|
|
|
\Magento\Checkout\Model\Session $checkoutSession, |
257
|
|
|
\Payone\Core\Model\Api\Request\Debit $debitRequest, |
258
|
|
|
\Payone\Core\Model\Api\Request\Capture $captureRequest, |
259
|
|
|
\Payone\Core\Model\Api\Request\Authorization $authorizationRequest, |
260
|
|
|
\Payone\Core\Model\ResourceModel\SavedPaymentData $savedPaymentData, |
261
|
|
|
?\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, |
|
|
|
|
262
|
|
|
?\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, |
|
|
|
|
263
|
|
|
array $data = [] |
264
|
|
|
) { |
265
|
|
|
parent::__construct($context, $registry, $extensionFactory, $customAttrFactory, $paymentData, $scopeConfig, $logger, $resource, $resourceCollection, $data); |
266
|
|
|
$this->toolkitHelper = $toolkitHelper; |
267
|
|
|
$this->shopHelper = $shopHelper; |
268
|
|
|
$this->url = $url; |
269
|
|
|
$this->checkoutSession = $checkoutSession; |
270
|
|
|
$this->debitRequest = $debitRequest; |
271
|
|
|
$this->captureRequest = $captureRequest; |
272
|
|
|
$this->authorizationRequest = $authorizationRequest; |
273
|
|
|
$this->savedPaymentData = $savedPaymentData; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* Get instructions text from config |
278
|
|
|
* |
279
|
|
|
* @return string |
280
|
|
|
*/ |
281
|
|
|
public function getInstructions() |
282
|
|
|
{ |
283
|
|
|
return trim($this->getConfigData('instructions') ?? ''); // return description text |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* Payment action getter compatible with payment model |
288
|
|
|
* |
289
|
|
|
* @return string |
290
|
|
|
*/ |
291
|
|
|
public function getConfigPaymentAction() |
292
|
|
|
{ |
293
|
|
|
return AbstractMethod::ACTION_AUTHORIZE; // only create order |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
/** |
297
|
|
|
* Authorize payment abstract method |
298
|
|
|
* |
299
|
|
|
* @param InfoInterface $payment |
300
|
|
|
* @param float $amount |
301
|
|
|
* @return AbstractMethod |
302
|
|
|
*/ |
303
|
|
|
public function authorize(InfoInterface $payment, $amount) |
304
|
|
|
{ |
305
|
|
|
$oReturn = parent::authorize($payment, $amount); // execute Magento parent authorization |
306
|
|
|
if (!$this->_registry->registry('payone_creating_substitute_order')) { |
307
|
|
|
$this->sendPayoneAuthorization($payment, $amount); // send auth request to PAYONE |
308
|
|
|
} else { |
309
|
|
|
$payment->getOrder()->setCanSendNewEmailFlag(false); // dont send email now, will be sent on appointed |
310
|
|
|
} |
311
|
|
|
return $oReturn; // return magento parent auth value |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* Refund payment abstract method |
316
|
|
|
* |
317
|
|
|
* @param InfoInterface $payment |
318
|
|
|
* @param float $amount |
319
|
|
|
* @return AbstractMethod |
320
|
|
|
*/ |
321
|
|
|
public function refund(InfoInterface $payment, $amount) |
322
|
|
|
{ |
323
|
|
|
$oReturn = parent::refund($payment, $amount); // execute Magento parent refund |
324
|
|
|
$this->sendPayoneDebit($payment, $amount); // send debit request to PAYONE |
325
|
|
|
return $oReturn; // return magento parent refund value |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* Capture payment abstract method |
330
|
|
|
* |
331
|
|
|
* @param InfoInterface $payment |
332
|
|
|
* @param float $amount |
333
|
|
|
* @return AbstractMethod |
334
|
|
|
*/ |
335
|
|
|
public function capture(InfoInterface $payment, $amount) |
336
|
|
|
{ |
337
|
|
|
$oReturn = parent::capture($payment, $amount); // execute Magento parent capture |
338
|
|
|
if ($payment->getParentTransactionId()) {// does the order already have a transaction? |
339
|
|
|
$this->sendPayoneCapture($payment, $amount); // is probably admin invoice capture |
340
|
|
|
} else { |
341
|
|
|
$this->sendPayoneAuthorization($payment, $amount); // is probably frontend checkout capture |
342
|
|
|
} |
343
|
|
|
return $oReturn; // return magento parent capture value |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
/** |
347
|
|
|
* To check billing country is allowed for the payment method |
348
|
|
|
* Overrides the parent method with extended behaviour |
349
|
|
|
* |
350
|
|
|
* @param string $country |
351
|
|
|
* @return bool |
352
|
|
|
*/ |
353
|
|
|
public function canUseForCountry($country) |
354
|
|
|
{ |
355
|
|
|
$aAvailableCountries = []; |
356
|
|
|
$iAllowSpecific = $this->shopHelper->getConfigParam('allowspecific'); |
357
|
|
|
$sSpecificCountry = $this->shopHelper->getConfigParam('specificcountry'); |
358
|
|
|
if ($this->hasCustomConfig()) {// check for non-global configuration |
359
|
|
|
$iAllowSpecific = $this->getCustomConfigParam('allowspecific'); // only specific countries allowed? |
360
|
|
|
$sSpecificCountry = $this->getCustomConfigParam('specificcountry'); |
361
|
|
|
} |
362
|
|
|
if (!empty($sSpecificCountry)) { |
363
|
|
|
$aAvailableCountries = explode(',', $sSpecificCountry); |
364
|
|
|
} |
365
|
|
|
if ($iAllowSpecific == 1 && !in_array($country, $aAvailableCountries)) {// only specific but not included |
366
|
|
|
return false; // cant use for given country |
367
|
|
|
} |
368
|
|
|
return true; // can use for given country |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
/** |
372
|
|
|
* Returns if the current payment process is a express payment |
373
|
|
|
* |
374
|
|
|
* @return false |
375
|
|
|
*/ |
376
|
|
|
public function isExpressPayment() |
377
|
|
|
{ |
378
|
|
|
return false; |
379
|
|
|
} |
380
|
|
|
} |
381
|
|
|
|
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