Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractConfig.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Paypal\Model;
7 
14 
18 abstract class AbstractConfig implements ConfigInterface
19 {
23  const PAYMENT_ACTION_SALE = 'Sale';
24 
25  const PAYMENT_ACTION_AUTH = 'Authorization';
26 
27  const PAYMENT_ACTION_ORDER = 'Order';
33  const METHOD_WPP_EXPRESS = 'paypal_express';
34 
40  protected $_methodCode;
41 
47  protected $_storeId;
48 
52  protected $pathPattern;
53 
57  protected $productMetadata;
58 
62  private static $bnCode = 'Magento_Cart_%s';
63 
67  protected $_scopeConfig;
68 
72  public function __construct(
73  \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
74  ) {
75  $this->_scopeConfig = $scopeConfig;
76  }
77 
81  protected $methodInstance;
82 
89  public function setMethodInstance($method)
90  {
91  $this->methodInstance = $method;
92  return $this;
93  }
94 
101  public function setMethod($method)
102  {
103  if ($method instanceof MethodInterface) {
104  $this->_methodCode = $method->getCode();
105  } elseif (is_string($method)) {
106  $this->_methodCode = $method;
107  }
108  return $this;
109  }
110 
116  public function getMethodCode()
117  {
118  return $this->_methodCode;
119  }
120 
127  public function setStoreId($storeId)
128  {
129  $this->_storeId = (int)$storeId;
130  return $this;
131  }
132 
142  public function getValue($key, $storeId = null)
143  {
144  switch ($key) {
145  case 'getDebugReplacePrivateDataKeys':
146  return $this->methodInstance->getDebugReplacePrivateDataKeys();
147  default:
148  $underscored = strtolower(preg_replace('/(.)([A-Z])/', "$1_$2", $key));
149  $path = $this->_getSpecificConfigPath($underscored);
150  if ($path !== null) {
151  $value = $this->_scopeConfig->getValue(
152  $path,
154  $this->_storeId
155  );
156  $value = $this->_prepareValue($underscored, $value);
157  return $value;
158  }
159  }
160  return null;
161  }
162 
169  public function setMethodCode($methodCode)
170  {
171  $this->_methodCode = $methodCode;
172  }
173 
180  public function setPathPattern($pathPattern)
181  {
182  $this->pathPattern = $pathPattern;
183  }
184 
191  protected function _getSpecificConfigPath($fieldName)
192  {
193  if ($this->pathPattern) {
194  return sprintf($this->pathPattern, $this->_methodCode, $fieldName);
195  }
196 
197  return "payment/{$this->_methodCode}/{$fieldName}";
198  }
199 
207  protected function _prepareValue($key, $value)
208  {
209  // Always set payment action as "Sale" for Unilateral payments in EC
210  if ($key == 'payment_action' &&
211  $value != self::PAYMENT_ACTION_SALE &&
212  $this->_methodCode == self::METHOD_WPP_EXPRESS &&
214  ) {
216  }
217  return $value;
218  }
219 
225  public function shouldUseUnilateralPayments()
226  {
227  return $this->getValue('business_account') && !$this->isWppApiAvailabe();
228  }
229 
235  public function isWppApiAvailabe()
236  {
237  return $this->getValue('api_username')
238  && $this->getValue('api_password')
239  && ($this->getValue('api_signature')
240  || $this->getValue('api_cert'));
241  }
242 
250  public function isMethodAvailable($methodCode = null)
251  {
253 
254  return $this->isMethodActive($methodCode);
255  }
256 
266  public function isMethodActive($method)
267  {
268  switch ($method) {
271  $isEnabled = $this->_scopeConfig->isSetFlag(
272  'payment/' . Config::METHOD_WPS_EXPRESS .'/active',
274  $this->_storeId
275  )
276  || $this->_scopeConfig->isSetFlag(
277  'payment/' . Config::METHOD_WPP_EXPRESS .'/active',
279  $this->_storeId
280  );
282  break;
285  $isEnabled = $this->_scopeConfig->isSetFlag(
286  'payment/' . Config::METHOD_WPS_BML .'/active',
288  $this->_storeId
289  )
290  || $this->_scopeConfig->isSetFlag(
291  'payment/' . Config::METHOD_WPP_BML .'/active',
293  $this->_storeId
294  );
296  break;
299  $isEnabled = $this->_scopeConfig->isSetFlag(
300  'payment/' . Config::METHOD_PAYMENT_PRO .'/active',
302  $this->_storeId
303  )
304  || $this->_scopeConfig->isSetFlag(
305  'payment/' . Config::METHOD_PAYFLOWPRO .'/active',
307  $this->_storeId
308  );
310  break;
311  default:
312  $isEnabled = $this->_scopeConfig->isSetFlag(
313  "payment/{$method}/active",
315  $this->_storeId
316  );
317  }
318 
319  return $this->isMethodSupportedForCountry($method) && $isEnabled;
320  }
321 
331  public function isMethodSupportedForCountry($method = null, $countryCode = null)
332  {
333  return true;
334  }
335 
341  public function getBuildNotationCode()
342  {
343  $notationCode = $this->_scopeConfig->getValue('paypal/notation_code', ScopeInterface::SCOPE_STORES);
344  return $notationCode ?: sprintf(self::$bnCode, $this->getProductMetadata()->getEdition());
345  }
346 
353  protected function getProductMetadata()
354  {
355  if ($this->productMetadata === null) {
356  $this->productMetadata = ObjectManager::getInstance()->get(ProductMetadataInterface::class);
357  }
358  return $this->productMetadata;
359  }
360 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
isMethodSupportedForCountry($method=null, $countryCode=null)
$value
Definition: gender.phtml:16
__construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig)
$method
Definition: info.phtml:13