Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Form.php
Go to the documentation of this file.
1 <?php
7 
14 use Magento\Paypal\Model\ConfigFactory;
16 
18 {
25 
31  protected $_paypalData;
32 
37 
41  protected $_localeResolver;
42 
46  protected $_config;
47 
51  protected $_isScopePrivate;
52 
56  protected $currentCustomer;
57 
66  public function __construct(
67  Context $context,
68  ConfigFactory $paypalConfigFactory,
69  ResolverInterface $localeResolver,
70  Data $paypalData,
72  array $data = []
73  ) {
74  $this->_paypalData = $paypalData;
75  $this->_paypalConfigFactory = $paypalConfigFactory;
76  $this->_localeResolver = $localeResolver;
77  $this->_config = null;
78  $this->_isScopePrivate = true;
79  $this->currentCustomer = $currentCustomer;
80  parent::__construct($context, $data);
81  }
82 
88  protected function _construct()
89  {
90  $this->_config = $this->_paypalConfigFactory->create()
91  ->setMethod($this->getMethodCode());
92  $mark = $this->_getMarkTemplate();
93  $mark->setPaymentAcceptanceMarkHref(
94  $this->_config->getPaymentMarkWhatIsPaypalUrl($this->_localeResolver)
95  )->setPaymentAcceptanceMarkSrc(
96  $this->_config->getPaymentMarkImageUrl($this->_localeResolver->getLocale())
97  );
98 
99  // known issue: code above will render only static mark image
101  parent::_construct();
102 
103  $this->setRedirectMessage(__('You will be redirected to the PayPal website.'));
104  }
105 
111  public function getMethodCode()
112  {
113  return $this->_methodCode;
114  }
115 
121  protected function _getMarkTemplate()
122  {
124  $mark = $this->_layout->createBlock(\Magento\Framework\View\Element\Template::class);
125  $mark->setTemplate('Magento_Paypal::payment/mark.phtml');
126  return $mark;
127  }
128 
136  {
137  $this->setTemplate(
138  'Magento_Paypal::payment/redirect.phtml'
139  )->setRedirectMessage(
140  __('You will be redirected to the PayPal website when you place an order.')
141  )->setMethodTitle(
142  // Output PayPal mark, omit title
143  ''
144  )->setMethodLabelAfterHtml(
145  $mark->toHtml()
146  );
147  }
148 
154  public function getBillingAgreementCode()
155  {
156  $customerId = $this->currentCustomer->getCustomerId();
157  return $this->_paypalData->shouldAskToCreateBillingAgreement($this->_config, $customerId)
159  : null;
160  }
161 }
__()
Definition: __.php:13
_initializeRedirectTemplateWithMark(Template $mark)
Definition: Form.php:135
__construct(Context $context, ConfigFactory $paypalConfigFactory, ResolverInterface $localeResolver, Data $paypalData, CurrentCustomer $currentCustomer, array $data=[])
Definition: Form.php:66