Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
AbstractConfig Class Reference
Inheritance diagram for AbstractConfig:
ConfigInterface ConfigInterface Config AbstractConfigTesting PayflowConfig

Public Member Functions

 __construct (\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig)
 
 setMethodInstance ($method)
 
 setMethod ($method)
 
 getMethodCode ()
 
 setStoreId ($storeId)
 
 getValue ($key, $storeId=null)
 
 setMethodCode ($methodCode)
 
 setPathPattern ($pathPattern)
 
 shouldUseUnilateralPayments ()
 
 isWppApiAvailabe ()
 
 isMethodAvailable ($methodCode=null)
 
 isMethodActive ($method)
 
 isMethodSupportedForCountry ($method=null, $countryCode=null)
 
 getBuildNotationCode ()
 

Data Fields

const PAYMENT_ACTION_SALE = 'Sale'
 
const PAYMENT_ACTION_AUTH = 'Authorization'
 
const PAYMENT_ACTION_ORDER = 'Order'
 
const METHOD_WPP_EXPRESS = 'paypal_express'
 

Protected Member Functions

 _getSpecificConfigPath ($fieldName)
 
 _prepareValue ($key, $value)
 
 getProductMetadata ()
 

Protected Attributes

 $_methodCode
 
 $_storeId
 
 $pathPattern
 
 $productMetadata
 
 $_scopeConfig
 
 $methodInstance
 

Detailed Description

Class AbstractConfig

Definition at line 18 of file AbstractConfig.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\App\Config\ScopeConfigInterface  $scopeConfig)
Parameters
\Magento\Framework\App\Config\ScopeConfigInterface$scopeConfig

Definition at line 72 of file AbstractConfig.php.

74  {
75  $this->_scopeConfig = $scopeConfig;
76  }

Member Function Documentation

◆ _getSpecificConfigPath()

_getSpecificConfigPath (   $fieldName)
protected

Map any supported payment method into a config path by specified field name

Parameters
string$fieldName
Returns
string|null

Definition at line 191 of file AbstractConfig.php.

192  {
193  if ($this->pathPattern) {
194  return sprintf($this->pathPattern, $this->_methodCode, $fieldName);
195  }
196 
197  return "payment/{$this->_methodCode}/{$fieldName}";
198  }

◆ _prepareValue()

_prepareValue (   $key,
  $value 
)
protected

Perform additional config value preparation and return new value if needed

Parameters
string$keyUnderscored key
string$valueOld value
Returns
string Modified value or old value

Definition at line 207 of file AbstractConfig.php.

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  }
$value
Definition: gender.phtml:16

◆ getBuildNotationCode()

getBuildNotationCode ( )

BN code getter

Returns
string

Definition at line 341 of file AbstractConfig.php.

342  {
343  $notationCode = $this->_scopeConfig->getValue('paypal/notation_code', ScopeInterface::SCOPE_STORES);
344  return $notationCode ?: sprintf(self::$bnCode, $this->getProductMetadata()->getEdition());
345  }

◆ getMethodCode()

getMethodCode ( )

Payment method instance code getter

Returns
string

Definition at line 116 of file AbstractConfig.php.

◆ getProductMetadata()

getProductMetadata ( )
protected

The getter function to get the ProductMetadata

Returns
ProductMetadataInterface
Deprecated:
100.1.0

Definition at line 353 of file AbstractConfig.php.

354  {
355  if ($this->productMetadata === null) {
356  $this->productMetadata = ObjectManager::getInstance()->get(ProductMetadataInterface::class);
357  }
358  return $this->productMetadata;
359  }

◆ getValue()

getValue (   $key,
  $storeId = null 
)

Returns payment configuration value

Parameters
string$key
null$storeId
Returns
null|string

@SuppressWarnings(PHPMD.UnusedFormalParameter)

Implements ConfigInterface.

Definition at line 142 of file AbstractConfig.php.

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  }
$value
Definition: gender.phtml:16

◆ isMethodActive()

isMethodActive (   $method)

Check whether method active in configuration and supported for merchant country or not

Parameters
string$methodMethod code
Returns
bool
Todo:
: refactor this @SuppressWarnings(PHPMD.CyclomaticComplexity)

