Passed
Pull Request — master (#305)
by
unknown
04:03
created

Amazon   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 124
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 124
rs 10
c 1
b 0
f 0
wmc 11

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getCartUrl() 0 3 1
A getLoadReviewUrl() 0 3 1
A __construct() 0 9 1
A getClientId() 0 3 1
A getSellerId() 0 3 1
A getWidgetUrl() 0 3 1
A getErrorUrl() 0 3 1
A isInvalidPaymentTriggered() 0 6 2
A getOrderReferenceId() 0 3 1
A triggerInvalidPayment() 0 3 1
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\Block\Onepage;
28
29
use Magento\Framework\View\Element\Template;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\View\Element\Template 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
use Payone\Core\Model\PayoneConfig;
31
32
/**
33
 * Block class for Amazon Pay checkout
34
 */
35
class Amazon extends Template
36
{
37
    /**
38
     * Checkout session object
39
     *
40
     * @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...
41
     */
42
    protected $checkoutSession;
43
44
    /**
45
     * @var \Payone\Core\Helper\Payment
46
     */
47
    protected $paymentHelper;
48
49
    /**
50
     * Constructor
51
     *
52
     * @param \Magento\Checkout\Model\Session                  $checkoutSession
53
     * @param \Magento\Framework\View\Element\Template\Context $context
54
     * @param \Payone\Core\Helper\Payment                      $paymentHelper
55
     * @param array                                            $data
56
     */
57
    public function __construct(
58
        \Magento\Checkout\Model\Session $checkoutSession,
59
        \Magento\Framework\View\Element\Template\Context $context,
0 ignored issues
show
Bug introduced by
The type Magento\Framework\View\Element\Template\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...
60
        \Payone\Core\Helper\Payment $paymentHelper,
61
        array $data = []
62
    ) {
63
        parent::__construct($context, $data);
64
        $this->checkoutSession = $checkoutSession;
65
        $this->paymentHelper = $paymentHelper;
66
    }
67
68
    /**
69
     * Get Amazon client id from config
70
     *
71
     * @return string
72
     */
73
    public function getClientId()
74
    {
75
        return $this->paymentHelper->getConfigParam('client_id', PayoneConfig::METHOD_AMAZONPAY, 'payone_payment');
76
    }
77
78
    /**
79
     * Get Amazon seller id from config
80
     *
81
     * @return string
82
     */
83
    public function getSellerId()
84
    {
85
        return $this->paymentHelper->getConfigParam('seller_id', PayoneConfig::METHOD_AMAZONPAY, 'payone_payment');
86
    }
87
88
    /**
89
     * Get redirect url of the checkout controller
90
     *
91
     * @return string
92
     */
93
    public function getCartUrl()
94
    {
95
        return $this->_urlBuilder->getUrl("checkout/cart", ['_secure' => true]);
96
    }
97
98
    /**
99
     * Get url of the loadReview ajax controller
100
     *
101
     * @return string
102
     */
103
    public function getLoadReviewUrl()
104
    {
105
        return $this->_urlBuilder->getUrl("payone/amazon/loadReview", ['_secure' => true]);
106
    }
107
108
    /**
109
     * Returns error url
110
     *
111
     * @return string
112
     */
113
    public function getErrorUrl()
114
    {
115
        return $this->_urlBuilder->getUrl('payone/amazon/confirmOrderError');
116
    }
117
118
    /**
119
     * Get amazon widget url
120
     *
121
     * @return string
122
     */
123
    public function getWidgetUrl()
124
    {
125
        return $this->paymentHelper->getAmazonPayWidgetUrl();
126
    }
127
128
    /**
129
     * Check if request param invalidPayment is set
130
     *
131
     * @return bool
132
     */
133
    public function isInvalidPaymentTriggered()
134
    {
135
        if ($this->getRequest()->getParam('invalidPayment')) {
136
            return true;
137
        }
138
        return false;
139
    }
140
141
    /**
142
     * Returns amazon order reference id
143
     *
144
     * @return string
145
     */
146
    public function getOrderReferenceId()
147
    {
148
        return $this->checkoutSession->getAmazonReferenceId();
149
    }
150
151
    /**
152
     * Returns if invalidPayment javascript method has to be started after initialization
153
     *
154
     * @return bool
155
     */
156
    public function triggerInvalidPayment()
157
    {
158
        return !empty($this->checkoutSession->getTriggerInvalidPayment());
159
    }
160
}
161