Passed
Pull Request — master (#214)
by Florian
02:54
created

Configuration::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 4
dl 0
loc 10
rs 10
c 0
b 0
f 0
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 - 2017 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\Controller\Adminhtml\Config\Amazon;
28
29
use Magento\Backend\App\Action;
0 ignored issues
show
Bug introduced by
The type Magento\Backend\App\Action 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...
30
31
/**
32
 * Controller for Amazon get configuration script
33
 */
34
class Configuration extends Action
35
{
36
    /**
37
     * Result factory for get configuration script
38
     *
39
     * @var \Magento\Framework\Controller\Result\JsonFactory
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Controller\Result\JsonFactory 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
    protected $resultJsonFactory;
42
43
    /**
44
     * Object of getconfiguration request
45
     *
46
     * @var \Payone\Core\Model\Api\Request\Genericpayment\GetConfiguration
47
     */
48
    protected $getConfiguration;
49
50
    /**
51
     * Amazon Pay payment object
52
     *
53
     * @var \Payone\Core\Model\Methods\AmazonPay
54
     */
55
    protected $payment;
56
57
    /**
58
     * Constructor
59
     *
60
     * @param \Magento\Backend\App\Action\Context                            $context
61
     * @param \Magento\Framework\Controller\Result\JsonFactory               $resultJsonFactory
62
     * @param \Payone\Core\Model\Api\Request\Genericpayment\GetConfiguration $getConfiguration
63
     * @param \Payone\Core\Model\Methods\AmazonPay                           $payment
64
     */
65
    public function __construct(
66
        \Magento\Backend\App\Action\Context $context,
0 ignored issues
show
Bug introduced by
The type Magento\Backend\App\Action\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...
67
        \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
68
        \Payone\Core\Model\Api\Request\Genericpayment\GetConfiguration $getConfiguration,
69
        \Payone\Core\Model\Methods\AmazonPay $payment
70
    ) {
71
        parent::__construct($context);
72
        $this->resultJsonFactory = $resultJsonFactory;
73
        $this->getConfiguration = $getConfiguration;
74
        $this->payment = $payment;
75
    }
76
77
    /**
78
     * Return if the user has the needed rights to view this page
79
     *
80
     * @return bool
81
     */
82
    protected function _isAllowed()
83
    {
84
        return $this->_authorization->isAllowed('Payone_Core::payone_configuration_payment');
85
    }
86
87
    /**
88
     * Return amazon configuration data
89
     *
90
     * @return \Magento\Framework\Controller\Result\Json
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Controller\Result\Json 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...
91
     */
92
    public function execute()
93
    {
94
        $aData = false;
95
96
        $aResult = $this->getConfiguration->sendRequest($this->payment);
97
        if ($this->_isAllowed() && isset($aResult['status'])) {
98
            if ($aResult['status'] == 'OK') {
99
                $aData['success'] = true;
100
                $aData['client_id'] = $aResult['add_paydata[client_id]'];
101
                $aData['seller_id'] = $aResult['add_paydata[seller_id]'];
102
            } elseif ($aResult['status'] == 'ERROR') {
103
                $aData['success'] = false;
104
                $aData['errormessage'] = $aResult['errormessage'];
105
            }
106
        }
107
108
        /** @var \Magento\Framework\Controller\Result\Json $resultJson */
109
        $resultJson = $this->resultJsonFactory->create();
110
        return $resultJson->setData($aData);
111
    }
112
}
113