Issues (1092)

Controller/Paypal/Express.php (9 issues)

Labels
Severity
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\Controller\Paypal;
28
29
use Magento\Framework\Controller\ResultFactory;
0 ignored issues
show
The type Magento\Framework\Controller\ResultFactory 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 Magento\Quote\Model\Quote;
0 ignored issues
show
The type Magento\Quote\Model\Quote 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 Payone\Core\Model\PayoneConfig;
32
33
/**
34
 * Controller for PayPal Express initiation
35
 */
36
class Express extends \Magento\Framework\App\Action\Action
0 ignored issues
show
The type Magento\Framework\App\Action\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...
37
{
38
    /**
39
     * Checkout session
40
     *
41
     * @var \Magento\Checkout\Model\Session
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. 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...
42
     */
43
    protected $checkoutSession;
44
45
    /**
46
     * PAYONE request model
47
     *
48
     * @var \Payone\Core\Model\Api\Request\Genericpayment\PayPalExpress
49
     */
50
    protected $genericRequest;
51
52
    /**
53
     * PayPal payment model
54
     *
55
     * @var \Payone\Core\Model\Methods\Paypal
56
     */
57
    protected $paypalPayment;
58
59
    /**
60
     * Checkout helper
61
     *
62
     * @var \Magento\Checkout\Helper\Data
0 ignored issues
show
The type Magento\Checkout\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...
63
     */
64
    protected $checkoutHelper;
65
66
    /**
67
     * Customer session
68
     *
69
     * @var \Magento\Customer\Model\Session
0 ignored issues
show
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...
70
     */
71
    protected $customerSession;
72
73
    /**
74
     * PAYONE payment helper
75
     *
76
     * @var \Payone\Core\Helper\Payment
77
     */
78
    protected $paymentHelper;
79
80
    /**
81
     * Payone checkout helper
82
     *
83
     * @var \Payone\Core\Helper\Checkout
84
     */
85
    protected $payoneCheckoutHelper;
86
87
    /**
88
     * Constructor
89
     *
90
     * @param \Magento\Framework\App\Action\Context                       $context
91
     * @param \Magento\Checkout\Model\Session                             $checkoutSession
92
     * @param \Payone\Core\Model\Api\Request\Genericpayment\PayPalExpress $genericRequest
93
     * @param \Payone\Core\Model\Methods\Paypal                           $paypalPayment
94
     * @param \Magento\Checkout\Helper\Data                               $checkoutHelper
95
     * @param \Magento\Customer\Model\Session                             $customerSession
96
     * @param \Payone\Core\Helper\Payment                                 $paymentHelper
97
     * @param \Payone\Core\Helper\Checkout                                $payoneCheckoutHelper
98
     */
99
    public function __construct(
100
        \Magento\Framework\App\Action\Context $context,
0 ignored issues
show
The type Magento\Framework\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...
101
        \Magento\Checkout\Model\Session $checkoutSession,
102
        \Payone\Core\Model\Api\Request\Genericpayment\PayPalExpress $genericRequest,
103
        \Payone\Core\Model\Methods\Paypal $paypalPayment,
104
        \Magento\Checkout\Helper\Data $checkoutHelper,
105
        \Magento\Customer\Model\Session $customerSession,
106
        \Payone\Core\Helper\Payment $paymentHelper,
107
        \Payone\Core\Helper\Checkout $payoneCheckoutHelper
108
    ) {
109
        parent::__construct($context);
110
        $this->checkoutSession = $checkoutSession;
111
        $this->genericRequest = $genericRequest;
112
        $this->paypalPayment = $paypalPayment;
113
        $this->checkoutHelper = $checkoutHelper;
114
        $this->customerSession = $customerSession;
115
        $this->paymentHelper = $paymentHelper;
116
        $this->payoneCheckoutHelper = $payoneCheckoutHelper;
117
    }
118
119
    /**
120
     * Determine if a logged in customer is required for an express checkout
121
     * For example needed for virtual products ( download-products etc. )
122
     *
123
     * @param  Quote $oQuote
124
     * @return bool
125
     */
126
    protected function loginNeededForExpressCheckout(Quote $oQuote)
127
    {
128
        $oCustomer = $this->customerSession->getCustomerDataObject();
129
        if (!$oCustomer->getId()) {
130
            $sCheckoutMethod = $oQuote->getCheckoutMethod();
131
            if ((!$sCheckoutMethod || $sCheckoutMethod != \Magento\Checkout\Model\Type\Onepage::METHOD_REGISTER)
0 ignored issues
show
The type Magento\Checkout\Model\Type\Onepage 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...
132
                && !$this->checkoutHelper->isAllowedGuestCheckout($oQuote, $oQuote->getStoreId())
133
            ) {
134
                return true;
135
            }
136
        }
137
        return false;
138
    }
139
140
    /**
141
     * Redirect to payment-provider or to success page
142
     *
143
     * @return void
144
     */
145
    public function execute()
146
    {
147
        $oQuote = $this->checkoutSession->getQuote();
148
149
        if ($this->paymentHelper->isPayPalExpressActive() && $oQuote && $oQuote->hasItems()) {
150
            if ($this->loginNeededForExpressCheckout($oQuote)) {
151
                $this->messageManager->addNoticeMessage(__('Please sign in to check out.'));
0 ignored issues
show
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

151
                $this->messageManager->addNoticeMessage(/** @scrutinizer ignore-call */ __('Please sign in to check out.'));
Loading history...
152
153
                $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
154
                return $resultRedirect->setPath('customer/account/login');
155
            }
156
157
            $this->checkoutSession->setIsPayonePayPalExpress(true);
158
            $aResponse = $this->genericRequest->sendRequest($oQuote, $this->paypalPayment);
159
            $this->checkoutSession->unsIsPayonePayPalExpress();
160
            if ($aResponse['status'] == 'ERROR') {
161
                $this->messageManager->addError(__($aResponse['customermessage']));
162
163
                $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
164
                return $resultRedirect->setPath('checkout/cart');
165
            } elseif ($aResponse['status'] == 'REDIRECT') {
166
                $oPayment = $oQuote->getPayment();
167
                $oPayment->setMethod(PayoneConfig::METHOD_PAYPAL);
168
                $oQuote->setPayment($oPayment);
169
                $oQuote->save();
170
171
                $this->checkoutSession->setPayoneWorkorderId($aResponse['workorderid']);
172
                $this->checkoutSession->setPayoneQuoteComparisonString($this->payoneCheckoutHelper->getQuoteComparisonString($oQuote));
173
                $this->_redirect($aResponse['redirecturl']);
174
            }
175
            return;
176
        }
177
        $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
178
        return $resultRedirect->setPath('checkout/cart');
179
    }
180
}
181