/**
  * @return \Magento\Framework\View\Element\AbstractBlock
  */
 protected function _beforeToHtml()
 {
     $result = parent::_beforeToHtml();
     /** @var \Magento\Paypal\Model\Config $config */
     $config = $this->_paypalConfigFactory->create();
     $config->setMethod($this->_paymentMethodCode);
     $isInCatalog = $this->getIsInCatalogProduct();
     if (!$this->_shortcutValidator->validate($this->_paymentMethodCode, $isInCatalog)) {
         $this->_shouldRender = false;
         return $result;
     }
     $quote = $isInCatalog || !$this->_checkoutSession ? null : $this->_checkoutSession->getQuote();
     // set misc data
     $this->setShortcutHtmlId($this->_mathRandom->getUniqueHash('ec_shortcut_'))->setCheckoutUrl($this->getUrl($this->_startAction));
     // use static image if in catalog
     if ($isInCatalog || null === $quote) {
         $this->setImageUrl($config->getExpressCheckoutShortcutImageUrl($this->_localeResolver->getLocale()));
     } else {
         /**@todo refactor checkout model. Move getCheckoutShortcutImageUrl to helper or separate model */
         $parameters = ['params' => ['quote' => $quote, 'config' => $config]];
         $checkoutModel = $this->_checkoutFactory->create($this->_checkoutType, $parameters);
         $this->setImageUrl($checkoutModel->getCheckoutShortcutImageUrl());
     }
     // ask whether to create a billing agreement
     $customerId = $this->currentCustomer->getCustomerId();
     // potential issue for caching
     if ($this->_paypalData->shouldAskToCreateBillingAgreement($config, $customerId)) {
         $this->setConfirmationUrl($this->getUrl($this->_startAction, [\Magento\Paypal\Model\Express\Checkout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT => 1]));
         $this->setConfirmationMessage(__('Would you like to sign a billing agreement to streamline further purchases with PayPal?'));
     }
     return $result;
 }
 /**
  * Instantiate quote and checkout
  *
  * @return void
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _initCheckout()
 {
     $quote = $this->_getQuote();
     if (!$quote->hasItems() || $quote->getHasError()) {
         $this->getResponse()->setStatusHeader(403, '1.1', 'Forbidden');
         throw new \Magento\Framework\Exception\LocalizedException(__('We can\'t initialize Express Checkout.'));
     }
     if (!isset($this->_checkoutTypes[$this->_checkoutType])) {
         $parameters = ['params' => ['quote' => $quote, 'config' => $this->_config]];
         $this->_checkoutTypes[$this->_checkoutType] = $this->_checkoutFactory->create($this->_checkoutType, $parameters);
     }
     $this->_checkout = $this->_checkoutTypes[$this->_checkoutType];
 }
Exemple #3
0
 /**
  * @return \Magento\Framework\View\Element\AbstractBlock
  */
 protected function _beforeToHtml()
 {
     $result = parent::_beforeToHtml();
     $isInCatalog = $this->getIsInCatalogProduct();
     if (!$this->_shortcutValidator->validate($this->_paymentMethodCode, $isInCatalog)) {
         $this->_shouldRender = false;
         return $result;
     }
     $quote = $isInCatalog || !$this->_checkoutSession ? null : $this->_checkoutSession->getQuote();
     // set misc data
     $this->setShortcutHtmlId($this->_mathRandom->getUniqueHash('ec_shortcut_'))->setCheckoutUrl($this->getUrl($this->_startAction));
     // use static image if in catalog
     if ($isInCatalog || null === $quote) {
         $this->setImageUrl($this->config->getExpressCheckoutShortcutImageUrl($this->_localeResolver->getLocale()));
     } else {
         /**@todo refactor checkout model. Move getCheckoutShortcutImageUrl to helper or separate model */
         $parameters = ['params' => ['quote' => $quote, 'config' => $this->config]];
         $checkoutModel = $this->_checkoutFactory->create($this->_checkoutType, $parameters);
         $this->setImageUrl($checkoutModel->getCheckoutShortcutImageUrl());
     }
     return $result;
 }
Exemple #4
0
 /**
  * Instantiate quote and checkout
  *
  * @return void
  * @throws \Magento\Framework\Model\Exception
  */
 protected function _initCheckout()
 {
     $quote = $this->_getQuote();
     if (!$quote->hasItems() || $quote->getHasError()) {
         $this->getResponse()->setHeader('HTTP/1.1', '403 Forbidden');
         throw new \Magento\Framework\Model\Exception(__('We can\'t initialize Express Checkout.'));
     }
     if (!isset($this->_checkoutTypes[$this->_checkoutType])) {
         $parameters = array('params' => array('quote' => $quote, 'config' => $this->_config));
         $this->_checkoutTypes[$this->_checkoutType] = $this->_checkoutFactory->create($this->_checkoutType, $parameters);
     }
     $this->_checkout = $this->_checkoutTypes[$this->_checkoutType];
 }