3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
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
*
37
- * @var \Magento\Framework\View\LayoutInterface
51
+ * @deprecated
52
+ * @var LayoutInterface
38
53
*/
39
54
protected $ _layout ;
40
55
56
+ /**
57
+ * @var LayoutFactory
58
+ */
59
+ private $ layoutFactory ;
60
+
41
61
/**
42
62
* Factory for payment method models
43
63
*
44
- * @var \Magento\Payment\Model\Method\ Factory
64
+ * @var Factory
45
65
*/
46
66
protected $ _methodFactory ;
47
67
48
68
/**
49
69
* App emulation model
50
70
*
51
- * @var \Magento\Store\Model\App\ Emulation
71
+ * @var Emulation
52
72
*/
53
73
protected $ _appEmulation ;
54
74
55
75
/**
56
- * @var \Magento\Framework\App\Config\ Initial
76
+ * @var Initial
57
77
*/
58
78
protected $ _initialConfig ;
59
79
60
80
/**
61
81
* Construct
62
82
*
63
- * @param \Magento\Framework\App\Helper\ Context $context
83
+ * @param Context $context
64
84
* @param LayoutFactory $layoutFactory
65
- * @param \Magento\Payment\Model\Method\ Factory $paymentMethodFactory
66
- * @param \Magento\Store\Model\App\ Emulation $appEmulation
67
- * @param \Magento\Payment\Model\ Config $paymentConfig
68
- * @param \Magento\Framework\App\Config\ Initial $initialConfig
85
+ * @param Factory $paymentMethodFactory
86
+ * @param Emulation $appEmulation
87
+ * @param Config $paymentConfig
88
+ * @param Initial $initialConfig
69
89
*/
70
90
public function __construct (
71
- \ Magento \ Framework \ App \ Helper \ Context $ context ,
91
+ Context $ context ,
72
92
LayoutFactory $ layoutFactory ,
73
- \ Magento \ Payment \ Model \ Method \ Factory $ paymentMethodFactory ,
74
- \ Magento \ Store \ Model \ App \ Emulation $ appEmulation ,
75
- \ Magento \ Payment \ Model \ Config $ paymentConfig ,
76
- \ Magento \ Framework \ App \ Config \ Initial $ initialConfig
93
+ Factory $ paymentMethodFactory ,
94
+ Emulation $ appEmulation ,
95
+ Config $ paymentConfig ,
96
+ Initial $ initialConfig
77
97
) {
78
98
parent ::__construct ($ context );
79
- $ this ->_layout = $ layoutFactory-> create () ;
99
+ $ this ->layoutFactory = $ layoutFactory ;
80
100
$ this ->_methodFactory = $ paymentMethodFactory ;
81
101
$ this ->_appEmulation = $ appEmulation ;
82
102
$ this ->_paymentConfig = $ paymentConfig ;
@@ -99,18 +119,18 @@ protected function getMethodModelConfigName($code)
99
119
*
100
120
* @param string $code
101
121
*
102
- * @throws \Magento\Framework\Exception\LocalizedException
103
122
* @return MethodInterface
123
+ * @throws LocalizedException
104
124
*/
105
125
public function getMethodInstance ($ code )
106
126
{
107
127
$ class = $ this ->scopeConfig ->getValue (
108
128
$ this ->getMethodModelConfigName ($ code ),
109
- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE
129
+ ScopeInterface::SCOPE_STORE
110
130
);
111
131
112
132
if (!$ class ) {
113
- throw new \ UnexpectedValueException ('Payment model name is not provided in config! ' );
133
+ throw new UnexpectedValueException ('Payment model name is not provided in config! ' );
114
134
}
115
135
116
136
return $ this ->_methodFactory ->create ($ class );
@@ -133,7 +153,7 @@ public function getStoreMethods($store = null, $quote = null)
133
153
foreach (array_keys ($ methods ) as $ code ) {
134
154
$ model = $ this ->scopeConfig ->getValue (
135
155
$ this ->getMethodModelConfigName ($ code ),
136
- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE ,
156
+ ScopeInterface::SCOPE_STORE ,
137
157
$ store
138
158
);
139
159
if (!$ model ) {
@@ -178,12 +198,12 @@ public function getMethodFormBlock(MethodInterface $method, LayoutInterface $lay
178
198
* Retrieve payment information block
179
199
*
180
200
* @param InfoInterface $info
181
- * @param \Magento\Framework\View\ LayoutInterface $layout
201
+ * @param LayoutInterface $layout
182
202
* @return Template
183
203
*/
184
204
public function getInfoBlock (InfoInterface $ info , LayoutInterface $ layout = null )
185
205
{
186
- $ layout = $ layout ?: $ this ->_layout ;
206
+ $ layout = $ layout ?: $ this ->layoutFactory -> create () ;
187
207
$ blockType = $ info ->getMethodInstance ()->getInfoBlockType ();
188
208
$ block = $ layout ->createBlock ($ blockType );
189
209
$ block ->setInfo ($ info );
@@ -196,21 +216,21 @@ public function getInfoBlock(InfoInterface $info, LayoutInterface $layout = null
196
216
* @param InfoInterface $info
197
217
* @param int $storeId
198
218
* @return string
199
- * @throws \ Exception
219
+ * @throws Exception
200
220
*/
201
221
public function getInfoBlockHtml (InfoInterface $ info , $ storeId )
202
222
{
203
- $ this ->_appEmulation ->startEnvironmentEmulation ($ storeId , \ Magento \ Framework \ App \ Area::AREA_FRONTEND , true );
223
+ $ this ->_appEmulation ->startEnvironmentEmulation ($ storeId , Area::AREA_FRONTEND , true );
204
224
205
225
try {
206
226
// Retrieve specified view block from appropriate design package (depends on emulated store)
207
227
$ paymentBlock = $ this ->getInfoBlock ($ info );
208
- $ paymentBlock ->setArea (\ Magento \ Framework \ App \ Area::AREA_FRONTEND )
228
+ $ paymentBlock ->setArea (Area::AREA_FRONTEND )
209
229
->setIsSecureMode (true );
210
230
$ paymentBlock ->getMethod ()
211
231
->setStore ($ storeId );
212
232
$ paymentBlockHtml = $ paymentBlock ->toHtml ();
213
- } catch (\ Exception $ exception ) {
233
+ } catch (Exception $ exception ) {
214
234
$ this ->_appEmulation ->stopEnvironmentEmulation ();
215
235
throw $ exception ;
216
236
}
@@ -313,8 +333,8 @@ public function getPaymentMethodList($sorted = true, $asLabelValue = false, $wit
313
333
public function isZeroSubTotal ($ store = null )
314
334
{
315
335
return $ this ->scopeConfig ->getValue (
316
- \ Magento \ Payment \ Model \ Method \ Free::XML_PATH_PAYMENT_FREE_ACTIVE ,
317
- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE ,
336
+ Free::XML_PATH_PAYMENT_FREE_ACTIVE ,
337
+ ScopeInterface::SCOPE_STORE ,
318
338
$ store
319
339
);
320
340
}
@@ -328,8 +348,8 @@ public function isZeroSubTotal($store = null)
328
348
public function getZeroSubTotalOrderStatus ($ store = null )
329
349
{
330
350
return $ this ->scopeConfig ->getValue (
331
- \ Magento \ Payment \ Model \ Method \ Free::XML_PATH_PAYMENT_FREE_ORDER_STATUS ,
332
- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE ,
351
+ Free::XML_PATH_PAYMENT_FREE_ORDER_STATUS ,
352
+ ScopeInterface::SCOPE_STORE ,
333
353
$ store
334
354
);
335
355
}
@@ -343,8 +363,8 @@ public function getZeroSubTotalOrderStatus($store = null)
343
363
public function getZeroSubTotalPaymentAutomaticInvoice ($ store = null )
344
364
{
345
365
return $ this ->scopeConfig ->getValue (
346
- \ Magento \ Payment \ Model \ Method \ Free::XML_PATH_PAYMENT_FREE_PAYMENT_ACTION ,
347
- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE ,
366
+ Free::XML_PATH_PAYMENT_FREE_PAYMENT_ACTION ,
367
+ ScopeInterface::SCOPE_STORE ,
348
368
$ store
349
369
);
350
370
}
@@ -359,9 +379,9 @@ public function getZeroSubTotalPaymentAutomaticInvoice($store = null)
359
379
private function getMethodStoreTitle (string $ code , ?int $ storeId = null ): string
360
380
{
361
381
$ configPath = sprintf ('%s/%s/title ' , self ::XML_PATH_PAYMENT_METHODS , $ code );
362
- return (string ) $ this ->scopeConfig ->getValue (
382
+ return (string )$ this ->scopeConfig ->getValue (
363
383
$ configPath ,
364
- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE ,
384
+ ScopeInterface::SCOPE_STORE ,
365
385
$ storeId
366
386
);
367
387
}
0 commit comments