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