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

KlarnaBase   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 29
dl 0
loc 95
rs 10
c 1
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A assignData() 0 8 1
A getPaymentSpecificParameters() 0 23 3
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\Methods\Klarna;
28
29
use Payone\Core\Model\PayoneConfig;
30
use Magento\Sales\Model\Order;
0 ignored issues
show
Bug introduced by
The type Magento\Sales\Model\Order 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 Magento\Payment\Model\InfoInterface;
0 ignored issues
show
Bug introduced by
The type Magento\Payment\Model\InfoInterface 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\Framework\Exception\LocalizedException;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Exception\LocalizedException 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
use Payone\Core\Model\Methods\PayoneMethod;
34
use Magento\Framework\DataObject;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\DataObject 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...
35
36
/**
37
 * Base class for all Klarna methods
38
 */
39
class KlarnaBase extends PayoneMethod
40
{
41
    /* Payment method sub types */
42
    const METHOD_KLARNA_SUBTYPE_INVOICE = 'KIV';
43
    const METHOD_KLARNA_SUBTYPE_DEBIT = 'KDD';
44
    const METHOD_KLARNA_SUBTYPE_INSTALLMENT = 'KIS';
45
46
    /**
47
     * Payment method code for pseudo-payment-type Klarna
48
     *
49
     * @var string
50
     */
51
    protected $_code = PayoneConfig::METHOD_KLARNA_BASE;
52
53
    /**
54
     * Clearingtype for PAYONE authorization request
55
     *
56
     * @var string
57
     */
58
    protected $sClearingtype = 'fnc';
59
60
    /**
61
     * Payment method group identifier
62
     *
63
     * @var string
64
     */
65
    protected $sGroupName = PayoneConfig::METHOD_GROUP_KLARNA;
66
67
    /**
68
     * Payment method long sub type
69
     *
70
     * @var string|bool
71
     */
72
    protected $sLongSubType = false;
73
74
    /**
75
     * Determines if the redirect-parameters have to be added
76
     * to the authorization-request
77
     *
78
     * @var bool
79
     */
80
    protected $blNeedsRedirectUrls = true;
81
82
    /**
83
     * Info instructions block path
84
     *
85
     * @var string
86
     */
87
    protected $_infoBlockType = 'Payone\Core\Block\Info\ClearingReference';
88
89
    /**
90
     * Return parameters specific to this payment type
91
     *
92
     * @param  Order $oOrder
93
     * @return array
94
     */
95
    public function getPaymentSpecificParameters(Order $oOrder)
96
    {
97
        $aBaseParams = [
98
            'financingtype' => $this->getSubType(),
99
            'add_paydata[authorization_token]' => $this->getInfoInstance()->getAdditionalInformation('authorization_token'),
100
        ];
101
102
        $oBilling = $oOrder->getBillingAddress();
103
        if ($oBilling->getCompany()) {
104
            $aBaseParams['add_paydata[organization_entity_type]'] = 'OTHER';
105
            $aBaseParams['add_paydata[organization_registry_id]'] = '';
106
        }
107
108
        $oShipping = $oOrder->getShippingAddress();
109
        if ($oShipping) {
110
            $aBaseParams['add_paydata[shipping_email]'] = $oOrder->getCustomerEmail();
111
            $aBaseParams['add_paydata[shipping_title]'] = '';
112
            $aBaseParams['add_paydata[shipping_telephonenumber]'] = '';
113
        }
114
115
        $aSubTypeParams = $this->getSubTypeSpecificParameters($oOrder);
116
        $aParams = array_merge($aBaseParams, $aSubTypeParams);
117
        return $aParams;
118
    }
119
120
    /**
121
     * Add the checkout-form-data to the checkout session
122
     *
123
     * @param  DataObject $data
124
     * @return $this
125
     */
126
    public function assignData(DataObject $data)
127
    {
128
        parent::assignData($data);
129
130
        $oInfoInstance = $this->getInfoInstance();
131
        $oInfoInstance->setAdditionalInformation('authorization_token', $this->toolkitHelper->getAdditionalDataEntry($data, 'authorization_token'));
132
133
        return $this;
134
    }
135
}
136