Completed
Push — master ( 9097d5...0ce82e )
by Florian
06:13
created

BaseMethod::getConfigPaymentAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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\Methods;
28
29
use Payone\Core\Model\PayoneConfig;
30
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...
31
use Magento\Payment\Model\Method\AbstractMethod;
0 ignored issues
show
Bug introduced by
The type Magento\Payment\Model\Method\AbstractMethod 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
33
/**
34
 * Abstract model for all the PAYONE payment methods
35
 *
36
 * @category  Payone
37
 * @package   Payone_Magento2_Plugin
38
 * @author    FATCHIP GmbH <[email protected]>
39
 * @copyright 2003 - 2016 Payone GmbH
40
 * @license   <http://www.gnu.org/licenses/> GNU Lesser General Public License
41
 * @link      http://www.payone.de
42
 */
43
abstract class BaseMethod extends AbstractMethod
44
{
45
    /**
46
     * Info instructions block path
47
     *
48
     * @var string
49
     */
50
    protected $_infoBlockType = 'Payone\Core\Block\Info\Basic';
51
52
    /**
53
     * Form block path
54
     *
55
     * @var string
56
     */
57
    protected $_formBlockType = 'Payone\Core\Block\Form\Base';
58
59
    /**
60
     * Availability option
61
     *
62
     * @var bool
63
     */
64
    protected $_isOffline = false;
65
66
    /**
67
     * Payment Method feature
68
     *
69
     * @var bool
70
     */
71
    protected $_canAuthorize = true;
72
73
    /**
74
     * Determines if payment type can use refund mechanism
75
     *
76
     * @var bool
77
     */
78
    protected $_canRefund = true;
79
80
    /**
81
     * Determines if payment type can use capture mechanism
82
     *
83
     * @var bool
84
     */
85
    protected $_canCapture = true;
86
87
    /**
88
     * Determines if payment type can use partial captures
89
     * Is true for all PAYONE Payment Methods except Barzahlen
90
     *
91
     * @var bool
92
     */
93
    protected $_canCapturePartial = true;
94
95
    /**
96
     * Determines if payment type can use partial refunds
97
     *
98
     * @var bool
99
     */
100
    protected $_canRefundInvoicePartial = true;
101
102
    /**
103
     * Clearingtype for PAYONE authorization request
104
     *
105
     * @var string|bool
106
     */
107
    protected $sClearingtype = false;
108
109
    /**
110
     * Determines if the redirect-parameters have to be added
111
     * to the authorization-request
112
     *
113
     * @var bool
114
     */
115
    protected $blNeedsRedirectUrls = false;
116
117
    /**
118
     * Determines if the invoice information has to be added
119
     * to the authorization-request
120
     *
121
     * @var bool
122
     */
123
    protected $blNeedsProductInfo = false;
124
125
    /**
126
     * Determines if the bank data has to be added to the debit-request
127
     *
128
     * @var bool
129
     */
130
    protected $blNeedsSepaDataOnDebit = false;
131
132
    /**
133
     * Max length for narrative text parameter
134
     *
135
     * @var int
136
     */
137
    protected $iNarrativeTextMax = 81;
138
139
    /**
140
     * PAYONE toolkit helper
141
     *
142
     * @var \Payone\Core\Helper\Toolkit
143
     */
144
    protected $toolkitHelper;
145
146
    /**
147
     * PAYONE shop helper
148
     *
149
     * @var \Payone\Core\Helper\Shop
150
     */
151
    protected $shopHelper;
152
153
    /**
154
     * URL helper
155
     *
156
     * @var \Magento\Framework\Url
157
     */
158
    protected $url;
159
160
    /**
161
     * Checkout session model
162
     *
163
     * @var \Magento\Checkout\Model\Session
0 ignored issues
show
Bug introduced by
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...
164
     */
165
    protected $checkoutSession;
166
167
    /**
168
     * Payment method group identifier
169
     *
170
     * @var string|bool
171
     */
172
    protected $sGroupName = false;
173
174
    /**
175
     * Payment method sub type
176
     *
177
     * @var string|bool
178
     */
179
    protected $sSubType = false;
180
181
    /**
182
     * PAYONE debit request model
183
     *
184
     * @var \Payone\Core\Model\Api\Request\Debit
185
     */
186
    protected $debitRequest;
187
188
    /**
189
     * PAYONE capture request model
190
     *
191
     * @var \Payone\Core\Model\Api\Request\Capture
192
     */
193
    protected $captureRequest;
194
195
    /**
196
     * PAYONE authorization request model
197
     *
198
     * @var \Payone\Core\Model\Api\Request\Authorization
199
     */
200
    protected $authorizationRequest;
201
202
    /**
203
     * Constructor
204
     *
205
     * @param \Magento\Framework\Model\Context                        $context
206
     * @param \Magento\Framework\Registry                             $registry
207
     * @param \Magento\Framework\Api\ExtensionAttributesFactory       $extensionFactory
208
     * @param \Magento\Framework\Api\AttributeValueFactory            $customAttrFactory
209
     * @param \Magento\Payment\Helper\Data                            $paymentData
210
     * @param \Magento\Framework\App\Config\ScopeConfigInterface      $scopeConfig
211
     * @param \Magento\Payment\Model\Method\Logger                    $logger
212
     * @param \Payone\Core\Helper\Toolkit                             $toolkitHelper
213
     * @param \Payone\Core\Helper\Shop                                $shopHelper
214
     * @param \Magento\Framework\Url                                  $url
215
     * @param \Magento\Checkout\Model\Session                         $checkoutSession
216
     * @param \Payone\Core\Model\Api\Request\Debit                    $debitRequest
217
     * @param \Payone\Core\Model\Api\Request\Capture                  $captureRequest
218
     * @param \Payone\Core\Model\Api\Request\Authorization            $authorizationRequest
219
     * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
220
     * @param \Magento\Framework\Data\Collection\AbstractDb           $resourceCollection
221
     * @param array                                                   $data
222
     */
223
    public function __construct(
224
        \Magento\Framework\Model\Context $context,
225
        \Magento\Framework\Registry $registry,
226
        \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
227
        \Magento\Framework\Api\AttributeValueFactory $customAttrFactory,
228
        \Magento\Payment\Helper\Data $paymentData,
0 ignored issues
show
Bug introduced by
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...
229
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
230
        \Magento\Payment\Model\Method\Logger $logger,
0 ignored issues
show
Bug introduced by
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...
231
        \Payone\Core\Helper\Toolkit $toolkitHelper,
232
        \Payone\Core\Helper\Shop $shopHelper,
233
        \Magento\Framework\Url $url,
234
        \Magento\Checkout\Model\Session $checkoutSession,
235
        \Payone\Core\Model\Api\Request\Debit $debitRequest,
236
        \Payone\Core\Model\Api\Request\Capture $captureRequest,
237
        \Payone\Core\Model\Api\Request\Authorization $authorizationRequest,
238
        \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
239
        \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
240
        array $data = []
241
    ) {
242
        parent::__construct($context, $registry, $extensionFactory, $customAttrFactory, $paymentData, $scopeConfig, $logger, $resource, $resourceCollection, $data);
243
        $this->toolkitHelper = $toolkitHelper;
244
        $this->shopHelper = $shopHelper;
245
        $this->url = $url;
246
        $this->checkoutSession = $checkoutSession;
247
        $this->debitRequest = $debitRequest;
248
        $this->captureRequest = $captureRequest;
249
        $this->authorizationRequest = $authorizationRequest;
250
    }
251
252
    /**
253
     * Get instructions text from config
254
     *
255
     * @return string
256
     */
257
    public function getInstructions()
258
    {
259
        return trim($this->getConfigData('instructions')); // return description text
260
    }
261
262
    /**
263
     * Payment action getter compatible with payment model
264
     *
265
     * @return string
266
     */
267
    public function getConfigPaymentAction()
268
    {
269
        return AbstractMethod::ACTION_AUTHORIZE; // only create order
270
    }
271
272
    /**
273
     * Authorize payment abstract method
274
     *
275
     * @param  InfoInterface $payment
276
     * @param  float         $amount
277
     * @return AbstractMethod
278
     */
279
    public function authorize(InfoInterface $payment, $amount)
280
    {
281
        $oReturn = parent::authorize($payment, $amount); // execute Magento parent authorization
282
        $this->sendPayoneAuthorization($payment, $amount); // send auth request to PAYONE
283
        return $oReturn; // return magento parent auth value
284
    }
285
286
    /**
287
     * Refund payment abstract method
288
     *
289
     * @param  InfoInterface $payment
290
     * @param  float         $amount
291
     * @return AbstractMethod
292
     */
293
    public function refund(InfoInterface $payment, $amount)
294
    {
295
        $oReturn = parent::refund($payment, $amount); // execute Magento parent refund
296
        $this->sendPayoneDebit($payment, $amount); // send debit request to PAYONE
297
        return $oReturn; // return magento parent refund value
298
    }
299
300
    /**
301
     * Capture payment abstract method
302
     *
303
     * @param  InfoInterface $payment
304
     * @param  float         $amount
305
     * @return AbstractMethod
306
     */
307
    public function capture(InfoInterface $payment, $amount)
308
    {
309
        $oReturn = parent::capture($payment, $amount); // execute Magento parent capture
310
        if ($payment->getParentTransactionId()) {// does the order already have a transaction?
311
            $this->sendPayoneCapture($payment, $amount); // is probably admin invoice capture
312
        } else {
313
            $this->sendPayoneAuthorization($payment, $amount); // is probably frontend checkout capture
314
        }
315
        return $oReturn; // return magento parent capture value
316
    }
317
318
    /**
319
     * To check billing country is allowed for the payment method
320
     * Overrides the parent method with extended behaviour
321
     *
322
     * @param  string $country
323
     * @return bool
324
     */
325
    public function canUseForCountry($country)
326
    {
327
        $iAllowSpecific = $this->shopHelper->getConfigParam('allowspecific');
328
        $aAvailableCountries = explode(',', $this->shopHelper->getConfigParam('specificcountry'));
329
        if ($this->hasCustomConfig()) {// check for non-global configuration
330
            $iAllowSpecific = $this->getCustomConfigParam('allowspecific'); // only specific countries allowed?
331
            $aAvailableCountries = explode(',', $this->getCustomConfigParam('specificcountry')); // get allowed countries
332
        }
333
        if ($iAllowSpecific == 1 && !in_array($country, $aAvailableCountries)) {// only specific but not included
334
            return false; // cant use for given country
335
        }
336
        return true; // can use for given country
337
    }
338
}
339