|
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\Sales\Model\Order; |
|
|
|
|
|
|
31
|
|
|
use Magento\Framework\DataObject; |
|
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Model for creditcard payment method |
|
35
|
|
|
*/ |
|
36
|
|
|
class Creditcard extends PayoneMethod |
|
37
|
|
|
{ |
|
38
|
|
|
/** |
|
39
|
|
|
* Payment method code |
|
40
|
|
|
* |
|
41
|
|
|
* @var string |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $_code = PayoneConfig::METHOD_CREDITCARD; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Info instructions block path |
|
47
|
|
|
* |
|
48
|
|
|
* @var string |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $_infoBlockType = 'Payone\Core\Block\Info\Creditcard'; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Clearingtype for PAYONE authorization request |
|
54
|
|
|
* |
|
55
|
|
|
* @var string |
|
56
|
|
|
*/ |
|
57
|
|
|
protected $sClearingtype = 'cc'; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Determines if the redirect-parameters have to be added |
|
61
|
|
|
* to the authorization-request |
|
62
|
|
|
* |
|
63
|
|
|
* @var bool |
|
64
|
|
|
*/ |
|
65
|
|
|
protected $blNeedsRedirectUrls = true; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Keys that need to be assigned to the additionalinformation fields |
|
69
|
|
|
* |
|
70
|
|
|
* @var array |
|
71
|
|
|
*/ |
|
72
|
|
|
protected $aAssignKeys = [ |
|
73
|
|
|
'pseudocardpan', |
|
74
|
|
|
'truncatedcardpan', |
|
75
|
|
|
'cardtype', |
|
76
|
|
|
'cardexpiredate', |
|
77
|
|
|
'selectedData', |
|
78
|
|
|
'cardholder', |
|
79
|
|
|
|
|
80
|
|
|
]; |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @var \Payone\Core\Helper\Payment |
|
84
|
|
|
*/ |
|
85
|
|
|
protected $paymentHelper; |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Constructor |
|
89
|
|
|
* |
|
90
|
|
|
* @param \Magento\Framework\Model\Context $context |
|
91
|
|
|
* @param \Magento\Framework\Registry $registry |
|
92
|
|
|
* @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory |
|
93
|
|
|
* @param \Magento\Framework\Api\AttributeValueFactory $customAttrFactory |
|
94
|
|
|
* @param \Magento\Payment\Helper\Data $paymentData |
|
95
|
|
|
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig |
|
96
|
|
|
* @param \Magento\Payment\Model\Method\Logger $logger |
|
97
|
|
|
* @param \Payone\Core\Helper\Toolkit $toolkitHelper |
|
98
|
|
|
* @param \Payone\Core\Helper\Shop $shopHelper |
|
99
|
|
|
* @param \Magento\Framework\Url $url |
|
100
|
|
|
* @param \Magento\Checkout\Model\Session $checkoutSession |
|
101
|
|
|
* @param \Payone\Core\Model\Api\Request\Debit $debitRequest |
|
102
|
|
|
* @param \Payone\Core\Model\Api\Request\Capture $captureRequest |
|
103
|
|
|
* @param \Payone\Core\Model\Api\Request\Authorization $authorizationRequest |
|
104
|
|
|
* @param \Payone\Core\Model\ResourceModel\SavedPaymentData $savedPaymentData |
|
105
|
|
|
* @param \Payone\Core\Helper\Payment $paymentHelper |
|
106
|
|
|
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource |
|
107
|
|
|
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection |
|
108
|
|
|
* @param array $data |
|
109
|
|
|
*/ |
|
110
|
|
|
public function __construct( |
|
111
|
|
|
\Magento\Framework\Model\Context $context, |
|
|
|
|
|
|
112
|
|
|
\Magento\Framework\Registry $registry, |
|
|
|
|
|
|
113
|
|
|
\Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, |
|
|
|
|
|
|
114
|
|
|
\Magento\Framework\Api\AttributeValueFactory $customAttrFactory, |
|
|
|
|
|
|
115
|
|
|
\Magento\Payment\Helper\Data $paymentData, |
|
|
|
|
|
|
116
|
|
|
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, |
|
|
|
|
|
|
117
|
|
|
\Magento\Payment\Model\Method\Logger $logger, |
|
|
|
|
|
|
118
|
|
|
\Payone\Core\Helper\Toolkit $toolkitHelper, |
|
119
|
|
|
\Payone\Core\Helper\Shop $shopHelper, |
|
120
|
|
|
\Magento\Framework\Url $url, |
|
|
|
|
|
|
121
|
|
|
\Magento\Checkout\Model\Session $checkoutSession, |
|
|
|
|
|
|
122
|
|
|
\Payone\Core\Model\Api\Request\Debit $debitRequest, |
|
123
|
|
|
\Payone\Core\Model\Api\Request\Capture $captureRequest, |
|
124
|
|
|
\Payone\Core\Model\Api\Request\Authorization $authorizationRequest, |
|
125
|
|
|
\Payone\Core\Model\ResourceModel\SavedPaymentData $savedPaymentData, |
|
126
|
|
|
\Payone\Core\Helper\Payment $paymentHelper, |
|
127
|
|
|
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, |
|
|
|
|
|
|
128
|
|
|
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, |
|
|
|
|
|
|
129
|
|
|
array $data = [] |
|
130
|
|
|
) { |
|
131
|
|
|
parent::__construct($context, $registry, $extensionFactory, $customAttrFactory, $paymentData, $scopeConfig, $logger, $toolkitHelper, $shopHelper, $url, $checkoutSession, $debitRequest, $captureRequest, $authorizationRequest, $savedPaymentData, $resource, $resourceCollection, $data); |
|
132
|
|
|
$this->paymentHelper = $paymentHelper; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Check whether payment method can be used |
|
137
|
|
|
* |
|
138
|
|
|
* @param \Magento\Quote\Api\Data\CartInterface|null $quote |
|
139
|
|
|
* @return bool |
|
140
|
|
|
*/ |
|
141
|
|
|
public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null) |
|
|
|
|
|
|
142
|
|
|
{ |
|
143
|
|
|
$blParentReturn = parent::isAvailable($quote); |
|
144
|
|
|
if ($blParentReturn === false) { |
|
145
|
|
|
return false; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
// dont show payment method when configuration is not complete |
|
149
|
|
|
if (empty($this->paymentHelper->getAvailableCreditcardTypes())) { |
|
150
|
|
|
return false; |
|
151
|
|
|
} |
|
152
|
|
|
return $blParentReturn; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Return parameters specific to this payment type |
|
157
|
|
|
* |
|
158
|
|
|
* @param Order $oOrder |
|
159
|
|
|
* @return array |
|
160
|
|
|
*/ |
|
161
|
|
|
public function getPaymentSpecificParameters(Order $oOrder) |
|
162
|
|
|
{ |
|
163
|
|
|
$aReturn = ['pseudocardpan' => $this->getInfoInstance()->getAdditionalInformation('pseudocardpan')]; |
|
164
|
|
|
$sSelectedData = $this->getInfoInstance()->getAdditionalInformation('selectedData'); |
|
165
|
|
|
if (!empty($sSelectedData) && $sSelectedData != 'new') { |
|
166
|
|
|
$aReturn['pseudocardpan'] = $this->getInfoInstance()->getAdditionalInformation('selectedData'); |
|
167
|
|
|
} |
|
168
|
|
|
$aReturn['cardholder'] = $this->getInfoInstance()->getAdditionalInformation('cardholder'); |
|
169
|
|
|
return $aReturn; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* Add the checkout-form-data to the checkout session |
|
174
|
|
|
* |
|
175
|
|
|
* @param DataObject $data |
|
176
|
|
|
* @return $this |
|
177
|
|
|
*/ |
|
178
|
|
|
public function assignData(DataObject $data) |
|
179
|
|
|
{ |
|
180
|
|
|
parent::assignData($data); |
|
181
|
|
|
|
|
182
|
|
|
$oInfoInstance = $this->getInfoInstance(); |
|
183
|
|
|
foreach ($this->aAssignKeys as $sKey) { |
|
184
|
|
|
$sData = $this->toolkitHelper->getAdditionalDataEntry($data, $sKey); |
|
185
|
|
|
if ($sData) { |
|
186
|
|
|
$oInfoInstance->setAdditionalInformation($sKey, $sData); |
|
187
|
|
|
} |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
$aAddData = $data->getAdditionalData(); |
|
191
|
|
|
if (isset($aAddData['saveData']) && $aAddData['saveData'] == '1') { |
|
192
|
|
|
$this->handlePaymentDataStorage($data); |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
return $this; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* Add value to the payment storage data array |
|
200
|
|
|
* |
|
201
|
|
|
* @param array $aDest |
|
202
|
|
|
* @param array $aSource |
|
203
|
|
|
* @param string $sDestField |
|
204
|
|
|
* @param string $sSourceField |
|
205
|
|
|
* @return void |
|
206
|
|
|
*/ |
|
207
|
|
|
protected function addValueToArray(&$aDest, $aSource, $sDestField, $sSourceField) |
|
208
|
|
|
{ |
|
209
|
|
|
if (isset($aSource[$sSourceField])) { |
|
210
|
|
|
$aDest[$sDestField] = $aSource[$sSourceField]; |
|
211
|
|
|
} |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* Convert DataObject to needed array format |
|
216
|
|
|
* |
|
217
|
|
|
* @param DataObject $data |
|
218
|
|
|
* @return array |
|
219
|
|
|
*/ |
|
220
|
|
|
protected function getPaymentStorageData(DataObject $data) |
|
221
|
|
|
{ |
|
222
|
|
|
$aReturn = parent::getPaymentStorageData($data); |
|
223
|
|
|
$aAdditionalData = $data->getAdditionalData(); |
|
224
|
|
|
|
|
225
|
|
|
if (isset($aAdditionalData['pseudocardpan']) && isset($aAdditionalData['truncatedcardpan'])) { |
|
226
|
|
|
$this->addValueToArray($aReturn, $aAdditionalData, 'cardpan', 'pseudocardpan'); |
|
227
|
|
|
$this->addValueToArray($aReturn, $aAdditionalData, 'masked', 'truncatedcardpan'); |
|
228
|
|
|
$this->addValueToArray($aReturn, $aAdditionalData, 'cardholder', 'cardholder'); |
|
229
|
|
|
$this->addValueToArray($aReturn, $aAdditionalData, 'cardtype', 'cardtype'); |
|
230
|
|
|
$this->addValueToArray($aReturn, $aAdditionalData, 'cardexpiredate', 'cardexpiredate'); |
|
231
|
|
|
} |
|
232
|
|
|
return $aReturn; |
|
233
|
|
|
} |
|
234
|
|
|
} |
|
235
|
|
|
|
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