Issues (1092)

Model/Methods/Payolution/PayolutionBase.php (17 issues)

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 - 2017 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\Payolution;
28
29
use Payone\Core\Model\PayoneConfig;
30
use Magento\Sales\Model\Order;
0 ignored issues
show
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
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
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
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 Payolution methods
38
 */
39
class PayolutionBase extends PayoneMethod
40
{
41
    /* Payment method sub types */
42
    const METHOD_PAYOLUTION_SUBTYPE_INVOICE = 'PYV';
43
    const METHOD_PAYOLUTION_SUBTYPE_DEBIT = 'PYD';
44
    const METHOD_PAYOLUTION_SUBTYPE_INSTALLMENT = 'PYS';
45
46
    /**
47
     * Clearingtype for PAYONE authorization request
48
     *
49
     * @var string
50
     */
51
    protected $sClearingtype = 'fnc';
52
53
    /**
54
     * Payment method group identifier
55
     *
56
     * @var string
57
     */
58
    protected $sGroupName = PayoneConfig::METHOD_GROUP_PAYOLUTION;
59
60
    /**
61
     * Payment method long sub type
62
     *
63
     * @var string|bool
64
     */
65
    protected $sLongSubType = false;
66
67
    /**
68
     * Keys that need to be assigned to the additionalinformation fields
69
     *
70
     * @var array
71
     */
72
    protected $aAssignKeys = [
73
        'telephone',
74
        'b2bmode',
75
        'trade_registry_number',
76
        'company_uid',
77
        'dateofbirth'
78
    ];
79
80
    /**
81
     * PAYONE genericpayment pre_check request model
82
     *
83
     * @var \Payone\Core\Model\Api\Request\Genericpayment\PreCheck
84
     */
85
    protected $precheckRequest;
86
87
    /**
88
     * Info instructions block path
89
     *
90
     * @var string
91
     */
92
    protected $_infoBlockType = 'Payone\Core\Block\Info\ClearingReference';
93
94
    /**
95
     * Constructor
96
     *
97
     * @param \Magento\Framework\Model\Context                        $context
98
     * @param \Magento\Framework\Registry                             $registry
99
     * @param \Magento\Framework\Api\ExtensionAttributesFactory       $extensionFactory
100
     * @param \Magento\Framework\Api\AttributeValueFactory            $customAttrFactory
101
     * @param \Magento\Payment\Helper\Data                            $paymentData
102
     * @param \Magento\Framework\App\Config\ScopeConfigInterface      $scopeConfig
103
     * @param \Magento\Payment\Model\Method\Logger                    $logger
104
     * @param \Payone\Core\Helper\Toolkit                             $toolkitHelper
105
     * @param \Payone\Core\Helper\Shop                                $shopHelper
106
     * @param \Magento\Framework\Url                                  $url
107
     * @param \Magento\Checkout\Model\Session                         $checkoutSession
108
     * @param \Payone\Core\Model\Api\Request\Debit                    $debitRequest
109
     * @param \Payone\Core\Model\Api\Request\Capture                  $captureRequest
110
     * @param \Payone\Core\Model\Api\Request\Authorization            $authorizationRequest
111
     * @param \Payone\Core\Model\ResourceModel\SavedPaymentData       $savedPaymentData
112
     * @param \Payone\Core\Model\Api\Request\Genericpayment\PreCheck  $precheckRequest
113
     * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
114
     * @param \Magento\Framework\Data\Collection\AbstractDb           $resourceCollection
115
     * @param array                                                   $data
116
     */
117
    public function __construct(
118
        \Magento\Framework\Model\Context $context,
0 ignored issues
show
The type Magento\Framework\Model\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...
119
        \Magento\Framework\Registry $registry,
0 ignored issues
show
The type Magento\Framework\Registry 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...
120
        \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
0 ignored issues
show
The type Magento\Framework\Api\ExtensionAttributesFactory 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...
121
        \Magento\Framework\Api\AttributeValueFactory $customAttrFactory,
0 ignored issues
show
The type Magento\Framework\Api\AttributeValueFactory 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...
122
        \Magento\Payment\Helper\Data $paymentData,
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...
123
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
0 ignored issues
show
The type Magento\Framework\App\Config\ScopeConfigInterface 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...
124
        \Magento\Payment\Model\Method\Logger $logger,
0 ignored issues
show
The type Magento\Payment\Model\Method\Logger 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...
125
        \Payone\Core\Helper\Toolkit $toolkitHelper,
126
        \Payone\Core\Helper\Shop $shopHelper,
127
        \Magento\Framework\Url $url,
0 ignored issues
show
The type Magento\Framework\Url 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...
128
        \Magento\Checkout\Model\Session $checkoutSession,
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...
129
        \Payone\Core\Model\Api\Request\Debit $debitRequest,
130
        \Payone\Core\Model\Api\Request\Capture $captureRequest,
131
        \Payone\Core\Model\Api\Request\Authorization $authorizationRequest,
132
        \Payone\Core\Model\ResourceModel\SavedPaymentData $savedPaymentData,
133
        \Payone\Core\Model\Api\Request\Genericpayment\PreCheck $precheckRequest,
134
        ?\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
0 ignored issues
show
The type Magento\Framework\Model\...eModel\AbstractResource 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...
135
        ?\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
0 ignored issues
show
The type Magento\Framework\Data\Collection\AbstractDb 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...
136
        array $data = []
137
    ) {
138
        parent::__construct($context, $registry, $extensionFactory, $customAttrFactory, $paymentData, $scopeConfig, $logger, $toolkitHelper, $shopHelper, $url, $checkoutSession, $debitRequest, $captureRequest, $authorizationRequest, $savedPaymentData, $resource, $resourceCollection, $data);
139
        $this->precheckRequest = $precheckRequest;
140
    }
141
142
    /**
143
     * Return parameters specific to this payment type
144
     *
145
     * @param  Order $oOrder
146
     * @return array
147
     */
148
    public function getPaymentSpecificParameters(Order $oOrder)
149
    {
150
        $aBaseParams = [
151
            'financingtype' => $this->getSubType(),
152
            'api_version' => '3.10',
153
            'workorderid' => $this->getInfoInstance()->getAdditionalInformation('workorderid'),
154
        ];
155
156
        $sBirthday = $this->getInfoInstance()->getAdditionalInformation('dateofbirth');
157
        if ($sBirthday) {
158
            $aBaseParams['birthday'] = $sBirthday;
159
        }
160
161
        $blB2b = $this->getInfoInstance()->getAdditionalInformation('b2bmode');
162
        if ($blB2b == '1') {
163
            $aBaseParams['add_paydata[b2b]'] = 'yes';
164
165
            $sTradeRegistryNumber = $this->getInfoInstance()->getAdditionalInformation('trade_registry_number');
166
            if (!empty($sTradeRegistryNumber)) {
167
                $aBaseParams['add_paydata[company_trade_registry_number]'] = $sTradeRegistryNumber;
168
            }
169
            $sCompanyUid = $this->getInfoInstance()->getAdditionalInformation('company_uid');
170
            if (!empty($sCompanyUid)) {
171
                $aBaseParams['add_paydata[company_uid]'] = $sCompanyUid;
172
            }
173
        }
174
175
        $aSubTypeParams = $this->getSubTypeSpecificParameters($oOrder);
176
        $aParams = array_merge($aBaseParams, $aSubTypeParams);
177
        return $aParams;
178
    }
179
180
    /**
181
     * Method to trigger the Payone genericpayment request pre-check
182
     *
183
     * @param  float $dAmount
184
     * @return array
185
     * @throws LocalizedException
186
     */
187
    public function sendPayonePreCheck($dAmount)
188
    {
189
        $oQuote = $this->checkoutSession->getQuote();
190
        if ($this->shopHelper->getConfigParam('currency', 'global', 'payone_general', $oQuote->getStore()->getCode()) == 'display') {
191
            $dAmount = $oQuote->getGrandTotal(); // send display amount instead of base amount
192
        }
193
        $aResponse = $this->precheckRequest->sendRequest($this, $oQuote, $dAmount);
194
195
        if ($aResponse['status'] == 'ERROR') {// request returned an error
196
            throw new LocalizedException(__($aResponse['errorcode'].' - '.$aResponse['customermessage']));
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

196
            throw new LocalizedException(/** @scrutinizer ignore-call */ __($aResponse['errorcode'].' - '.$aResponse['customermessage']));
Loading history...
197
        } elseif ($aResponse['status'] == 'OK') {
198
            $this->getInfoInstance()->setAdditionalInformation('workorderid', $aResponse['workorderid']);
199
        }
200
        return $aResponse;
201
    }
202
203
    /**
204
     * Return long subtype
205
     *
206
     * @return string
207
     */
208
    public function getLongSubType()
209
    {
210
        return $this->sLongSubType;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->sLongSubType also could return the type boolean which is incompatible with the documented return type string.
Loading history...
211
    }
212
213
    /**
214
     * Add the checkout-form-data to the checkout session
215
     *
216
     * @param  DataObject $data
217
     * @return $this
218
     */
219
    public function assignData(DataObject $data)
220
    {
221
        parent::assignData($data);
222
223
        $oInfoInstance = $this->getInfoInstance();
224
        foreach ($this->aAssignKeys as $sKey) {
225
            $sData = $this->toolkitHelper->getAdditionalDataEntry($data, $sKey);
226
            if ($sData) {
227
                $oInfoInstance->setAdditionalInformation($sKey, $sData);
228
            }
229
        }
230
231
        return $this;
232
    }
233
}
234