|
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 safe invoice payment method |
|
35
|
|
|
*/ |
|
36
|
|
|
class SafeInvoice extends PayoneMethod |
|
37
|
|
|
{ |
|
38
|
|
|
/** |
|
39
|
|
|
* Payment method code |
|
40
|
|
|
* |
|
41
|
|
|
* @var string |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $_code = PayoneConfig::METHOD_SAFE_INVOICE; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Clearingtype for PAYONE authorization request |
|
47
|
|
|
* |
|
48
|
|
|
* @var string |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $sClearingtype = 'rec'; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Determines if the invoice information has to be added |
|
54
|
|
|
* to the authorization-request |
|
55
|
|
|
* |
|
56
|
|
|
* @var bool |
|
57
|
|
|
*/ |
|
58
|
|
|
protected $blNeedsProductInfo = true; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Payment ban entity |
|
62
|
|
|
* |
|
63
|
|
|
* @var \Payone\Core\Model\ResourceModel\PaymentBan |
|
64
|
|
|
*/ |
|
65
|
|
|
protected $paymentBan; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Payment ban duration in hours |
|
69
|
|
|
* |
|
70
|
|
|
* @var int |
|
71
|
|
|
*/ |
|
72
|
|
|
protected $iBanDuration = 24; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Constructor |
|
76
|
|
|
* |
|
77
|
|
|
* @param \Magento\Framework\Model\Context $context |
|
78
|
|
|
* @param \Magento\Framework\Registry $registry |
|
79
|
|
|
* @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory |
|
80
|
|
|
* @param \Magento\Framework\Api\AttributeValueFactory $customAttrFactory |
|
81
|
|
|
* @param \Magento\Payment\Helper\Data $paymentData |
|
82
|
|
|
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig |
|
83
|
|
|
* @param \Magento\Payment\Model\Method\Logger $logger |
|
84
|
|
|
* @param \Payone\Core\Helper\Toolkit $toolkitHelper |
|
85
|
|
|
* @param \Payone\Core\Helper\Shop $shopHelper |
|
86
|
|
|
* @param \Magento\Framework\Url $url |
|
87
|
|
|
* @param \Magento\Checkout\Model\Session $checkoutSession |
|
88
|
|
|
* @param \Payone\Core\Model\Api\Request\Debit $debitRequest |
|
89
|
|
|
* @param \Payone\Core\Model\Api\Request\Capture $captureRequest |
|
90
|
|
|
* @param \Payone\Core\Model\Api\Request\Authorization $authorizationRequest |
|
91
|
|
|
* @param \Payone\Core\Model\ResourceModel\SavedPaymentData $savedPaymentData |
|
92
|
|
|
* @param \Payone\Core\Model\ResourceModel\PaymentBan $paymentBan |
|
93
|
|
|
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource |
|
94
|
|
|
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection |
|
95
|
|
|
* @param array $data |
|
96
|
|
|
*/ |
|
97
|
|
|
public function __construct( |
|
98
|
|
|
\Magento\Framework\Model\Context $context, |
|
|
|
|
|
|
99
|
|
|
\Magento\Framework\Registry $registry, |
|
|
|
|
|
|
100
|
|
|
\Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, |
|
|
|
|
|
|
101
|
|
|
\Magento\Framework\Api\AttributeValueFactory $customAttrFactory, |
|
|
|
|
|
|
102
|
|
|
\Magento\Payment\Helper\Data $paymentData, |
|
|
|
|
|
|
103
|
|
|
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, |
|
|
|
|
|
|
104
|
|
|
\Magento\Payment\Model\Method\Logger $logger, |
|
|
|
|
|
|
105
|
|
|
\Payone\Core\Helper\Toolkit $toolkitHelper, |
|
106
|
|
|
\Payone\Core\Helper\Shop $shopHelper, |
|
107
|
|
|
\Magento\Framework\Url $url, |
|
|
|
|
|
|
108
|
|
|
\Magento\Checkout\Model\Session $checkoutSession, |
|
|
|
|
|
|
109
|
|
|
\Payone\Core\Model\Api\Request\Debit $debitRequest, |
|
110
|
|
|
\Payone\Core\Model\Api\Request\Capture $captureRequest, |
|
111
|
|
|
\Payone\Core\Model\Api\Request\Authorization $authorizationRequest, |
|
112
|
|
|
\Payone\Core\Model\ResourceModel\SavedPaymentData $savedPaymentData, |
|
113
|
|
|
\Payone\Core\Model\ResourceModel\PaymentBan $paymentBan, |
|
114
|
|
|
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, |
|
|
|
|
|
|
115
|
|
|
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, |
|
|
|
|
|
|
116
|
|
|
array $data = [] |
|
117
|
|
|
) { |
|
118
|
|
|
parent::__construct($context, $registry, $extensionFactory, $customAttrFactory, $paymentData, $scopeConfig, $logger, $toolkitHelper, $shopHelper, $url, $checkoutSession, $debitRequest, $captureRequest, $authorizationRequest, $savedPaymentData, $resource, $resourceCollection, $data); |
|
119
|
|
|
$this->paymentBan = $paymentBan; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @param Order $oOrder |
|
124
|
|
|
* @return string|false |
|
125
|
|
|
*/ |
|
126
|
|
|
protected function getBirthday(Order $oOrder) |
|
127
|
|
|
{ |
|
128
|
|
|
$sDob = false; |
|
129
|
|
|
if (!empty($oOrder->getCustomerDob())) { |
|
130
|
|
|
$sDob = $oOrder->getCustomerDob(); |
|
131
|
|
|
} elseif (!empty($this->getInfoInstance()->getAdditionalInformation('dob'))) { |
|
132
|
|
|
$sDob = $this->getInfoInstance()->getAdditionalInformation('dob'); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
if (!empty($sDob)) { |
|
136
|
|
|
$iDobTime = strtotime($sDob); |
|
137
|
|
|
if ($iDobTime !== false) { |
|
138
|
|
|
$sDob = date('Ymd', $iDobTime); |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
return $sDob; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Return parameters specific to this payment type |
|
146
|
|
|
* |
|
147
|
|
|
* @param Order $oOrder |
|
148
|
|
|
* @return array |
|
149
|
|
|
*/ |
|
150
|
|
|
public function getPaymentSpecificParameters(Order $oOrder) |
|
151
|
|
|
{ |
|
152
|
|
|
$aParams = ['clearingsubtype' => 'POV']; |
|
153
|
|
|
|
|
154
|
|
|
$sDob = $this->getBirthday($oOrder); |
|
155
|
|
|
if ($sDob) { |
|
156
|
|
|
$aParams['birthday'] = $sDob; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
$sBusinessrelation = 'b2c'; |
|
160
|
|
|
if (!empty($oOrder->getBillingAddress()->getCompany())) { |
|
161
|
|
|
$sBusinessrelation = 'b2b'; |
|
162
|
|
|
} |
|
163
|
|
|
$aParams['businessrelation'] = $sBusinessrelation; |
|
164
|
|
|
|
|
165
|
|
|
return $aParams; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* Returns formatted birthday if possible |
|
170
|
|
|
* |
|
171
|
|
|
* @param DataObject $data |
|
172
|
|
|
* @return string|false |
|
173
|
|
|
*/ |
|
174
|
|
|
protected function getFormattedBirthday(DataObject $data) |
|
175
|
|
|
{ |
|
176
|
|
|
$sFormattedDob = false; |
|
177
|
|
|
|
|
178
|
|
|
$sBirthday = $this->toolkitHelper->getAdditionalDataEntry($data, 'birthday'); |
|
179
|
|
|
$sBirthmonth = $this->toolkitHelper->getAdditionalDataEntry($data, 'birthmonth'); |
|
180
|
|
|
$sBirthyear = $this->toolkitHelper->getAdditionalDataEntry($data, 'birthyear'); |
|
181
|
|
|
if ($sBirthday && $sBirthmonth && $sBirthyear) { |
|
182
|
|
|
$sFormattedDob = $sBirthyear.'-'.$sBirthmonth.'-'.$sBirthday; |
|
183
|
|
|
} |
|
184
|
|
|
return $sFormattedDob; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* Add the checkout-form-data to the checkout session |
|
189
|
|
|
* |
|
190
|
|
|
* @param DataObject $data |
|
191
|
|
|
* @return $this |
|
192
|
|
|
*/ |
|
193
|
|
|
public function assignData(DataObject $data) |
|
194
|
|
|
{ |
|
195
|
|
|
parent::assignData($data); |
|
196
|
|
|
|
|
197
|
|
|
$sFormattedDob = $this->getFormattedBirthday($data); |
|
198
|
|
|
if ($sFormattedDob !== false) { |
|
199
|
|
|
$oInfoInstance = $this->getInfoInstance(); |
|
200
|
|
|
$oInfoInstance->setAdditionalInformation('dob', $sFormattedDob); |
|
201
|
|
|
} |
|
202
|
|
|
return $this; |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* Perform certain actions with the response |
|
207
|
|
|
* |
|
208
|
|
|
* @param array $aResponse |
|
209
|
|
|
* @param Order $oOrder |
|
210
|
|
|
* @param float $amount |
|
211
|
|
|
* @return array |
|
212
|
|
|
*/ |
|
213
|
|
|
protected function handleResponse($aResponse, Order $oOrder, $amount) |
|
214
|
|
|
{ |
|
215
|
|
|
$aResponse = parent::handleResponse($aResponse, $oOrder, $amount); |
|
216
|
|
|
if (isset($aResponse['status']) && $aResponse['status'] == 'ERROR' |
|
217
|
|
|
&& isset($aResponse['errorcode']) && $aResponse['errorcode'] == '351' |
|
218
|
|
|
) { |
|
219
|
|
|
if (!empty($oOrder->getCustomerId())) { |
|
220
|
|
|
$this->paymentBan->addPaymentBan($this->getCode(), $oOrder->getCustomerId(), $this->iBanDuration); |
|
221
|
|
|
} else { // guest checkout |
|
222
|
|
|
$aBans = $this->checkoutSession->getPayonePaymentBans(); |
|
223
|
|
|
if (!$aBans) { |
|
224
|
|
|
$aBans = []; |
|
225
|
|
|
} |
|
226
|
|
|
$aBans[$this->getCode()] = $this->paymentBan->getBanEndDate($this->iBanDuration); |
|
227
|
|
|
$this->checkoutSession->setPayonePaymentBans($aBans); |
|
228
|
|
|
} |
|
229
|
|
|
} |
|
230
|
|
|
return $aResponse; |
|
231
|
|
|
} |
|
232
|
|
|
} |
|
233
|
|
|
|
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