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 - 2021 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 Apple Pay payment method |
35
|
|
|
*/ |
36
|
|
|
class ApplePay extends PayoneMethod |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* Payment method code |
40
|
|
|
* |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
protected $_code = PayoneConfig::METHOD_APPLEPAY; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Clearingtype for PAYONE authorization request |
47
|
|
|
* |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
protected $sClearingtype = 'wlt'; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var \Payone\Core\Helper\ApplePay |
54
|
|
|
*/ |
55
|
|
|
protected $applePayHelper; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Mapping ApplePay cardtype to Payone cardtype |
59
|
|
|
* |
60
|
|
|
* @var array |
61
|
|
|
*/ |
62
|
|
|
protected $cardTypeMapping = [ |
63
|
|
|
'visa' => 'V', |
64
|
|
|
'mastercard' => 'M', |
65
|
|
|
'girocard' => 'G', |
66
|
|
|
]; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Constructor |
70
|
|
|
* |
71
|
|
|
* @param \Magento\Framework\Model\Context $context |
72
|
|
|
* @param \Magento\Framework\Registry $registry |
73
|
|
|
* @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory |
74
|
|
|
* @param \Magento\Framework\Api\AttributeValueFactory $customAttrFactory |
75
|
|
|
* @param \Magento\Payment\Helper\Data $paymentData |
76
|
|
|
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig |
77
|
|
|
* @param \Magento\Payment\Model\Method\Logger $logger |
78
|
|
|
* @param \Payone\Core\Helper\Toolkit $toolkitHelper |
79
|
|
|
* @param \Payone\Core\Helper\Shop $shopHelper |
80
|
|
|
* @param \Magento\Framework\Url $url |
81
|
|
|
* @param \Magento\Checkout\Model\Session $checkoutSession |
82
|
|
|
* @param \Payone\Core\Model\Api\Request\Debit $debitRequest |
83
|
|
|
* @param \Payone\Core\Model\Api\Request\Capture $captureRequest |
84
|
|
|
* @param \Payone\Core\Model\Api\Request\Authorization $authorizationRequest |
85
|
|
|
* @param \Payone\Core\Model\ResourceModel\SavedPaymentData $savedPaymentData |
86
|
|
|
* @param \Payone\Core\Helper\ApplePay $applePayHelper |
87
|
|
|
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource |
88
|
|
|
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection |
89
|
|
|
* @param array $data |
90
|
|
|
*/ |
91
|
|
|
public function __construct( |
92
|
|
|
\Magento\Framework\Model\Context $context, |
|
|
|
|
93
|
|
|
\Magento\Framework\Registry $registry, |
|
|
|
|
94
|
|
|
\Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, |
|
|
|
|
95
|
|
|
\Magento\Framework\Api\AttributeValueFactory $customAttrFactory, |
|
|
|
|
96
|
|
|
\Magento\Payment\Helper\Data $paymentData, |
|
|
|
|
97
|
|
|
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, |
|
|
|
|
98
|
|
|
\Magento\Payment\Model\Method\Logger $logger, |
|
|
|
|
99
|
|
|
\Payone\Core\Helper\Toolkit $toolkitHelper, |
100
|
|
|
\Payone\Core\Helper\Shop $shopHelper, |
101
|
|
|
\Magento\Framework\Url $url, |
|
|
|
|
102
|
|
|
\Magento\Checkout\Model\Session $checkoutSession, |
|
|
|
|
103
|
|
|
\Payone\Core\Model\Api\Request\Debit $debitRequest, |
104
|
|
|
\Payone\Core\Model\Api\Request\Capture $captureRequest, |
105
|
|
|
\Payone\Core\Model\Api\Request\Authorization $authorizationRequest, |
106
|
|
|
\Payone\Core\Model\ResourceModel\SavedPaymentData $savedPaymentData, |
107
|
|
|
\Payone\Core\Helper\ApplePay $applePayHelper, |
108
|
|
|
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, |
|
|
|
|
109
|
|
|
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, |
|
|
|
|
110
|
|
|
array $data = [] |
111
|
|
|
) { |
112
|
|
|
parent::__construct($context, $registry, $extensionFactory, $customAttrFactory, $paymentData, $scopeConfig, $logger, $toolkitHelper, $shopHelper, $url, $checkoutSession, $debitRequest, $captureRequest, $authorizationRequest, $savedPaymentData, $resource, $resourceCollection, $data); |
113
|
|
|
$this->applePayHelper = $applePayHelper; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Check whether payment method can be used |
118
|
|
|
* |
119
|
|
|
* @param \Magento\Quote\Api\Data\CartInterface|null $quote |
120
|
|
|
* @return bool |
121
|
|
|
*/ |
122
|
|
|
public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null) |
|
|
|
|
123
|
|
|
{ |
124
|
|
|
$blParentReturn = parent::isAvailable($quote); |
125
|
|
|
if ($blParentReturn === false) { |
126
|
|
|
return false; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
// dont show payment method when configuration is not complete |
130
|
|
|
if ($this->applePayHelper->isConfigurationComplete() === false) { |
131
|
|
|
return false; |
132
|
|
|
} |
133
|
|
|
return $blParentReturn; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Maps ApplePay cardtype to Payone cardtype |
138
|
|
|
* |
139
|
|
|
* @param array $aToken |
140
|
|
|
* @return string |
141
|
|
|
*/ |
142
|
|
|
protected function getPayoneCardType($aToken) |
143
|
|
|
{ |
144
|
|
|
$sCardType = "?"; |
145
|
|
|
if (isset($aToken['paymentMethod']['network']) && isset($this->cardTypeMapping[strtolower($aToken['paymentMethod']['network'])])) { |
146
|
|
|
$sCardType = $this->cardTypeMapping[strtolower($aToken['paymentMethod']['network'])]; |
147
|
|
|
} |
148
|
|
|
return $sCardType; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Return parameters specific to this payment type |
153
|
|
|
* |
154
|
|
|
* @param Order $oOrder |
155
|
|
|
* @return array |
156
|
|
|
*/ |
157
|
|
|
public function getPaymentSpecificParameters(Order $oOrder) |
158
|
|
|
{ |
159
|
|
|
$oInfoInstance = $this->getInfoInstance(); |
160
|
|
|
|
161
|
|
|
$sJsonToken = $oInfoInstance->getAdditionalInformation('token'); |
162
|
|
|
$aToken = json_decode($sJsonToken, true); |
163
|
|
|
if (empty($aToken) || !is_array($aToken)) { |
164
|
|
|
throw new \Exception("Apple Pay token is missing!"); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
$aParams = [ |
168
|
|
|
'wallettype' => 'APL', |
169
|
|
|
'api_version' => '3.11', |
170
|
|
|
'cardtype' => $this->getPayoneCardType($aToken), |
171
|
|
|
'add_paydata[paymentdata_token_data]' => $aToken['paymentData']['data'], |
172
|
|
|
'add_paydata[paymentdata_token_signature]' => $aToken['paymentData']['signature'], |
173
|
|
|
'add_paydata[paymentdata_token_version]' => $aToken['paymentData']['version'], |
174
|
|
|
'add_paydata[paymentdata_token_ephemeral_publickey]' => $aToken['paymentData']['header']['ephemeralPublicKey'], |
175
|
|
|
'add_paydata[paymentdata_token_publickey_hash]' => $aToken['paymentData']['header']['publicKeyHash'], |
176
|
|
|
'add_paydata[paymentdata_token_transaction_id]' => $aToken['paymentData']['header']['transactionId'], |
177
|
|
|
]; |
178
|
|
|
return $aParams; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Add the checkout-form-data to the checkout session |
183
|
|
|
* |
184
|
|
|
* @param DataObject $data |
185
|
|
|
* @return $this |
186
|
|
|
*/ |
187
|
|
|
public function assignData(DataObject $data) |
188
|
|
|
{ |
189
|
|
|
parent::assignData($data); |
190
|
|
|
|
191
|
|
|
$oInfoInstance = $this->getInfoInstance(); |
192
|
|
|
$oInfoInstance->setAdditionalInformation('token', $this->toolkitHelper->getAdditionalDataEntry($data, 'token')); |
193
|
|
|
|
194
|
|
|
return $this; |
195
|
|
|
} |
196
|
|
|
} |
197
|
|
|
|
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