|
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 Magento\Framework\Exception\LocalizedException; |
|
|
|
|
|
|
30
|
|
|
use Payone\Core\Model\Exception\AuthorizationException; |
|
31
|
|
|
use Magento\Payment\Model\InfoInterface; |
|
|
|
|
|
|
32
|
|
|
use Magento\Sales\Model\Order; |
|
|
|
|
|
|
33
|
|
|
use Magento\Framework\DataObject; |
|
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Abstract model for all the PAYONE payment methods |
|
37
|
|
|
*/ |
|
38
|
|
|
abstract class PayoneMethod extends BaseMethod |
|
39
|
|
|
{ |
|
40
|
|
|
/** |
|
41
|
|
|
* Returns clearingtype |
|
42
|
|
|
* |
|
43
|
|
|
* @return string |
|
44
|
|
|
*/ |
|
45
|
|
|
public function getClearingtype() |
|
46
|
|
|
{ |
|
47
|
|
|
return $this->sClearingtype; |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Returns authorization-mode |
|
52
|
|
|
* preauthorization or authorization |
|
53
|
|
|
* |
|
54
|
|
|
* @return string |
|
55
|
|
|
*/ |
|
56
|
|
|
public function getAuthorizationMode() |
|
57
|
|
|
{ |
|
58
|
|
|
$sRequestType = $this->shopHelper->getConfigParam('request_type'); |
|
59
|
|
|
if ($this->hasCustomConfig()) { |
|
60
|
|
|
$sCustomRequestType = $this->getCustomConfigParam('request_type'); |
|
61
|
|
|
if (!empty($sCustomRequestType)) { |
|
62
|
|
|
$sRequestType = $sCustomRequestType; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
return $sRequestType; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Method handling the debit request and the response |
|
70
|
|
|
* |
|
71
|
|
|
* @param InfoInterface $payment |
|
72
|
|
|
* @param float $amount |
|
73
|
|
|
* @return void |
|
74
|
|
|
* @throws LocalizedException |
|
75
|
|
|
*/ |
|
76
|
|
|
protected function sendPayoneDebit(InfoInterface $payment, $amount) |
|
77
|
|
|
{ |
|
78
|
|
|
if ($this->shopHelper->getConfigParam('currency') == 'display' && $payment->getCreditmemo()) { |
|
79
|
|
|
$amount = $payment->getCreditmemo()->getGrandTotal(); // send display amount instead of base amount |
|
80
|
|
|
} |
|
81
|
|
|
$aResponse = $this->debitRequest->sendRequest($this, $payment, $amount); |
|
82
|
|
|
if (!$aResponse) { |
|
83
|
|
|
throw new LocalizedException(__('Unkown error')); |
|
|
|
|
|
|
84
|
|
|
} elseif ($aResponse['status'] == 'ERROR') { |
|
85
|
|
|
$this->checkoutSession->setPayoneDebitRequest($this->debitRequest->getParameters()); |
|
86
|
|
|
$this->checkoutSession->setPayoneDebitResponse($this->debitRequest->getResponse()); |
|
87
|
|
|
$this->checkoutSession->setPayoneDebitOrderId($this->debitRequest->getOrderId()); |
|
88
|
|
|
throw new LocalizedException(__($aResponse['errorcode'].' - '.$aResponse['customermessage'])); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Method handling the capture request and the response |
|
94
|
|
|
* |
|
95
|
|
|
* @param InfoInterface $payment |
|
96
|
|
|
* @param float $amount |
|
97
|
|
|
* @return void |
|
98
|
|
|
* @throws LocalizedException |
|
99
|
|
|
*/ |
|
100
|
|
|
protected function sendPayoneCapture(InfoInterface $payment, $amount) |
|
101
|
|
|
{ |
|
102
|
|
|
if ($this->shopHelper->getConfigParam('currency') == 'display' && $payment->getOrder()->hasInvoices()) { |
|
103
|
|
|
$oInvoice = $payment->getOrder()->getInvoiceCollection()->getLastItem(); |
|
104
|
|
|
$amount = $oInvoice->getGrandTotal(); // send display amount instead of base amount |
|
105
|
|
|
} |
|
106
|
|
|
$aResponse = $this->captureRequest->sendRequest($this, $payment, $amount); |
|
107
|
|
|
if (!$aResponse) {// response not existing |
|
108
|
|
|
throw new LocalizedException(__('Unkown error')); |
|
|
|
|
|
|
109
|
|
|
} elseif ($aResponse['status'] == 'ERROR') {// request returned an error |
|
110
|
|
|
throw new LocalizedException(__($aResponse['errorcode'].' - '.$aResponse['customermessage'])); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Removes status flag used during checkout process from session |
|
116
|
|
|
* |
|
117
|
|
|
* @return void |
|
118
|
|
|
*/ |
|
119
|
|
|
protected function unsetSessionStatusFlags() { |
|
120
|
|
|
$this->checkoutSession->unsPayoneRedirectUrl(); |
|
121
|
|
|
$this->checkoutSession->unsPayoneRedirectedPaymentMethod(); |
|
122
|
|
|
$this->checkoutSession->unsPayoneCanceledPaymentMethod(); |
|
123
|
|
|
$this->checkoutSession->unsPayoneIsError(); |
|
124
|
|
|
$this->checkoutSession->unsShowAmazonPendingNotice(); |
|
125
|
|
|
$this->checkoutSession->unsAmazonRetryAsync(); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Method handling the authorization request and the response |
|
130
|
|
|
* |
|
131
|
|
|
* @param InfoInterface $payment |
|
132
|
|
|
* @param float $amount |
|
133
|
|
|
* @return void |
|
134
|
|
|
* @throws LocalizedException |
|
135
|
|
|
*/ |
|
136
|
|
|
protected function sendPayoneAuthorization(InfoInterface $payment, $amount) |
|
137
|
|
|
{ |
|
138
|
|
|
$this->unsetSessionStatusFlags(); |
|
139
|
|
|
$oOrder = $payment->getOrder(); |
|
140
|
|
|
$oOrder->setCanSendNewEmailFlag(false); // dont send email now, will be sent on appointed |
|
141
|
|
|
|
|
142
|
|
|
if ($this->shopHelper->getConfigParam('currency') == 'display') { |
|
143
|
|
|
$amount = $oOrder->getTotalDue(); // send display amount instead of base amount |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
$this->checkoutSession->unsPayoneRedirectUrl(); // remove redirect url from session |
|
147
|
|
|
$this->checkoutSession->unsPayoneRedirectedPaymentMethod(); |
|
148
|
|
|
$this->checkoutSession->unsPayoneCanceledPaymentMethod(); |
|
149
|
|
|
$this->checkoutSession->unsPayoneIsError(); |
|
150
|
|
|
|
|
151
|
|
|
$aResponse = $this->authorizationRequest->sendRequest($this, $oOrder, $amount); |
|
152
|
|
|
$aResponse = $this->handleResponse($aResponse, $oOrder, $amount); |
|
153
|
|
|
if ($aResponse['status'] == 'ERROR') {// request returned an error |
|
154
|
|
|
throw new AuthorizationException(__($aResponse['errorcode'].' - '.$aResponse['customermessage']), $aResponse); |
|
|
|
|
|
|
155
|
|
|
} elseif ($aResponse['status'] == 'APPROVED' || $aResponse['status'] == 'REDIRECT') {// request successful |
|
156
|
|
|
$payment->setTransactionId($aResponse['txid']); |
|
157
|
|
|
$payment->setIsTransactionClosed(0); |
|
158
|
|
|
if ($aResponse['status'] == 'REDIRECT') {// user needs to be redirected to external payment page |
|
159
|
|
|
$this->checkoutSession->setPayoneRedirectUrl($aResponse['redirecturl']); |
|
160
|
|
|
$this->checkoutSession->setPayoneRedirectedPaymentMethod($this->getCode()); |
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* Perform certain actions with the response |
|
167
|
|
|
* Extension hook for certain payment methods |
|
168
|
|
|
* |
|
169
|
|
|
* @param array $aResponse |
|
170
|
|
|
* @param Order $oOrder |
|
171
|
|
|
* @param float $amount |
|
172
|
|
|
* @return array |
|
173
|
|
|
*/ |
|
174
|
|
|
protected function handleResponse($aResponse, Order $oOrder, $amount) |
|
175
|
|
|
{ |
|
176
|
|
|
$aAddData = $oOrder->getPayment()->getAdditionalInformation(); |
|
177
|
|
|
if (!empty($aAddData['iban'])) { |
|
178
|
|
|
$oOrder->getPayment()->setAdditionalInformation('iban', $this->toolkitHelper->maskIban($aAddData['iban'])); |
|
179
|
|
|
} |
|
180
|
|
|
return $aResponse; |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* Convert DataObject to needed array format |
|
185
|
|
|
* Hook for overriding in specific payment type class |
|
186
|
|
|
* |
|
187
|
|
|
* @param DataObject $data |
|
188
|
|
|
* @return array |
|
189
|
|
|
*/ |
|
190
|
|
|
protected function getPaymentStorageData(DataObject $data) |
|
191
|
|
|
{ |
|
192
|
|
|
return []; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* Check config and save payment data |
|
197
|
|
|
* |
|
198
|
|
|
* @param DataObject $data |
|
199
|
|
|
* @return void |
|
200
|
|
|
*/ |
|
201
|
|
|
protected function handlePaymentDataStorage(DataObject $data) |
|
202
|
|
|
{ |
|
203
|
|
|
if ((bool)$this->getCustomConfigParam('save_data_enabled') === true) { |
|
204
|
|
|
$aPaymentData = $this->getPaymentStorageData($data); |
|
205
|
|
|
$iCustomerId = $this->checkoutSession->getQuote()->getCustomerId(); |
|
206
|
|
|
if (!empty($aPaymentData) && $iCustomerId) { |
|
207
|
|
|
$this->savedPaymentData->addSavedPaymentData($iCustomerId, $this->getCode(), $aPaymentData); |
|
208
|
|
|
} |
|
209
|
|
|
} |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* Returns operationmode live or test for this payment method |
|
214
|
|
|
* |
|
215
|
|
|
* @return string |
|
216
|
|
|
*/ |
|
217
|
|
|
public function getOperationMode() |
|
218
|
|
|
{ |
|
219
|
|
|
return $this->getCustomConfigParam('mode'); |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
/** |
|
223
|
|
|
* Return parameters specific to this payment type |
|
224
|
|
|
* |
|
225
|
|
|
* @param Order $oOrder |
|
226
|
|
|
* @return array |
|
227
|
|
|
*/ |
|
228
|
|
|
public function getPaymentSpecificParameters(Order $oOrder) |
|
229
|
|
|
{ |
|
230
|
|
|
return []; // filled in child classes |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
* Return success url for redirect payment types |
|
235
|
|
|
* |
|
236
|
|
|
* @param Order $oOrder |
|
237
|
|
|
* @return string |
|
238
|
|
|
*/ |
|
239
|
|
|
public function getSuccessUrl(Order $oOrder = null) |
|
240
|
|
|
{ |
|
241
|
|
|
$sAddedParams = ''; |
|
242
|
|
|
if ($oOrder !== null) { |
|
243
|
|
|
$sAddedParams = '?incrementId='.$oOrder->getIncrementId(); |
|
244
|
|
|
} |
|
245
|
|
|
return $this->url->getUrl('payone/onepage/returned').$sAddedParams; |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
/** |
|
249
|
|
|
* Return cancel url for redirect payment types |
|
250
|
|
|
* |
|
251
|
|
|
* @return string |
|
252
|
|
|
*/ |
|
253
|
|
|
public function getCancelUrl() |
|
254
|
|
|
{ |
|
255
|
|
|
return $this->url->getUrl('payone/onepage/cancel'); |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
/** |
|
259
|
|
|
* Return error url for redirect payment types |
|
260
|
|
|
* |
|
261
|
|
|
* @return string |
|
262
|
|
|
*/ |
|
263
|
|
|
public function getErrorUrl() |
|
264
|
|
|
{ |
|
265
|
|
|
return $this->url->getUrl('payone/onepage/cancel?error=1'); |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
/** |
|
269
|
|
|
* Return if redirect urls have to be added to the authroization request |
|
270
|
|
|
* |
|
271
|
|
|
* @return bool |
|
272
|
|
|
*/ |
|
273
|
|
|
public function needsRedirectUrls() |
|
274
|
|
|
{ |
|
275
|
|
|
return $this->blNeedsRedirectUrls; |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
/** |
|
279
|
|
|
* Return if transaction_param has to be added to the authroization request |
|
280
|
|
|
* |
|
281
|
|
|
* @return bool |
|
282
|
|
|
*/ |
|
283
|
|
|
public function needsTransactionParam() |
|
284
|
|
|
{ |
|
285
|
|
|
return $this->blNeedsTransactionParam; |
|
286
|
|
|
} |
|
287
|
|
|
|
|
288
|
|
|
/** |
|
289
|
|
|
* Return if invoice data has to be added to the authroization request |
|
290
|
|
|
* |
|
291
|
|
|
* @return bool |
|
292
|
|
|
*/ |
|
293
|
|
|
public function needsProductInfo() |
|
294
|
|
|
{ |
|
295
|
|
|
return $this->blNeedsProductInfo; |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
|
|
299
|
|
|
/** |
|
300
|
|
|
* Return if bank data has to be added to the debit request |
|
301
|
|
|
* |
|
302
|
|
|
* @return bool |
|
303
|
|
|
*/ |
|
304
|
|
|
public function needsSepaDataOnDebit() |
|
305
|
|
|
{ |
|
306
|
|
|
return $this->blNeedsSepaDataOnDebit; |
|
307
|
|
|
} |
|
308
|
|
|
|
|
309
|
|
|
/** |
|
310
|
|
|
* Get config parameter for this payment type |
|
311
|
|
|
* |
|
312
|
|
|
* @param string $sParam |
|
313
|
|
|
* @param string $sStoreCode |
|
314
|
|
|
* @return string |
|
315
|
|
|
*/ |
|
316
|
|
|
public function getCustomConfigParam($sParam, $sStoreCode = null) |
|
317
|
|
|
{ |
|
318
|
|
|
if ($sStoreCode === null) { |
|
319
|
|
|
$sStoreCode = $this->getStoreCode(); |
|
320
|
|
|
} |
|
321
|
|
|
return $this->shopHelper->getConfigParam($sParam, $this->getCode(), 'payone_payment', $sStoreCode); |
|
322
|
|
|
} |
|
323
|
|
|
|
|
324
|
|
|
/** |
|
325
|
|
|
* Trys to retrieve the storecode from the order |
|
326
|
|
|
* |
|
327
|
|
|
* @return string|null |
|
328
|
|
|
*/ |
|
329
|
|
|
protected function getStoreCode() |
|
330
|
|
|
{ |
|
331
|
|
|
try { |
|
332
|
|
|
$oInfoInstance = $this->getInfoInstance(); |
|
333
|
|
|
if (empty($oInfoInstance)) { |
|
334
|
|
|
return null; |
|
335
|
|
|
} |
|
336
|
|
|
} catch (\Exception $oExc) { |
|
337
|
|
|
return null; |
|
338
|
|
|
} |
|
339
|
|
|
|
|
340
|
|
|
$oOrder = $oInfoInstance->getOrder(); |
|
341
|
|
|
if (empty($oOrder)) { |
|
342
|
|
|
$oOrder = $oInfoInstance->getQuote(); |
|
343
|
|
|
if (empty($oOrder)) { |
|
344
|
|
|
return null; |
|
345
|
|
|
} |
|
346
|
|
|
} |
|
347
|
|
|
|
|
348
|
|
|
$oStore = $oOrder->getStore(); |
|
349
|
|
|
if (empty($oStore)) { |
|
350
|
|
|
return null; |
|
351
|
|
|
} |
|
352
|
|
|
return $oStore->getCode(); |
|
353
|
|
|
} |
|
354
|
|
|
|
|
355
|
|
|
/** |
|
356
|
|
|
* Returns if global PAYONE config is used for this payment type |
|
357
|
|
|
* |
|
358
|
|
|
* @return bool |
|
359
|
|
|
*/ |
|
360
|
|
|
public function hasCustomConfig() |
|
361
|
|
|
{ |
|
362
|
|
|
if ($this->getCustomConfigParam('use_global') == '0') {// has non-global config |
|
363
|
|
|
return true; |
|
364
|
|
|
} |
|
365
|
|
|
return false; |
|
366
|
|
|
} |
|
367
|
|
|
|
|
368
|
|
|
/** |
|
369
|
|
|
* Return if this payment method is part of a group |
|
370
|
|
|
* |
|
371
|
|
|
* @return bool |
|
372
|
|
|
*/ |
|
373
|
|
|
public function isGroupMethod() |
|
374
|
|
|
{ |
|
375
|
|
|
if ($this->sGroupName === false) { |
|
376
|
|
|
return false; |
|
377
|
|
|
} |
|
378
|
|
|
return true; |
|
379
|
|
|
} |
|
380
|
|
|
|
|
381
|
|
|
/** |
|
382
|
|
|
* Returns group identifier |
|
383
|
|
|
* |
|
384
|
|
|
* @return string|bool |
|
385
|
|
|
*/ |
|
386
|
|
|
public function getGroupName() |
|
387
|
|
|
{ |
|
388
|
|
|
return $this->sGroupName; |
|
389
|
|
|
} |
|
390
|
|
|
|
|
391
|
|
|
/** |
|
392
|
|
|
* Returns group identifier |
|
393
|
|
|
* |
|
394
|
|
|
* @return string|bool |
|
395
|
|
|
*/ |
|
396
|
|
|
public function getSubType() |
|
397
|
|
|
{ |
|
398
|
|
|
return $this->sSubType; |
|
399
|
|
|
} |
|
400
|
|
|
|
|
401
|
|
|
/** |
|
402
|
|
|
* Return parameters specific to this payment sub type |
|
403
|
|
|
* |
|
404
|
|
|
* @param Order $oOrder |
|
405
|
|
|
* @return array |
|
406
|
|
|
*/ |
|
407
|
|
|
public function getSubTypeSpecificParameters(Order $oOrder) |
|
408
|
|
|
{ |
|
409
|
|
|
return []; // filled in child classes |
|
410
|
|
|
} |
|
411
|
|
|
|
|
412
|
|
|
/** |
|
413
|
|
|
* Formats the reference number if needed for this payment method |
|
414
|
|
|
* Needed for Paydirekt |
|
415
|
|
|
* |
|
416
|
|
|
* @param string $sRefNr |
|
417
|
|
|
* @return string |
|
418
|
|
|
*/ |
|
419
|
|
|
public function formatReferenceNumber($sRefNr) |
|
420
|
|
|
{ |
|
421
|
|
|
return $sRefNr; |
|
422
|
|
|
} |
|
423
|
|
|
|
|
424
|
|
|
/** |
|
425
|
|
|
* Return max length of narrative text |
|
426
|
|
|
* |
|
427
|
|
|
* @return int |
|
428
|
|
|
*/ |
|
429
|
|
|
public function getNarrativeTextMaxLength() |
|
430
|
|
|
{ |
|
431
|
|
|
return $this->iNarrativeTextMax; |
|
432
|
|
|
} |
|
433
|
|
|
} |
|
434
|
|
|
|
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