Passed
Pull Request — master (#396)
by
unknown
02:33
created

ApplePay::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 19
dl 0
loc 23
rs 10
c 1
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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
Bug introduced by
The type Magento\Sales\Model\Order 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
use Magento\Framework\DataObject;
0 ignored issues
show
Bug introduced by
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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

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
     * @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,
0 ignored issues
show
Bug introduced by
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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
93
        \Magento\Framework\Registry $registry,
0 ignored issues
show
Bug introduced by
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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
94
        \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
0 ignored issues
show
Bug introduced by
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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
95
        \Magento\Framework\Api\AttributeValueFactory $customAttrFactory,
0 ignored issues
show
Bug introduced by
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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
96
        \Magento\Payment\Helper\Data $paymentData,
0 ignored issues
show
Bug introduced by
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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
97
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
0 ignored issues
show
Bug introduced by
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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
98
        \Magento\Payment\Model\Method\Logger $logger,
0 ignored issues
show
Bug introduced by
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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
99
        \Payone\Core\Helper\Toolkit $toolkitHelper,
100
        \Payone\Core\Helper\Shop $shopHelper,
101
        \Magento\Framework\Url $url,
0 ignored issues
show
Bug introduced by
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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
102
        \Magento\Checkout\Model\Session $checkoutSession,
0 ignored issues
show
Bug introduced by
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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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,
0 ignored issues
show
Bug introduced by
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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
109
        \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
0 ignored issues
show
Bug introduced by
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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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)
0 ignored issues
show
Bug introduced by
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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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