Definition at line 266 of file AbstractConfig.php.

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  }
isMethodSupportedForCountry($method=null, $countryCode=null)
$method
Definition: info.phtml:13

◆ isMethodAvailable()

isMethodAvailable (   $methodCode = null)

Check whether method available for checkout or not

Parameters
null$methodCode
Returns
bool

Definition at line 250 of file AbstractConfig.php.

◆ isMethodSupportedForCountry()

isMethodSupportedForCountry (   $method = null,
  $countryCode = null 
)

Check whether method supported for specified country or not

Parameters
string | null$method
string | null$countryCode
Returns
bool

@SuppressWarnings(PHPMD.UnusedFormalParameter)

Definition at line 331 of file AbstractConfig.php.

332  {
333  return true;
334  }

◆ isWppApiAvailabe()

isWppApiAvailabe ( )

Check whether WPP API credentials are available for this method

Returns
bool

Definition at line 235 of file AbstractConfig.php.

236  {
237  return $this->getValue('api_username')
238  && $this->getValue('api_password')
239  && ($this->getValue('api_signature')
240  || $this->getValue('api_cert'));
241  }

◆ setMethod()

setMethod (   $method)

Method code setter

Parameters
string | MethodInterface$method
Returns
$this

Definition at line 101 of file AbstractConfig.php.

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  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$method
Definition: info.phtml:13

◆ setMethodCode()

setMethodCode (   $methodCode)

Sets method code

Parameters
string$methodCode
Returns
void

Implements ConfigInterface.

Definition at line 169 of file AbstractConfig.php.

170  {
171  $this->_methodCode = $methodCode;
172  }

◆ setMethodInstance()

setMethodInstance (   $method)

Sets method instance used for retrieving method specific data

Parameters
MethodInterface$method
Returns
$this

Definition at line 89 of file AbstractConfig.php.

90  {
91  $this->methodInstance = $method;
92  return $this;
93  }
$method
Definition: info.phtml:13

◆ setPathPattern()

setPathPattern (   $pathPattern)

Sets path pattern

Parameters
string$pathPattern
Returns
void

Implements ConfigInterface.

Definition at line 180 of file AbstractConfig.php.

181  {
182  $this->pathPattern = $pathPattern;
183  }

◆ setStoreId()

setStoreId (   $storeId)

Store ID setter

Parameters
int$storeId
Returns
$this

Definition at line 127 of file AbstractConfig.php.

128  {
129  $this->_storeId = (int)$storeId;
130  return $this;
131  }

◆ shouldUseUnilateralPayments()

shouldUseUnilateralPayments ( )

Check whether only Unilateral payments (Accelerated Boarding) possible for Express method or not

Returns
bool

Definition at line 225 of file AbstractConfig.php.

226  {
227  return $this->getValue('business_account') && !$this->isWppApiAvailabe();
228  }

Field Documentation

◆ $_methodCode

$_methodCode
protected

Definition at line 40 of file AbstractConfig.php.

◆ $_scopeConfig

$_scopeConfig
protected

Definition at line 67 of file AbstractConfig.php.

◆ $_storeId

$_storeId
protected

Definition at line 47 of file AbstractConfig.php.

◆ $methodInstance

$methodInstance
protected

Definition at line 81 of file AbstractConfig.php.

◆ $pathPattern

$pathPattern
protected

Definition at line 52 of file AbstractConfig.php.

◆ $productMetadata

$productMetadata
protected

Definition at line 57 of file AbstractConfig.php.

◆ METHOD_WPP_EXPRESS

const METHOD_WPP_EXPRESS = 'paypal_express'

#- PayPal Website Payments Pro - Express Checkout

Definition at line 33 of file AbstractConfig.php.

◆ PAYMENT_ACTION_AUTH

const PAYMENT_ACTION_AUTH = 'Authorization'

Definition at line 25 of file AbstractConfig.php.

◆ PAYMENT_ACTION_ORDER

const PAYMENT_ACTION_ORDER = 'Order'

Definition at line 27 of file AbstractConfig.php.

◆ PAYMENT_ACTION_SALE

const PAYMENT_ACTION_SALE = 'Sale'

#+ Payment actions

Definition at line 23 of file AbstractConfig.php.


The documentation for this class was generated from the following file: