1
1
<?php
2
+ declare (strict_types=1 );
2
3
/**
3
4
* Copyright © Magento, Inc. All rights reserved.
4
5
* See COPYING.txt for license details.
5
6
*/
7
+
6
8
namespace Magento \Payment \Helper ;
7
9
10
+ use Exception ;
11
+ use Magento \Framework \App \Area ;
12
+ use Magento \Framework \App \Config \Initial ;
13
+ use Magento \Framework \App \Helper \AbstractHelper ;
14
+ use Magento \Framework \App \Helper \Context ;
15
+ use Magento \Framework \Exception \LocalizedException ;
16
+ use Magento \Payment \Model \Config ;
17
+ use Magento \Payment \Model \Method \Factory ;
18
+ use Magento \Payment \Model \Method \Free ;
8
19
use Magento \Quote \Model \Quote ;
20
+ use Magento \Store \Model \App \Emulation ;
21
+ use Magento \Store \Model \ScopeInterface ;
9
22
use Magento \Store \Model \Store ;
10
23
use Magento \Payment \Block \Form ;
11
24
use Magento \Payment \Model \InfoInterface ;
14
27
use Magento \Framework \View \LayoutFactory ;
15
28
use Magento \Payment \Model \Method \AbstractMethod ;
16
29
use Magento \Payment \Model \MethodInterface ;
30
+ use UnexpectedValueException ;
17
31
18
32
/**
19
33
* Payment module base helper
22
36
* @api
23
37
* @since 100.0.2
24
38
*/
25
- class Data extends \ Magento \ Framework \ App \ Helper \ AbstractHelper
39
+ class Data extends AbstractHelper
26
40
{
27
41
const XML_PATH_PAYMENT_METHODS = 'payment ' ;
28
42
29
43
/**
30
- * @var \Magento\Payment\Model\ Config
44
+ * @var Config
31
45
*/
32
46
protected $ _paymentConfig ;
33
47
34
48
/**
35
49
* Layout
36
50
* @deprecated
37
- * @var \Magento\Framework\View\ LayoutInterface
51
+ * @var LayoutInterface
38
52
*/
39
53
protected $ _layout ;
40
54
41
55
/**
42
56
* LayoutFactory
43
- * @var \Magento\Framework\View\LayoutFactory
57
+ *
58
+ * @var LayoutFactory
44
59
*/
45
- private $ _layoutFactory ;
60
+ private $ layoutFactory ;
46
61
47
62
/**
48
63
* Factory for payment method models
49
64
*
50
- * @var \Magento\Payment\Model\Method\ Factory
65
+ * @var Factory
51
66
*/
52
67
protected $ _methodFactory ;
53
68
54
69
/**
55
70
* App emulation model
56
71
*
57
- * @var \Magento\Store\Model\App\ Emulation
72
+ * @var Emulation
58
73
*/
59
74
protected $ _appEmulation ;
60
75
61
76
/**
62
- * @var \Magento\Framework\App\Config\ Initial
77
+ * @var Initial
63
78
*/
64
79
protected $ _initialConfig ;
65
80
66
81
/**
67
82
* Construct
68
83
*
69
- * @param \Magento\Framework\App\Helper\ Context $context
84
+ * @param Context $context
70
85
* @param LayoutFactory $layoutFactory
71
- * @param \Magento\Payment\Model\Method\ Factory $paymentMethodFactory
72
- * @param \Magento\Store\Model\App\ Emulation $appEmulation
73
- * @param \Magento\Payment\Model\ Config $paymentConfig
74
- * @param \Magento\Framework\App\Config\ Initial $initialConfig
86
+ * @param Factory $paymentMethodFactory
87
+ * @param Emulation $appEmulation
88
+ * @param Config $paymentConfig
89
+ * @param Initial $initialConfig
75
90
*/
76
91
public function __construct (
77
- \ Magento \ Framework \ App \ Helper \ Context $ context ,
92
+ Context $ context ,
78
93
LayoutFactory $ layoutFactory ,
79
- \ Magento \ Payment \ Model \ Method \ Factory $ paymentMethodFactory ,
80
- \ Magento \ Store \ Model \ App \ Emulation $ appEmulation ,
81
- \ Magento \ Payment \ Model \ Config $ paymentConfig ,
82
- \ Magento \ Framework \ App \ Config \ Initial $ initialConfig
94
+ Factory $ paymentMethodFactory ,
95
+ Emulation $ appEmulation ,
96
+ Config $ paymentConfig ,
97
+ Initial $ initialConfig
83
98
) {
84
99
parent ::__construct ($ context );
85
- $ this ->_layoutFactory = $ layoutFactory ;
100
+ $ this ->layoutFactory = $ layoutFactory ;
86
101
$ this ->_methodFactory = $ paymentMethodFactory ;
87
102
$ this ->_appEmulation = $ appEmulation ;
88
103
$ this ->_paymentConfig = $ paymentConfig ;
@@ -105,18 +120,18 @@ protected function getMethodModelConfigName($code)
105
120
*
106
121
* @param string $code
107
122
*
108
- * @throws \Magento\Framework\Exception\LocalizedException
109
123
* @return MethodInterface
124
+ * @throws LocalizedException
110
125
*/
111
126
public function getMethodInstance ($ code )
112
127
{
113
128
$ class = $ this ->scopeConfig ->getValue (
114
129
$ this ->getMethodModelConfigName ($ code ),
115
- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE
130
+ ScopeInterface::SCOPE_STORE
116
131
);
117
132
118
133
if (!$ class ) {
119
- throw new \ UnexpectedValueException ('Payment model name is not provided in config! ' );
134
+ throw new UnexpectedValueException ('Payment model name is not provided in config! ' );
120
135
}
121
136
122
137
return $ this ->_methodFactory ->create ($ class );
@@ -139,7 +154,7 @@ public function getStoreMethods($store = null, $quote = null)
139
154
foreach (array_keys ($ methods ) as $ code ) {
140
155
$ model = $ this ->scopeConfig ->getValue (
141
156
$ this ->getMethodModelConfigName ($ code ),
142
- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE ,
157
+ ScopeInterface::SCOPE_STORE ,
143
158
$ store
144
159
);
145
160
if (!$ model ) {
@@ -184,12 +199,12 @@ public function getMethodFormBlock(MethodInterface $method, LayoutInterface $lay
184
199
* Retrieve payment information block
185
200
*
186
201
* @param InfoInterface $info
187
- * @param \Magento\Framework\View\ LayoutInterface $layout
202
+ * @param LayoutInterface $layout
188
203
* @return Template
189
204
*/
190
205
public function getInfoBlock (InfoInterface $ info , LayoutInterface $ layout = null )
191
206
{
192
- $ layout = $ layout ?: $ this ->_layoutFactory ->create ();
207
+ $ layout = $ layout ?: $ this ->layoutFactory ->create ();
193
208
$ blockType = $ info ->getMethodInstance ()->getInfoBlockType ();
194
209
$ block = $ layout ->createBlock ($ blockType );
195
210
$ block ->setInfo ($ info );
@@ -202,21 +217,21 @@ public function getInfoBlock(InfoInterface $info, LayoutInterface $layout = null
202
217
* @param InfoInterface $info
203
218
* @param int $storeId
204
219
* @return string
205
- * @throws \ Exception
220
+ * @throws Exception
206
221
*/
207
222
public function getInfoBlockHtml (InfoInterface $ info , $ storeId )
208
223
{
209
- $ this ->_appEmulation ->startEnvironmentEmulation ($ storeId , \ Magento \ Framework \ App \ Area::AREA_FRONTEND , true );
224
+ $ this ->_appEmulation ->startEnvironmentEmulation ($ storeId , Area::AREA_FRONTEND , true );
210
225
211
226
try {
212
227
// Retrieve specified view block from appropriate design package (depends on emulated store)
213
228
$ paymentBlock = $ this ->getInfoBlock ($ info );
214
- $ paymentBlock ->setArea (\ Magento \ Framework \ App \ Area::AREA_FRONTEND )
229
+ $ paymentBlock ->setArea (Area::AREA_FRONTEND )
215
230
->setIsSecureMode (true );
216
231
$ paymentBlock ->getMethod ()
217
232
->setStore ($ storeId );
218
233
$ paymentBlockHtml = $ paymentBlock ->toHtml ();
219
- } catch (\ Exception $ exception ) {
234
+ } catch (Exception $ exception ) {
220
235
$ this ->_appEmulation ->stopEnvironmentEmulation ();
221
236
throw $ exception ;
222
237
}
@@ -319,8 +334,8 @@ public function getPaymentMethodList($sorted = true, $asLabelValue = false, $wit
319
334
public function isZeroSubTotal ($ store = null )
320
335
{
321
336
return $ this ->scopeConfig ->getValue (
322
- \ Magento \ Payment \ Model \ Method \ Free::XML_PATH_PAYMENT_FREE_ACTIVE ,
323
- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE ,
337
+ Free::XML_PATH_PAYMENT_FREE_ACTIVE ,
338
+ ScopeInterface::SCOPE_STORE ,
324
339
$ store
325
340
);
326
341
}
@@ -334,8 +349,8 @@ public function isZeroSubTotal($store = null)
334
349
public function getZeroSubTotalOrderStatus ($ store = null )
335
350
{
336
351
return $ this ->scopeConfig ->getValue (
337
- \ Magento \ Payment \ Model \ Method \ Free::XML_PATH_PAYMENT_FREE_ORDER_STATUS ,
338
- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE ,
352
+ Free::XML_PATH_PAYMENT_FREE_ORDER_STATUS ,
353
+ ScopeInterface::SCOPE_STORE ,
339
354
$ store
340
355
);
341
356
}
@@ -349,8 +364,8 @@ public function getZeroSubTotalOrderStatus($store = null)
349
364
public function getZeroSubTotalPaymentAutomaticInvoice ($ store = null )
350
365
{
351
366
return $ this ->scopeConfig ->getValue (
352
- \ Magento \ Payment \ Model \ Method \ Free::XML_PATH_PAYMENT_FREE_PAYMENT_ACTION ,
353
- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE ,
367
+ Free::XML_PATH_PAYMENT_FREE_PAYMENT_ACTION ,
368
+ ScopeInterface::SCOPE_STORE ,
354
369
$ store
355
370
);
356
371
}
@@ -365,9 +380,9 @@ public function getZeroSubTotalPaymentAutomaticInvoice($store = null)
365
380
private function getMethodStoreTitle (string $ code , ?int $ storeId = null ): string
366
381
{
367
382
$ configPath = sprintf ('%s/%s/title ' , self ::XML_PATH_PAYMENT_METHODS , $ code );
368
- return (string ) $ this ->scopeConfig ->getValue (
383
+ return (string )$ this ->scopeConfig ->getValue (
369
384
$ configPath ,
370
- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE ,
385
+ ScopeInterface::SCOPE_STORE ,
371
386
$ storeId
372
387
);
373
388
}
0 commit comments