ConfigProvider::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 36
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 17
nc 1
nop 17
dl 0
loc 36
rs 9.7
c 0
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 - 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;
28
29
use Payone\Core\Model\Methods\BNPL\BNPLBase;
30
use Payone\Core\Model\Methods\PayoneMethod;
31
use Payone\Core\Model\PayoneConfig;
32
use Payone\Core\Model\Methods\OnlineBankTransfer\Eps;
33
use Payone\Core\Model\Methods\OnlineBankTransfer\Ideal;
34
35
/**
36
 * Extension for config provider to extend the javascript
37
 * data-array in the checkout
38
 */
39
class ConfigProvider extends \Magento\Payment\Model\CcGenericConfigProvider
0 ignored issues
show
Bug introduced by
The type Magento\Payment\Model\CcGenericConfigProvider 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...
40
{
41
    /**
42
     * Payment helper object
43
     *
44
     * @var \Magento\Payment\Helper\Data
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...
45
     */
46
    protected $dataHelper;
47
48
    /**
49
     * PAYONE country helper
50
     *
51
     * @var \Payone\Core\Helper\Country
52
     */
53
    protected $countryHelper;
54
55
    /**
56
     * PAYONE country helper
57
     *
58
     * @var \Payone\Core\Helper\Customer
59
     */
60
    protected $customerHelper;
61
62
    /**
63
     * PAYONE payment helper
64
     *
65
     * @var \Payone\Core\Helper\Payment
66
     */
67
    protected $paymentHelper;
68
69
    /**
70
     * PAYONE hosted iframe helper
71
     *
72
     * @var \Payone\Core\Helper\HostedIframe
73
     */
74
    protected $hostedIframeHelper;
75
76
    /**
77
     * PAYONE request helper
78
     *
79
     * @var \Payone\Core\Helper\Request
80
     */
81
    protected $requestHelper;
82
83
    /**
84
     * Escaper object
85
     *
86
     * @var \Magento\Framework\Escaper
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Escaper 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...
87
     */
88
    protected $escaper;
89
    
90
    /**
91
     * PAYONE request helper
92
     *
93
     * @var \Payone\Core\Helper\Consumerscore
94
     */
95
    protected $consumerscoreHelper;
96
97
    /**
98
     * Privacy declaration object
99
     *
100
     * @var \Payone\Core\Model\Api\Payolution\PrivacyDeclaration
101
     */
102
    protected $privacyDeclaration;
103
104
    /**
105
     * Checkout session
106
     *
107
     * @var \Magento\Checkout\Model\Session
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...
108
     */
109
    protected $checkoutSession;
110
111
    /**
112
     * Customer session
113
     *
114
     * @var \Magento\Customer\Model\Session
0 ignored issues
show
Bug introduced by
The type Magento\Customer\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...
115
     */
116
    protected $customerSession;
117
118
    /**
119
     * PAYONE shop helper
120
     *
121
     * @var \Payone\Core\Helper\Shop
122
     */
123
    protected $shopHelper;
124
125
    /**
126
     * Resource model for saved payment data
127
     *
128
     * @var \Payone\Core\Model\ResourceModel\SavedPaymentData
129
     */
130
    protected $savedPaymentData;
131
132
    /**
133
     * @var \Payone\Core\Model\Methods\Ratepay\Installment\Proxy
0 ignored issues
show
Bug introduced by
The type Payone\Core\Model\Method...tepay\Installment\Proxy 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...
134
     */
135
    protected $ratepayInstallment;
136
137
    /**
138
     * PAYONE toolkit helper
139
     *
140
     * @var \Payone\Core\Helper\Toolkit
141
     */
142
    protected $toolkitHelper;
143
144
    /**
145
     * PAYONE ratepay helper
146
     *
147
     * @var \Payone\Core\Helper\Ratepay
148
     */
149
    protected $ratepayHelper;
150
151
    /**
152
     * Constructor
153
     *
154
     * @param \Magento\Payment\Model\CcConfig                      $ccConfig
155
     * @param \Magento\Payment\Helper\Data                         $dataHelper
156
     * @param \Payone\Core\Helper\Country                          $countryHelper
157
     * @param \Payone\Core\Helper\Customer                         $customerHelper
158
     * @param \Payone\Core\Helper\Payment                          $paymentHelper
159
     * @param \Payone\Core\Helper\HostedIframe                     $hostedIframeHelper
160
     * @param \Payone\Core\Helper\Request                          $requestHelper
161
     * @param \Magento\Framework\Escaper                           $escaper
162
     * @param \Payone\Core\Helper\Consumerscore                    $consumerscoreHelper
163
     * @param \Payone\Core\Model\Api\Payolution\PrivacyDeclaration $privacyDeclaration
164
     * @param \Magento\Checkout\Model\Session                      $checkoutSession
165
     * @param \Magento\Customer\Model\Session                      $customerSession
166
     * @param \Payone\Core\Helper\Shop                             $shopHelper
167
     * @param \Payone\Core\Model\ResourceModel\SavedPaymentData    $savedPaymentData
168
     * @param \Payone\Core\Model\Methods\Ratepay\Installment\Proxy $ratepayInstallment
169
     * @param \Payone\Core\Helper\Toolkit                          $toolkitHelper
170
     * @param \Payone\Core\Helper\Ratepay                          $ratepayHelper
171
     */
172
    public function __construct(
173
        \Magento\Payment\Model\CcConfig $ccConfig,
0 ignored issues
show
Bug introduced by
The type Magento\Payment\Model\CcConfig 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...
174
        \Magento\Payment\Helper\Data $dataHelper,
175
        \Payone\Core\Helper\Country $countryHelper,
176
        \Payone\Core\Helper\Customer $customerHelper,
177
        \Payone\Core\Helper\Payment $paymentHelper,
178
        \Payone\Core\Helper\HostedIframe $hostedIframeHelper,
179
        \Payone\Core\Helper\Request $requestHelper,
180
        \Magento\Framework\Escaper $escaper,
181
        \Payone\Core\Helper\Consumerscore $consumerscoreHelper,
182
        \Payone\Core\Model\Api\Payolution\PrivacyDeclaration $privacyDeclaration,
183
        \Magento\Checkout\Model\Session $checkoutSession,
184
        \Magento\Customer\Model\Session $customerSession,
185
        \Payone\Core\Helper\Shop $shopHelper,
186
        \Payone\Core\Model\ResourceModel\SavedPaymentData $savedPaymentData,
187
        \Payone\Core\Model\Methods\Ratepay\Installment\Proxy $ratepayInstallment,
188
        \Payone\Core\Helper\Toolkit $toolkitHelper,
189
        \Payone\Core\Helper\Ratepay $ratepayHelper
190
    ) {
191
        parent::__construct($ccConfig, $dataHelper);
192
        $this->dataHelper = $dataHelper;
193
        $this->countryHelper = $countryHelper;
194
        $this->customerHelper = $customerHelper;
195
        $this->paymentHelper = $paymentHelper;
196
        $this->hostedIframeHelper = $hostedIframeHelper;
197
        $this->requestHelper = $requestHelper;
198
        $this->escaper = $escaper;
199
        $this->consumerscoreHelper = $consumerscoreHelper;
200
        $this->privacyDeclaration = $privacyDeclaration;
201
        $this->checkoutSession = $checkoutSession;
202
        $this->customerSession = $customerSession;
203
        $this->shopHelper = $shopHelper;
204
        $this->savedPaymentData = $savedPaymentData;
205
        $this->ratepayInstallment = $ratepayInstallment;
206
        $this->toolkitHelper = $toolkitHelper;
207
        $this->ratepayHelper = $ratepayHelper;
208
    }
209
210
    /**
211
     * Get the payment description text
212
     *
213
     * @param  PayoneMethod $sCode
214
     * @return string
215
     */
216
    protected function getInstructionByMethod($oMethodInstance)
217
    {
218
        return nl2br($this->escaper->escapeHtml($oMethodInstance->getInstructions()));
219
    }
220
221
    /**
222
     * Add payolution parameters to the config array
223
     *
224
     * @return array
225
     */
226
    protected function getPayolutionConfig()
227
    {
228
        return [
229
            'b2bMode' => [
230
                'invoice' => $this->requestHelper->getConfigParam('b2b_mode', PayoneConfig::METHOD_PAYOLUTION_INVOICE, 'payone_payment'),
231
            ],
232
            'privacyDeclaration' => [
233
                'invoice' => $this->privacyDeclaration->getPayolutionAcceptanceText(PayoneConfig::METHOD_PAYOLUTION_INVOICE),
234
                'debit' => $this->privacyDeclaration->getPayolutionAcceptanceText(PayoneConfig::METHOD_PAYOLUTION_DEBIT),
235
                'installment' => $this->privacyDeclaration->getPayolutionAcceptanceText(PayoneConfig::METHOD_PAYOLUTION_INSTALLMENT),
236
            ],
237
        ];
238
    }
239
240
    /**
241
     * Add payone parameters to the config array
242
     *
243
     * @return array
244
     */
245
    protected function getPayoneConfig()
246
    {
247
        return [
248
            'locale' => $this->shopHelper->getLocale(),
249
            'fullLocale' => $this->requestHelper->getConfigParam('code', 'locale', 'general'),
250
            'availableCardTypes' => $this->paymentHelper->getAvailableCreditcardTypes(),
251
            'availableApplePayTypes' => $this->paymentHelper->getAvailableApplePayTypes(),
252
            'fieldConfig' => $this->hostedIframeHelper->getHostedFieldConfig(),
253
            'sepaCountries' => $this->countryHelper->getEnabledCountries(PayoneConfig::METHOD_DEBIT),
254
            'hostedRequest' => $this->requestHelper->getHostedIframeRequest(),
255
            'mandateManagementActive' => $this->paymentHelper->isMandateManagementActive(),
256
            'checkCvc' => (bool)$this->paymentHelper->isCheckCvcActive(),
257
            'ccMinValidity' => $this->requestHelper->getConfigParam('min_validity_period', PayoneConfig::METHOD_CREDITCARD, 'payone_payment'),
258
            'requestBic' => (bool)$this->requestHelper->getConfigParam('request_bic', PayoneConfig::METHOD_DEBIT, 'payone_payment'),
259
            'validateBankCode' => (bool)$this->requestHelper->getConfigParam('check_bankaccount', PayoneConfig::METHOD_DEBIT, 'payone_payment'),
260
            'disableSafeInvoice' => (bool)$this->requestHelper->getConfigParam('disable_after_refusal', PayoneConfig::METHOD_SAFE_INVOICE, 'payone_payment'),
261
            'bankaccountcheckRequest' => $this->requestHelper->getBankaccountCheckRequest(),
262
            'bankCodeValidatedAndValid' => false,
263
            'blockedMessage' => $this->paymentHelper->getBankaccountCheckBlockedMessage(),
264
            'epsBankGroups' => Eps::getBankGroups(),
265
            'addresscheckEnabled' => (int)$this->requestHelper->getConfigParam('enabled', 'address_check', 'payone_protect'),
266
            'addresscheckBillingEnabled' => $this->requestHelper->getConfigParam('check_billing', 'address_check', 'payone_protect') == 'NO' ? 0 : 1,
267
            'addresscheckShippingEnabled' => $this->requestHelper->getConfigParam('check_shipping', 'address_check', 'payone_protect') == 'NO' ? 0 : 1,
268
            'addresscheckConfirmCorrection' => (int)$this->requestHelper->getConfigParam('confirm_address_correction', 'address_check', 'payone_protect'),
269
            'canShowPaymentHintText' => $this->consumerscoreHelper->canShowPaymentHintText(),
270
            'paymentHintText' => $this->requestHelper->getConfigParam('payment_hint_text', 'creditrating', 'payone_protect'),
271
            'canShowAgreementMessage' => $this->consumerscoreHelper->canShowAgreementMessage(),
272
            'agreementMessage' => $this->requestHelper->getConfigParam('agreement_message', 'creditrating', 'payone_protect'),
273
            'consumerScoreEnabledMethods' => $this->consumerscoreHelper->getConsumerscoreEnabledMethods(),
274
            'payolution' => $this->getPayolutionConfig(),
275
            'canceledPaymentMethod' => $this->getCanceledPaymentMethod(),
276
            'isError' => $this->checkoutSession->getPayoneIsError(),
277
            'orderDeferredExists' => (bool)version_compare($this->shopHelper->getMagentoVersion(), '2.1.0', '>='),
278
            'saveCCDataEnabled' => (bool)$this->requestHelper->getConfigParam('save_data_enabled', PayoneConfig::METHOD_CREDITCARD, 'payone_payment'),
279
            'savedPaymentData' => $this->savedPaymentData->getSavedPaymentData($this->checkoutSession->getQuote()->getCustomerId(), PayoneConfig::METHOD_CREDITCARD),
280
            'currency' => $this->requestHelper->getConfigParam('currency'),
281
            'klarnaTitles' => $this->paymentHelper->getKlarnaMethodTitles(),
282
            'storeName' => $this->shopHelper->getStoreName(),
283
            'ratepay' => $this->getRatepayConfig(),
284
            'ratepayRefreshed' => false,
285
            'bnpl' => $this->getBNPLConfig(),
286
        ];
287
    }
288
289
    /**
290
     * Returns the extended checkout-data array
291
     *
292
     * @return array
293
     */
294
    public function getConfig()
295
    {
296
        $config = parent::getConfig();
297
        $config = array_merge_recursive($config, [
298
            'payment' => [
299
                'payone' => $this->getPayoneConfig(),
300
            ],
301
        ]);
302
        foreach ($this->paymentHelper->getAvailablePaymentTypes() as $sCode) {
303
            $oMethodInstance = $this->dataHelper->getMethodInstance($sCode);
304
            if ($oMethodInstance instanceof PayoneMethod && $oMethodInstance->isAvailable()) {
305
                $config['payment']['payone'][$sCode] = $oMethodInstance->getFrontendConfig();
306
                $config['payment']['instructions'][$sCode] = $this->getInstructionByMethod($oMethodInstance);
307
            }
308
        }
309
        return $config;
310
    }
311
312
    /**
313
     * Get canceled payment method from session
314
     *
315
     * @return string|bool
316
     */
317
    protected function getCanceledPaymentMethod()
318
    {
319
        $sPaymentMethod = $this->checkoutSession->getPayoneCanceledPaymentMethod();
320
        $this->checkoutSession->unsPayoneCanceledPaymentMethod();
321
        if ($sPaymentMethod) {
322
            return $sPaymentMethod;
323
        }
324
        return false;
325
    }
326
327
    /**
328
     * Return ratepay config for all ratepay payment methods
329
     *
330
     * @return array
331
     */
332
    protected function getRatepayConfig()
333
    {
334
        $aReturn = $this->ratepayHelper->getRatepayConfig();
335
336
        if (isset($aReturn[PayoneConfig::METHOD_RATEPAY_INSTALLMENT])) {
337
            $aReturn[PayoneConfig::METHOD_RATEPAY_INSTALLMENT]['allowedMonths'] = $this->ratepayInstallment->getAllowedMonths();
338
        }
339
        return $aReturn;
340
    }
341
342
    /**
343
     * Reads payone UUID from session
344
     * Generates it if not yet set in session
345
     *
346
     * @return string
347
     * @throws \Exception
348
     */
349
    protected function getUUID()
350
    {
351
        $sUUID = $this->checkoutSession->getPayoneUUID();
352
        if (empty($sUUID)) {
353
            $sUUID = $this->toolkitHelper->generateUUIDv4();
354
            $this->checkoutSession->setPayoneUUID($sUUID);
355
        }
356
        return $sUUID;
357
    }
358
359
    /**
360
     * Check if at least 1 BNPL method is active
361
     *
362
     * @return bool
363
     */
364
    protected function isBNPLActive()
365
    {
366
        if ($this->paymentHelper->isPaymentMethodActive(PayoneConfig::METHOD_BNPL_INVOICE) === true ||
367
            $this->paymentHelper->isPaymentMethodActive(PayoneConfig::METHOD_BNPL_DEBIT) === true ||
368
            $this->paymentHelper->isPaymentMethodActive(PayoneConfig::METHOD_BNPL_INSTALLMENT) === true
369
        ) {
370
            return true;
371
        }
372
        return false;
373
    }
374
375
    /**
376
     * Returns config options for BNPL payment methods
377
     *
378
     * @return array|false
379
     */
380
    protected function getBNPLConfig()
381
    {
382
        if ($this->isBNPLActive()) {
383
            return [
384
                'environment' => [ // "t" for TEST, "p" for PROD
385
                    PayoneConfig::METHOD_BNPL_INVOICE => $this->requestHelper->getConfigParam('mode', PayoneConfig::METHOD_BNPL_INVOICE, 'payone_payment') == 'live' ? 'p' : 't',
386
                    PayoneConfig::METHOD_BNPL_INSTALLMENT => $this->requestHelper->getConfigParam('mode', PayoneConfig::METHOD_BNPL_INSTALLMENT, 'payone_payment') == 'live' ? 'p' : 't',
387
                    PayoneConfig::METHOD_BNPL_DEBIT => $this->requestHelper->getConfigParam('mode', PayoneConfig::METHOD_BNPL_DEBIT, 'payone_payment') == 'live' ? 'p' : 't',
388
                ],
389
                'mid' => [
390
                    PayoneConfig::METHOD_BNPL_INVOICE => $this->paymentHelper->getCustomConfigParam('mid', PayoneConfig::METHOD_BNPL_INVOICE),
391
                    PayoneConfig::METHOD_BNPL_INSTALLMENT => $this->paymentHelper->getCustomConfigParam('mid', PayoneConfig::METHOD_BNPL_INSTALLMENT),
392
                    PayoneConfig::METHOD_BNPL_DEBIT => $this->paymentHelper->getCustomConfigParam('mid', PayoneConfig::METHOD_BNPL_DEBIT),
393
                ],
394
                'differentAddressAllowed' => [
395
                    PayoneConfig::METHOD_BNPL_INVOICE => (bool)$this->requestHelper->getConfigParam('different_address_allowed', PayoneConfig::METHOD_BNPL_INVOICE, 'payment'),
396
                    PayoneConfig::METHOD_BNPL_INSTALLMENT => (bool)$this->requestHelper->getConfigParam('different_address_allowed', PayoneConfig::METHOD_BNPL_INSTALLMENT, 'payment'),
397
                    PayoneConfig::METHOD_BNPL_DEBIT => (bool)$this->requestHelper->getConfigParam('different_address_allowed', PayoneConfig::METHOD_BNPL_DEBIT, 'payment'),
398
                ],
399
                'payla_partner_id' => BNPLBase::BNPL_PARTNER_ID,
400
                'uuid' => $this->getUUID(),
401
            ];
402
        }
403
        return false;
404
    }
405
}
406