Passed
Pull Request — master (#315)
by
unknown
03:23
created

StartSession::sendRequest()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 32
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 22
c 1
b 0
f 0
nc 4
nop 4
dl 0
loc 32
rs 9.568
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 - 2020 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
32
/**
33
 * Class for the PAYONE Server API request genericpayment - "start_session"
34
 */
35
class StartSession extends Base
36
{
37
    /**
38
     * Invoice generator
39
     *
40
     * @var \Payone\Core\Model\Api\Invoice
41
     */
42
    protected $invoiceGenerator;
43
44
    /**
45
     * Constructor
46
     *
47
     * @param \Payone\Core\Helper\Shop                $shopHelper
48
     * @param \Payone\Core\Helper\Environment         $environmentHelper
49
     * @param \Payone\Core\Helper\Api                 $apiHelper
50
     * @param \Payone\Core\Model\ResourceModel\ApiLog $apiLog
51
     * @param \Payone\Core\Helper\Customer            $customerHelper
52
     * @param \Payone\Core\Model\Api\Invoice          $invoiceGenerator
53
     */
54
    public function __construct(
55
        \Payone\Core\Helper\Shop $shopHelper,
56
        \Payone\Core\Helper\Environment $environmentHelper,
57
        \Payone\Core\Helper\Api $apiHelper,
58
        \Payone\Core\Model\ResourceModel\ApiLog $apiLog,
59
        \Payone\Core\Helper\Customer $customerHelper,
60
        \Payone\Core\Model\Api\Invoice $invoiceGenerator
61
    ) {
62
        parent::__construct($shopHelper, $environmentHelper, $apiHelper, $apiLog, $customerHelper);
63
        $this->customerHelper = $customerHelper;
64
        $this->invoiceGenerator = $invoiceGenerator;
65
    }
66
67
    /**
68
     * Send request to PAYONE Server-API with
69
     * request-type "genericpayment"
70
     *
71
     * @param Quote         $oQuote
72
     * @param PayoneMethod  $oPayment
73
     * @param double        $dShippingCosts
74
     * @param string        $sCustomerEmail
75
     * @return array Response
76
     */
77
    public function sendRequest(Quote $oQuote, PayoneMethod $oPayment, $dShippingCosts, $sCustomerEmail)
78
    {
79
        $this->addParameter('request', 'genericpayment');
80
        $this->addParameter('add_paydata[action]', 'start_session');
81
        $this->addParameter('api_version', '3.10');
82
        $this->addParameter('mode', $oPayment->getOperationMode());
83
        $this->addParameter('aid', $this->shopHelper->getConfigParam('aid')); // ID of PayOne Sub-Account
84
85
        $this->addParameter('amount', number_format($this->apiHelper->getQuoteAmount($oQuote), 2, '.', '') * 100); // add price to request
86
        $this->addParameter('currency', $this->apiHelper->getCurrencyFromQuote($oQuote)); // add currency to request
87
88
        $oBilling = $oQuote->getBillingAddress();
89
        $this->addAddress($oBilling);
90
        if ($oBilling->getCompany()) {
91
            $this->addParameter('add_paydata[organization_entity_type]', 'OTHER');
92
            $this->addParameter('add_paydata[organization_registry_id]', '');
93
        }
94
95
        $oShipping = $oQuote->getShippingAddress();
96
        if ($oShipping) {
97
            $this->addAddress($oShipping, true);
98
            $this->addParameter('add_paydata[shipping_email]', $sCustomerEmail);
99
            $this->addParameter('add_paydata[shipping_title]', '');
100
            $this->addParameter('add_paydata[shipping_telephonenumber]', '');
101
        }
102
103
        $this->addParameter('clearingtype', 'fnc');
104
        $this->addParameter('financingtype', $oPayment->getSubType());
105
106
        $this->invoiceGenerator->addProductInfo($this, $oQuote, false, false, $dShippingCosts);
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type array expected by parameter $aPositions of Payone\Core\Model\Api\Invoice::addProductInfo(). ( Ignorable by Annotation )

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

106
        $this->invoiceGenerator->addProductInfo($this, $oQuote, /** @scrutinizer ignore-type */ false, false, $dShippingCosts);
Loading history...
107
108
        return $this->send($oPayment);
109
    }
110
}
111