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 - 2023 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\BNPL; |
||
28 | |||
29 | use Payone\Core\Model\PayoneConfig; |
||
30 | use Magento\Sales\Model\Order; |
||
0 ignored issues
–
show
|
|||
31 | use Magento\Payment\Model\InfoInterface; |
||
0 ignored issues
–
show
The type
Magento\Payment\Model\InfoInterface was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
32 | use Magento\Framework\Exception\LocalizedException; |
||
0 ignored issues
–
show
The type
Magento\Framework\Exception\LocalizedException was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
33 | use Payone\Core\Model\Methods\PayoneMethod; |
||
34 | use Magento\Framework\DataObject; |
||
0 ignored issues
–
show
The type
Magento\Framework\DataObject was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
35 | |||
36 | /** |
||
37 | * Base class for all BNPL methods |
||
38 | */ |
||
39 | class BNPLBase extends PayoneMethod |
||
40 | { |
||
41 | /* Payment method sub types */ |
||
42 | const METHOD_BNPL_SUBTYPE_INVOICE = 'PIV'; |
||
43 | const METHOD_BNPL_SUBTYPE_INSTALLMENT = 'PIN'; |
||
44 | const METHOD_BNPL_SUBTYPE_DEBIT = 'PDD'; |
||
45 | |||
46 | const BNPL_PARTNER_ID = 'e7yeryF2of8X'; |
||
47 | |||
48 | /** |
||
49 | * Clearingtype for PAYONE authorization request |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | protected $sClearingtype = 'fnc'; |
||
54 | |||
55 | /** |
||
56 | * Payment method group identifier |
||
57 | * |
||
58 | * @var string |
||
59 | */ |
||
60 | protected $sGroupName = PayoneConfig::METHOD_GROUP_BNPL; |
||
61 | |||
62 | /** |
||
63 | * Payment method long sub type |
||
64 | * |
||
65 | * @var string|bool |
||
66 | */ |
||
67 | protected $sLongSubType = false; |
||
68 | |||
69 | /** |
||
70 | * Determines if the invoice information has to be added |
||
71 | * to the authorization-request |
||
72 | * |
||
73 | * @var bool |
||
74 | */ |
||
75 | protected $blNeedsProductInfo = true; |
||
76 | |||
77 | /** |
||
78 | * Keys that need to be assigned to the additionalinformation fields |
||
79 | * |
||
80 | * @var array |
||
81 | */ |
||
82 | protected $aAssignKeys = [ |
||
83 | 'dateofbirth', |
||
84 | 'telephone', |
||
85 | 'iban', |
||
86 | 'installmentOption', |
||
87 | 'optionid', |
||
88 | 'vatid', |
||
89 | ]; |
||
90 | |||
91 | /** |
||
92 | * Available countries for BNPL payment usage |
||
93 | * |
||
94 | * @var string[] |
||
95 | */ |
||
96 | protected $aAvailableCountries = [ |
||
97 | 'DE', |
||
98 | 'AT', |
||
99 | ]; |
||
100 | |||
101 | /** |
||
102 | * Info instructions block path |
||
103 | * |
||
104 | * @var string |
||
105 | */ |
||
106 | protected $_infoBlockType = 'Payone\Core\Block\Info\BNPL'; |
||
107 | |||
108 | /** |
||
109 | * @var \Payone\Core\Helper\Api |
||
110 | */ |
||
111 | protected $apiHelper; |
||
112 | |||
113 | /** |
||
114 | * Constructor |
||
115 | * |
||
116 | * @param \Magento\Framework\Model\Context $context |
||
117 | * @param \Magento\Framework\Registry $registry |
||
118 | * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory |
||
119 | * @param \Magento\Framework\Api\AttributeValueFactory $customAttrFactory |
||
120 | * @param \Magento\Payment\Helper\Data $paymentData |
||
121 | * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig |
||
122 | * @param \Magento\Payment\Model\Method\Logger $logger |
||
123 | * @param \Payone\Core\Helper\Toolkit $toolkitHelper |
||
124 | * @param \Payone\Core\Helper\Shop $shopHelper |
||
125 | * @param \Magento\Framework\Url $url |
||
126 | * @param \Magento\Checkout\Model\Session $checkoutSession |
||
127 | * @param \Payone\Core\Model\Api\Request\Debit $debitRequest |
||
128 | * @param \Payone\Core\Model\Api\Request\Capture $captureRequest |
||
129 | * @param \Payone\Core\Model\Api\Request\Authorization $authorizationRequest |
||
130 | * @param \Payone\Core\Model\ResourceModel\SavedPaymentData $savedPaymentData |
||
131 | * @param \Payone\Core\Helper\Api $apiHelper |
||
132 | * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource |
||
133 | * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection |
||
134 | * @param array $data |
||
135 | */ |
||
136 | public function __construct( |
||
137 | \Magento\Framework\Model\Context $context, |
||
0 ignored issues
–
show
The type
Magento\Framework\Model\Context was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
138 | \Magento\Framework\Registry $registry, |
||
0 ignored issues
–
show
The type
Magento\Framework\Registry was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
139 | \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, |
||
0 ignored issues
–
show
The type
Magento\Framework\Api\ExtensionAttributesFactory was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
140 | \Magento\Framework\Api\AttributeValueFactory $customAttrFactory, |
||
0 ignored issues
–
show
The type
Magento\Framework\Api\AttributeValueFactory was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
141 | \Magento\Payment\Helper\Data $paymentData, |
||
0 ignored issues
–
show
The type
Magento\Payment\Helper\Data was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
142 | \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, |
||
0 ignored issues
–
show
The type
Magento\Framework\App\Config\ScopeConfigInterface was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
143 | \Magento\Payment\Model\Method\Logger $logger, |
||
0 ignored issues
–
show
The type
Magento\Payment\Model\Method\Logger was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
144 | \Payone\Core\Helper\Toolkit $toolkitHelper, |
||
145 | \Payone\Core\Helper\Shop $shopHelper, |
||
146 | \Magento\Framework\Url $url, |
||
0 ignored issues
–
show
The type
Magento\Framework\Url was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
147 | \Magento\Checkout\Model\Session $checkoutSession, |
||
0 ignored issues
–
show
The type
Magento\Checkout\Model\Session was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
148 | \Payone\Core\Model\Api\Request\Debit $debitRequest, |
||
149 | \Payone\Core\Model\Api\Request\Capture $captureRequest, |
||
150 | \Payone\Core\Model\Api\Request\Authorization $authorizationRequest, |
||
151 | \Payone\Core\Model\ResourceModel\SavedPaymentData $savedPaymentData, |
||
152 | \Payone\Core\Helper\Api $apiHelper, |
||
153 | ?\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, |
||
0 ignored issues
–
show
The type
Magento\Framework\Model\...eModel\AbstractResource was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
154 | ?\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, |
||
0 ignored issues
–
show
The type
Magento\Framework\Data\Collection\AbstractDb was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
155 | array $data = [] |
||
156 | ) { |
||
157 | parent::__construct($context, $registry, $extensionFactory, $customAttrFactory, $paymentData, $scopeConfig, $logger, $toolkitHelper, $shopHelper, $url, $checkoutSession, $debitRequest, $captureRequest, $authorizationRequest, $savedPaymentData, $resource, $resourceCollection, $data); |
||
158 | $this->apiHelper = $apiHelper; |
||
159 | } |
||
160 | |||
161 | /** |
||
162 | * Check whether payment method can be used |
||
163 | * |
||
164 | * @param \Magento\Quote\Api\Data\CartInterface|null $quote |
||
165 | * @return bool |
||
166 | */ |
||
167 | public function isAvailable(?\Magento\Quote\Api\Data\CartInterface $quote = null) |
||
0 ignored issues
–
show
The type
Magento\Quote\Api\Data\CartInterface was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
168 | { |
||
169 | $blParentReturn = parent::isAvailable($quote); |
||
170 | |||
171 | // BNPL payment types are only available for payment in Euro |
||
172 | if ($quote !== null && $this->apiHelper->getCurrencyFromQuote($quote) != "EUR") { |
||
173 | return false; |
||
174 | } |
||
175 | return $blParentReturn; |
||
176 | } |
||
177 | |||
178 | /** |
||
179 | * To check billing country is allowed for the payment method |
||
180 | * |
||
181 | * @param string $country |
||
182 | * @return bool |
||
183 | * @deprecated 100.2.0 |
||
184 | */ |
||
185 | public function canUseForCountry($country) |
||
186 | { |
||
187 | // BNPL payments are only available for DE and AT orders |
||
188 | if (in_array($country, $this->aAvailableCountries) === false) { |
||
189 | return false; |
||
190 | } |
||
191 | return true; |
||
192 | } |
||
193 | |||
194 | /** |
||
195 | * Returns device token |
||
196 | * |
||
197 | * @return string |
||
198 | */ |
||
199 | protected function getDeviceToken() |
||
200 | { |
||
201 | $sUuid = $this->checkoutSession->getPayoneUUID(); |
||
202 | $sMid = $this->shopHelper->getConfigParam('mid'); |
||
203 | $sCustomMid = $this->getCustomConfigParam('mid'); |
||
204 | if ($this->hasCustomConfig() && !empty($sCustomMid)) { |
||
205 | $sMid = $sCustomMid; |
||
206 | } |
||
207 | return self::BNPL_PARTNER_ID.'_'.$sMid.'_'.$sUuid; |
||
208 | } |
||
209 | |||
210 | /** |
||
211 | * @param Order $oOrder |
||
212 | * @return string|false |
||
213 | */ |
||
214 | protected function getBirthday(Order $oOrder) |
||
215 | { |
||
216 | $sDob = false; |
||
217 | if (!empty($oOrder->getCustomerDob())) { |
||
218 | $sDob = $oOrder->getCustomerDob(); |
||
219 | } elseif (!empty($this->getInfoInstance()->getAdditionalInformation('dateofbirth'))) { |
||
220 | $sDob = $this->getInfoInstance()->getAdditionalInformation('dateofbirth'); |
||
221 | } |
||
222 | |||
223 | if (!empty($sDob)) { |
||
224 | $iDobTime = strtotime($sDob); |
||
225 | if ($iDobTime !== false) { |
||
226 | $sDob = date('Ymd', $iDobTime); |
||
227 | } |
||
228 | } |
||
229 | return $sDob; |
||
230 | } |
||
231 | |||
232 | /** |
||
233 | * Return parameters specific to this payment type |
||
234 | * |
||
235 | * @param Order $oOrder |
||
236 | * @return array |
||
237 | */ |
||
238 | public function getPaymentSpecificParameters(Order $oOrder) |
||
239 | { |
||
240 | $oInfoInstance = $this->getInfoInstance(); |
||
241 | |||
242 | $sBusinessrelation = 'b2c'; |
||
243 | if (!empty($oOrder->getBillingAddress()->getCompany())) { |
||
244 | $sBusinessrelation = 'b2b'; |
||
245 | } |
||
246 | |||
247 | $aBaseParams = [ |
||
248 | 'financingtype' => $this->getSubType(), |
||
249 | 'add_paydata[device_token]' => $this->getDeviceToken(), |
||
250 | 'businessrelation' => $sBusinessrelation, |
||
251 | 'birthday' => $this->getBirthday($oOrder), |
||
252 | ]; |
||
253 | |||
254 | $sTelephone = $oInfoInstance->getAdditionalInformation('telephone'); |
||
255 | if (!empty($sTelephone)) { |
||
256 | $aBaseParams['telephonenumber'] = $sTelephone; |
||
257 | } |
||
258 | |||
259 | $sVatId = $oInfoInstance->getAdditionalInformation('vatid'); |
||
260 | if ($sBusinessrelation == 'b2b' && !empty($sVatId)) { |
||
261 | $aBaseParams['vatid'] = $sVatId; |
||
262 | } |
||
263 | |||
264 | $aSubTypeParams = $this->getSubTypeSpecificParameters($oOrder); |
||
265 | $aParams = array_merge($aBaseParams, $aSubTypeParams); |
||
266 | return $aParams; |
||
267 | } |
||
268 | |||
269 | /** |
||
270 | * Add the checkout-form-data to the checkout session |
||
271 | * |
||
272 | * @param DataObject $data |
||
273 | * @return $this |
||
274 | */ |
||
275 | public function assignData(DataObject $data) |
||
276 | { |
||
277 | parent::assignData($data); |
||
278 | |||
279 | $oInfoInstance = $this->getInfoInstance(); |
||
280 | foreach ($this->aAssignKeys as $sKey) { |
||
281 | $sData = $this->toolkitHelper->getAdditionalDataEntry($data, $sKey); |
||
282 | if ($sData) { |
||
283 | $oInfoInstance->setAdditionalInformation($sKey, $sData); |
||
284 | } |
||
285 | } |
||
286 | |||
287 | return $this; |
||
288 | } |
||
289 | |||
290 | /** |
||
291 | * Perform certain actions with the response |
||
292 | * |
||
293 | * @param array $aResponse |
||
294 | * @param Order $oOrder |
||
295 | * @param float $amount |
||
296 | * @return array |
||
297 | */ |
||
298 | protected function handleResponse($aResponse, Order $oOrder, $amount) |
||
299 | { |
||
300 | $aResponse = parent::handleResponse($aResponse, $oOrder, $amount); |
||
301 | if (isset($aResponse['status']) && $aResponse['status'] == 'ERROR' && isset($aResponse['errorcode']) && $aResponse['errorcode'] == '307') { |
||
302 | $aBans = $this->checkoutSession->getPayonePaymentBans(); |
||
303 | if (empty($aBans)) { |
||
304 | $aBans = []; |
||
305 | } |
||
306 | |||
307 | $sBannedUntil = date('Y-m-d H:i:s', (time() + (60 * 60 * 8))); |
||
308 | $aBans[PayoneConfig::METHOD_BNPL_DEBIT] = $sBannedUntil; |
||
309 | $aBans[PayoneConfig::METHOD_BNPL_INSTALLMENT] = $sBannedUntil; |
||
310 | $aBans[PayoneConfig::METHOD_BNPL_INVOICE] = $sBannedUntil; |
||
311 | $this->checkoutSession->setPayonePaymentBans($aBans); |
||
312 | } |
||
313 | return $aResponse; |
||
314 | } |
||
315 | } |
||
316 |
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