5
5
*/
6
6
namespace Magento \Payment \Model \Method ;
7
7
8
+ use Magento \Framework \Api \AttributeValueFactory ;
9
+ use Magento \Framework \Api \ExtensionAttributesFactory ;
10
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
11
+ use Magento \Framework \App \ObjectManager ;
12
+ use Magento \Framework \Data \Collection \AbstractDb ;
13
+ use Magento \Framework \Model \Context ;
14
+ use Magento \Framework \Model \ResourceModel \AbstractResource ;
8
15
use Magento \Framework \Pricing \PriceCurrencyInterface ;
16
+ use Magento \Framework \Registry ;
17
+ use Magento \Payment \Helper \Data ;
18
+ use Magento \Sales \Model \Order \Config ;
19
+ use Magento \Sales \Model \Order \Status ;
9
20
10
21
/**
11
22
* Free payment method
@@ -50,6 +61,11 @@ class Free extends \Magento\Payment\Model\Method\AbstractMethod
50
61
*/
51
62
protected $ priceCurrency ;
52
63
64
+ /**
65
+ * @var Config|null
66
+ */
67
+ private $ config ;
68
+
53
69
/**
54
70
* @param \Magento\Framework\Model\Context $context
55
71
* @param \Magento\Framework\Registry $registry
@@ -62,6 +78,7 @@ class Free extends \Magento\Payment\Model\Method\AbstractMethod
62
78
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
63
79
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
64
80
* @param array $data
81
+ * @param Config|null $config
65
82
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
66
83
*/
67
84
public function __construct (
@@ -75,7 +92,8 @@ public function __construct(
75
92
PriceCurrencyInterface $ priceCurrency ,
76
93
\Magento \Framework \Model \ResourceModel \AbstractResource $ resource = null ,
77
94
\Magento \Framework \Data \Collection \AbstractDb $ resourceCollection = null ,
78
- array $ data = []
95
+ array $ data = [],
96
+ Config $ config = null
79
97
) {
80
98
parent ::__construct (
81
99
$ context ,
@@ -90,6 +108,7 @@ public function __construct(
90
108
$ data
91
109
);
92
110
$ this ->priceCurrency = $ priceCurrency ;
111
+ $ this ->config = $ config ?: ObjectManager::getInstance ()->create (Config::class);
93
112
}
94
113
95
114
/**
@@ -119,12 +138,14 @@ public function isAvailableInConfig($quote = null)
119
138
}
120
139
121
140
/**
122
- * Get config payment action, do nothing if status is pending
141
+ * Get config payment action, do nothing if status is pending or status is assigned to new[Pending] state
123
142
*
124
143
* @return string|null
125
144
*/
126
145
public function getConfigPaymentAction ()
127
146
{
128
- return $ this ->getConfigData ('order_status ' ) == 'pending ' ? null : parent ::getConfigPaymentAction ();
147
+ $ newStateStatuses = $ this ->config ->getStateStatuses ('new ' );
148
+ $ configNewOrderStatus = $ this ->getConfigData ('order_status ' );
149
+ return $ configNewOrderStatus == 'pending ' || array_key_exists ($ configNewOrderStatus , $ newStateStatuses ) ? null : parent ::getConfigPaymentAction ();
129
150
}
130
151
}
0 commit comments