/** * {@inheritdoc} */ public function getSectionData() { $customerId = $this->currentCustomer->getCustomerId(); if ($this->paypalData->shouldAskToCreateBillingAgreement($this->config, $customerId)) { return ['askToCreate' => true, 'confirmUrl' => $this->escaper->escapeUrl($this->urlBuilder->getUrl($this->startAction, [\Magento\Paypal\Model\Express\Checkout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT => 1])), 'confirmMessage' => $this->escaper->escapeJsQuote(__('Would you like to sign a billing agreement to streamline further purchases with PayPal?'))]; } return []; }
/** * @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; }
/** * Get billing agreement code * * @return string|null */ public function getBillingAgreementCode() { $customerId = $this->currentCustomer->getCustomerId(); return $this->_paypalData->shouldAskToCreateBillingAgreement($this->_config, $customerId) ? \Magento\Paypal\Model\Express\Checkout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT : null; }
/** * Return billing agreement code for method * * @param string $code * @return null|string */ protected function getBillingAgreementCode($code) { $customerId = $this->currentCustomer->getCustomerId(); $this->config->setMethod($code); return $this->paypalHelper->shouldAskToCreateBillingAgreement($this->config, $customerId) ? Express\Checkout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT : null; }