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

PayPalExpress::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 7
dl 0
loc 11
rs 10
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\Api\Request\Genericpayment;
28
29
use Magento\Quote\Model\Quote;
0 ignored issues
show
Bug introduced by
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...
30
use Payone\Core\Model\Methods\PayoneMethod;
31
use Payone\Core\Model\Methods\PaypalV2;
32
use Payone\Core\Model\PayoneConfig;
33
34
/**
35
 * Class for the PAYONE Server API request genericpayment - "setexpresscheckout" and "getexpresscheckoutdetails"
36
 */
37
class PayPalExpress extends Base
38
{
39
    /**
40
     * Invoice generator
41
     *
42
     * @var \Payone\Core\Model\Api\Invoice
43
     */
44
    protected $invoiceGenerator;
45
46
    /**
47
     * Constructor
48
     *
49
     * @param \Payone\Core\Helper\Shop                $shopHelper
50
     * @param \Payone\Core\Helper\Environment         $environmentHelper
51
     * @param \Payone\Core\Helper\Api                 $apiHelper
52
     * @param \Payone\Core\Helper\Toolkit             $toolkitHelper
53
     * @param \Payone\Core\Model\ResourceModel\ApiLog $apiLog
54
     * @param \Payone\Core\Helper\Customer            $customerHelper
55
     * @param \Payone\Core\Model\Api\Invoice          $invoiceGenerator
56
     */
57
    public function __construct(
58
        \Payone\Core\Helper\Shop $shopHelper,
59
        \Payone\Core\Helper\Environment $environmentHelper,
60
        \Payone\Core\Helper\Api $apiHelper,
61
        \Payone\Core\Helper\Toolkit $toolkitHelper,
62
        \Payone\Core\Model\ResourceModel\ApiLog $apiLog,
63
        \Payone\Core\Helper\Customer $customerHelper,
64
        \Payone\Core\Model\Api\Invoice $invoiceGenerator
65
    ) {
66
        parent::__construct($shopHelper, $environmentHelper, $apiHelper, $toolkitHelper, $apiLog, $customerHelper);
67
        $this->invoiceGenerator = $invoiceGenerator;
68
    }
69
70
    /**
71
     * Send request to PAYONE Server-API with
72
     * request-type "genericpayment"
73
     *
74
     * @param Quote        $oQuote
75
     * @param PayoneMethod $oPayment
76
     * @param string|bool  $sWorkorderId
77
     * @return array Response
78
     */
79
    public function sendRequest(Quote $oQuote, PayoneMethod $oPayment, $sWorkorderId = false)
80
    {
81
        $this->addParameter('request', 'genericpayment');
82
        $this->addParameter('mode', $oPayment->getOperationMode());
83
        $this->addParameter('aid', $this->shopHelper->getConfigParam('aid')); // ID of PayOne Sub-Account
84
        $this->addParameter('clearingtype', $oPayment->getClearingtype());
85
        $this->addParameter('wallettype', $oPayment->getWallettype());
86
        $this->addParameter('narrative_text', 'Test');
87
88
        $this->addParameter('amount', number_format($this->apiHelper->getQuoteAmount($oQuote), 2, '.', '') * 100); // add price to request
89
        $this->addParameter('currency', $this->apiHelper->getCurrencyFromQuote($oQuote)); // add currency to request
90
91
        if ($sWorkorderId !== false) {
92
            $this->addParameter('workorderid', $sWorkorderId);
0 ignored issues
show
Bug introduced by
It seems like $sWorkorderId can also be of type true; however, parameter $sValue of Payone\Core\Model\Api\Request\Base::addParameter() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

92
            $this->addParameter('workorderid', /** @scrutinizer ignore-type */ $sWorkorderId);
Loading history...
93
            $this->addParameter('add_paydata[action]', 'getexpresscheckoutdetails');
94
        } else {
95
            $this->addParameter('add_paydata[action]', 'setexpresscheckout');
96
97
            if ($oPayment instanceof PaypalV2) {
98
                $this->addParameter('add_paydata[payment_action]', $oPayment->getAuthorizationMode() == PayoneConfig::REQUEST_TYPE_AUTHORIZATION ? 'Capture' : 'Authorize'); # Is either Capture (for Authorization call) or Authorize (for preauthorization call)
99
            }
100
        }
101
102
        if ($this->apiHelper->isInvoiceDataNeeded($oPayment)) {
103
            $this->invoiceGenerator->addProductInfo($this, $oQuote);
104
        }
105
106
        $this->addRedirectUrls($oPayment);
107
108
        return $this->send($oPayment);
109
    }
110
}
111