33 * Copyright © Magento, Inc. All rights reserved.
44 * See COPYING.txt for license details.
55 */
6+ declare (strict_types=1 );
7+
68namespace Magento \Payment \Helper ;
79
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 ;
819use Magento \Quote \Model \Quote ;
20+ use Magento \Store \Model \App \Emulation ;
21+ use Magento \Store \Model \ScopeInterface ;
922use Magento \Store \Model \Store ;
1023use Magento \Payment \Block \Form ;
1124use Magento \Payment \Model \InfoInterface ;
1427use Magento \Framework \View \LayoutFactory ;
1528use Magento \Payment \Model \Method \AbstractMethod ;
1629use Magento \Payment \Model \MethodInterface ;
30+ use UnexpectedValueException ;
1731
1832/**
1933 * Payment module base helper
2236 * @api
2337 * @since 100.0.2
2438 */
25- class Data extends \ Magento \ Framework \ App \ Helper \ AbstractHelper
39+ class Data extends AbstractHelper
2640{
2741 const XML_PATH_PAYMENT_METHODS = 'payment ' ;
2842
2943 /**
30- * @var \Magento\Payment\Model\ Config
44+ * @var Config
3145 */
3246 protected $ _paymentConfig ;
3347
3448 /**
3549 * Layout
3650 *
37- * @var \Magento\Framework\View\LayoutInterface
51+ * @deprecated
52+ * @var LayoutInterface
3853 */
3954 protected $ _layout ;
4055
56+ /**
57+ * @var LayoutFactory
58+ */
59+ private $ layoutFactory ;
60+
4161 /**
4262 * Factory for payment method models
4363 *
44- * @var \Magento\Payment\Model\Method\ Factory
64+ * @var Factory
4565 */
4666 protected $ _methodFactory ;
4767
4868 /**
4969 * App emulation model
5070 *
51- * @var \Magento\Store\Model\App\ Emulation
71+ * @var Emulation
5272 */
5373 protected $ _appEmulation ;
5474
5575 /**
56- * @var \Magento\Framework\App\Config\ Initial
76+ * @var Initial
5777 */
5878 protected $ _initialConfig ;
5979
6080 /**
6181 * Construct
6282 *
63- * @param \Magento\Framework\App\Helper\ Context $context
83+ * @param Context $context
6484 * @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
6989 */
7090 public function __construct (
71- \ Magento \ Framework \ App \ Helper \ Context $ context ,
91+ Context $ context ,
7292 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
7797 ) {
7898 parent ::__construct ($ context );
79- $ this ->_layout = $ layoutFactory-> create () ;
99+ $ this ->layoutFactory = $ layoutFactory ;
80100 $ this ->_methodFactory = $ paymentMethodFactory ;
81101 $ this ->_appEmulation = $ appEmulation ;
82102 $ this ->_paymentConfig = $ paymentConfig ;
@@ -99,18 +119,18 @@ protected function getMethodModelConfigName($code)
99119 *
100120 * @param string $code
101121 *
102- * @throws \Magento\Framework\Exception\LocalizedException
103122 * @return MethodInterface
123+ * @throws LocalizedException
104124 */
105125 public function getMethodInstance ($ code )
106126 {
107127 $ class = $ this ->scopeConfig ->getValue (
108128 $ this ->getMethodModelConfigName ($ code ),
109- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE
129+ ScopeInterface::SCOPE_STORE
110130 );
111131
112132 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! ' );
114134 }
115135
116136 return $ this ->_methodFactory ->create ($ class );
@@ -133,7 +153,7 @@ public function getStoreMethods($store = null, $quote = null)
133153 foreach (array_keys ($ methods ) as $ code ) {
134154 $ model = $ this ->scopeConfig ->getValue (
135155 $ this ->getMethodModelConfigName ($ code ),
136- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE ,
156+ ScopeInterface::SCOPE_STORE ,
137157 $ store
138158 );
139159 if (!$ model ) {
@@ -178,12 +198,12 @@ public function getMethodFormBlock(MethodInterface $method, LayoutInterface $lay
178198 * Retrieve payment information block
179199 *
180200 * @param InfoInterface $info
181- * @param \Magento\Framework\View\ LayoutInterface $layout
201+ * @param LayoutInterface $layout
182202 * @return Template
183203 */
184204 public function getInfoBlock (InfoInterface $ info , LayoutInterface $ layout = null )
185205 {
186- $ layout = $ layout ?: $ this ->_layout ;
206+ $ layout = $ layout ?: $ this ->layoutFactory -> create () ;
187207 $ blockType = $ info ->getMethodInstance ()->getInfoBlockType ();
188208 $ block = $ layout ->createBlock ($ blockType );
189209 $ block ->setInfo ($ info );
@@ -196,21 +216,21 @@ public function getInfoBlock(InfoInterface $info, LayoutInterface $layout = null
196216 * @param InfoInterface $info
197217 * @param int $storeId
198218 * @return string
199- * @throws \ Exception
219+ * @throws Exception
200220 */
201221 public function getInfoBlockHtml (InfoInterface $ info , $ storeId )
202222 {
203- $ this ->_appEmulation ->startEnvironmentEmulation ($ storeId , \ Magento \ Framework \ App \ Area::AREA_FRONTEND , true );
223+ $ this ->_appEmulation ->startEnvironmentEmulation ($ storeId , Area::AREA_FRONTEND , true );
204224
205225 try {
206226 // Retrieve specified view block from appropriate design package (depends on emulated store)
207227 $ paymentBlock = $ this ->getInfoBlock ($ info );
208- $ paymentBlock ->setArea (\ Magento \ Framework \ App \ Area::AREA_FRONTEND )
228+ $ paymentBlock ->setArea (Area::AREA_FRONTEND )
209229 ->setIsSecureMode (true );
210230 $ paymentBlock ->getMethod ()
211231 ->setStore ($ storeId );
212232 $ paymentBlockHtml = $ paymentBlock ->toHtml ();
213- } catch (\ Exception $ exception ) {
233+ } catch (Exception $ exception ) {
214234 $ this ->_appEmulation ->stopEnvironmentEmulation ();
215235 throw $ exception ;
216236 }
@@ -313,8 +333,8 @@ public function getPaymentMethodList($sorted = true, $asLabelValue = false, $wit
313333 public function isZeroSubTotal ($ store = null )
314334 {
315335 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 ,
318338 $ store
319339 );
320340 }
@@ -328,8 +348,8 @@ public function isZeroSubTotal($store = null)
328348 public function getZeroSubTotalOrderStatus ($ store = null )
329349 {
330350 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 ,
333353 $ store
334354 );
335355 }
@@ -343,8 +363,8 @@ public function getZeroSubTotalOrderStatus($store = null)
343363 public function getZeroSubTotalPaymentAutomaticInvoice ($ store = null )
344364 {
345365 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 ,
348368 $ store
349369 );
350370 }
@@ -359,9 +379,9 @@ public function getZeroSubTotalPaymentAutomaticInvoice($store = null)
359379 private function getMethodStoreTitle (string $ code , ?int $ storeId = null ): string
360380 {
361381 $ configPath = sprintf ('%s/%s/title ' , self ::XML_PATH_PAYMENT_METHODS , $ code );
362- return (string ) $ this ->scopeConfig ->getValue (
382+ return (string )$ this ->scopeConfig ->getValue (
363383 $ configPath ,
364- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE ,
384+ ScopeInterface::SCOPE_STORE ,
365385 $ storeId
366386 );
367387 }
0 commit comments