Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
ExpressConfigProvider Class Reference
Inheritance diagram for ExpressConfigProvider:
ConfigProviderInterface

Public Member Functions

 __construct (ConfigFactory $configFactory, ResolverInterface $localeResolver, CurrentCustomer $currentCustomer, PaypalHelper $paypalHelper, PaymentHelper $paymentHelper, UrlInterface $urlBuilder)
 
 getConfig ()
 

Data Fields

const IN_CONTEXT_BUTTON_ID = 'paypal-express-in-context-button'
 

Protected Member Functions

 isInContextCheckout ()
 
 getMethodRedirectUrl ($code)
 
 getBillingAgreementCode ($code)
 

Protected Attributes

 $localeResolver
 
 $config
 
 $currentCustomer
 
 $paypalHelper
 
 $methodCodes
 
 $methods = []
 
 $paymentHelper
 
 $urlBuilder
 

Detailed Description

Class ExpressConfigProvider @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 19 of file ExpressConfigProvider.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ConfigFactory  $configFactory,
ResolverInterface  $localeResolver,
CurrentCustomer  $currentCustomer,
PaypalHelper  $paypalHelper,
PaymentHelper  $paymentHelper,
UrlInterface  $urlBuilder 
)

Constructor

Parameters
ConfigFactory$configFactory
ResolverInterface$localeResolver
CurrentCustomer$currentCustomer
PaypalHelper$paypalHelper
PaymentHelper$paymentHelper
UrlInterface$urlBuilder

Definition at line 78 of file ExpressConfigProvider.php.

85  {
86  $this->localeResolver = $localeResolver;
87  $this->config = $configFactory->create();
88  $this->currentCustomer = $currentCustomer;
89  $this->paypalHelper = $paypalHelper;
90  $this->paymentHelper = $paymentHelper;
91  $this->urlBuilder = $urlBuilder;
92 
93  foreach ($this->methodCodes as $code) {
94  $this->methods[$code] = $this->paymentHelper->getMethodInstance($code);
95  }
96  }
$configFactory
Definition: config_data.php:43
$code
Definition: info.phtml:12

Member Function Documentation

◆ getBillingAgreementCode()

getBillingAgreementCode (   $code)
protected

Return billing agreement code for method

Parameters
string$code
Returns
null|string

Definition at line 175 of file ExpressConfigProvider.php.

176  {
177  $customerId = $this->currentCustomer->getCustomerId();
178  $this->config->setMethod($code);
179  return $this->paypalHelper->shouldAskToCreateBillingAgreement($this->config, $customerId)
181  }
$code
Definition: info.phtml:12

◆ getConfig()

getConfig ( )

{Retrieve assoc array of checkout configuration

Returns
array
}

Implements ConfigProviderInterface.

Definition at line 101 of file ExpressConfigProvider.php.

102  {
103  $locale = $this->localeResolver->getLocale();
104 
105  $config = [
106  'payment' => [
107  'paypalExpress' => [
108  'paymentAcceptanceMarkHref' => $this->config->getPaymentMarkWhatIsPaypalUrl(
109  $this->localeResolver
110  ),
111  'paymentAcceptanceMarkSrc' => $this->config->getPaymentMarkImageUrl(
112  $locale
113  ),
114  'isContextCheckout' => false,
115  'inContextConfig' => []
116  ]
117  ]
118  ];
119 
120  $isInContext = $this->isInContextCheckout();
121  if ($isInContext) {
122  $config['payment']['paypalExpress']['isContextCheckout'] = $isInContext;
123  $config['payment']['paypalExpress']['inContextConfig'] = [
124  'inContextId' => self::IN_CONTEXT_BUTTON_ID,
125  'merchantId' => $this->config->getValue('merchant_id'),
126  'path' => $this->urlBuilder->getUrl('paypal/express/gettoken', ['_secure' => true]),
127  'clientConfig' => [
128  'environment' => ((int) $this->config->getValue('sandbox_flag') ? 'sandbox' : 'production'),
129  'locale' => $locale,
130  'button' => [
131  self::IN_CONTEXT_BUTTON_ID
132  ]
133  ],
134  ];
135  }
136 
137  foreach ($this->methodCodes as $code) {
138  if ($this->methods[$code]->isAvailable()) {
139  $config['payment']['paypalExpress']['redirectUrl'][$code] = $this->getMethodRedirectUrl($code);
140  $config['payment']['paypalExpress']['billingAgreementCode'][$code] =
141  $this->getBillingAgreementCode($code);
142  }
143  }
144 
145  return $config;
146  }
$code
Definition: info.phtml:12

◆ getMethodRedirectUrl()

getMethodRedirectUrl (   $code)
protected

Return redirect URL for method

Parameters
string$code
Returns
mixed

Definition at line 164 of file ExpressConfigProvider.php.

165  {
166  return $this->methods[$code]->getCheckoutRedirectUrl();
167  }
$code
Definition: info.phtml:12

◆ isInContextCheckout()

isInContextCheckout ( )
protected
Returns
bool

Definition at line 151 of file ExpressConfigProvider.php.

152  {
153  $this->config->setMethod(Config::METHOD_EXPRESS);
154 
155  return (bool)(int) $this->config->getValue('in_context');
156  }

Field Documentation

◆ $config

$config
protected

Definition at line 31 of file ExpressConfigProvider.php.

◆ $currentCustomer

$currentCustomer
protected

Definition at line 36 of file ExpressConfigProvider.php.

◆ $localeResolver

$localeResolver
protected

Definition at line 26 of file ExpressConfigProvider.php.

◆ $methodCodes

$methodCodes
protected

◆ $methods

$methods = []
protected

Definition at line 56 of file ExpressConfigProvider.php.

◆ $paymentHelper

$paymentHelper
protected

Definition at line 61 of file ExpressConfigProvider.php.

◆ $paypalHelper

$paypalHelper
protected

Definition at line 41 of file ExpressConfigProvider.php.

◆ $urlBuilder

$urlBuilder
protected

Definition at line 66 of file ExpressConfigProvider.php.

◆ IN_CONTEXT_BUTTON_ID

const IN_CONTEXT_BUTTON_ID = 'paypal-express-in-context-button'

Definition at line 21 of file ExpressConfigProvider.php.


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