Issues (1092)

Service/V1/PayPal.php (5 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 - 2024 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\Service\V1;
28
29
use Payone\Core\Api\PayPalInterface;
30
use Payone\Core\Model\PayoneConfig;
31
use Magento\Checkout\Model\Type\Onepage;
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...
32
use Magento\Customer\Model\Group;
0 ignored issues
show
The type Magento\Customer\Model\Group 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...
33
34
/**
35
 * Web API model for the PAYONE PayPal express
36
 */
37
class PayPal implements PayPalInterface
38
{
39
    /**
40
     * Factory for the response object
41
     *
42
     * @var \Payone\Core\Api\Data\PayPalResponseInterfaceFactory
0 ignored issues
show
The type Payone\Core\Api\Data\Pay...esponseInterfaceFactory 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...
43
     */
44
    protected $responseFactory;
45
46
    /**
47
     * Checkout session
48
     *
49
     * @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...
50
     */
51
    protected $checkoutSession;
52
53
    /**
54
     * Request object
55
     *
56
     * @var \Payone\Core\Model\Api\Request\Genericpayment\PayPalExpress
57
     */
58
    protected $paypalRequest;
59
60
    /**
61
     * @var \Payone\Core\Helper\Checkout
62
     */
63
    protected $checkoutHelper;
64
65
    /**
66
     * @var \Magento\Payment\Helper\Data
0 ignored issues
show
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...
67
     */
68
    protected $dataHelper;
69
70
    /**
71
     * Constructor.
72
     *
73
     * @param \Payone\Core\Api\Data\PayPalResponseInterfaceFactory        $responseFactory
74
     * @param \Magento\Checkout\Model\Session                             $checkoutSession
75
     * @param \Payone\Core\Model\Api\Request\Genericpayment\PayPalExpress $paypalRequest
76
     * @param \Payone\Core\Helper\Checkout                                $checkoutHelper
77
     * @param \Magento\Payment\Helper\Data                                $dataHelper
78
     */
79
    public function __construct(
80
        \Payone\Core\Api\Data\PayPalResponseInterfaceFactory $responseFactory,
81
        \Magento\Checkout\Model\Session $checkoutSession,
82
        \Payone\Core\Model\Api\Request\Genericpayment\PayPalExpress $paypalRequest,
83
        \Payone\Core\Helper\Checkout $checkoutHelper,
84
        \Magento\Payment\Helper\Data $dataHelper
85
    ) {
86
        $this->responseFactory = $responseFactory;
87
        $this->checkoutSession = $checkoutSession;
88
        $this->paypalRequest = $paypalRequest;
89
        $this->checkoutHelper = $checkoutHelper;
90
        $this->dataHelper = $dataHelper;
91
    }
92
93
    /**
94
     * Trigger PayPal Express v2 process
95
     *
96
     * @param  string $cartId
97
     * @return \Payone\Core\Service\V1\Data\PayPalResponse
98
     */
99
    public function startPayPalExpress($cartId)
100
    {
101
        $blSuccess = false;
102
        $oResponse = $this->responseFactory->create();
103
104
        $oQuote = $this->checkoutSession->getQuote();
105
106
        $oPayment = $oQuote->getPayment();
107
        $oPayment->setMethod(PayoneConfig::METHOD_PAYPALV2);
108
109
        $oQuote->setPayment($oPayment);
110
        $oQuote->collectTotals();
111
        $oQuote->save();
112
113
        $oMethodInstance = $this->dataHelper->getMethodInstance(PayoneConfig::METHOD_PAYPALV2);
114
        $oMethodInstance->setMethodInstance($oQuote->getPayment());
115
116
        $aResponse = $this->paypalRequest->sendRequest($oQuote, $oMethodInstance);
117
        if (isset($aResponse['status'], $aResponse['workorderid'], $aResponse['add_paydata[orderId]']) && $aResponse['status'] == 'REDIRECT') {
118
            $blSuccess = true;
119
120
            $oResponse->setData('orderId', $aResponse['add_paydata[orderId]']);
121
122
            if (!empty($aResponse['workorderid'])) {
123
                $this->checkoutSession->setIsPayonePayPalExpress(true);
124
                $this->checkoutSession->setPayoneWorkorderId($aResponse['workorderid']);
125
                $this->checkoutSession->setPayoneQuoteComparisonString($this->checkoutHelper->getQuoteComparisonString($oQuote));
126
            }
127
        }
128
129
        if (isset($aResponse['status'], $aResponse['customermessage']) && $aResponse['status'] == 'ERROR') {
130
            $oResponse->setData('errormessage', $aResponse['customermessage']);
131
        }
132
133
        $oResponse->setData('success', $blSuccess);
134
        return $oResponse;
135
    }
136
}
137