123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Braintree\Block\Paypal;
- use Magento\Braintree\Gateway\Config\PayPal\Config;
- use Magento\Braintree\Model\Ui\ConfigProvider;
- use Magento\Catalog\Block\ShortcutInterface;
- use Magento\Checkout\Model\Session;
- use Magento\Framework\Locale\ResolverInterface;
- use Magento\Framework\View\Element\Template;
- use Magento\Framework\View\Element\Template\Context;
- use Magento\Payment\Model\MethodInterface;
- /**
- * Class Button
- */
- class Button extends Template implements ShortcutInterface
- {
- const ALIAS_ELEMENT_INDEX = 'alias';
- const BUTTON_ELEMENT_INDEX = 'button_id';
- /**
- * @var ResolverInterface
- */
- private $localeResolver;
- /**
- * @var Session
- */
- private $checkoutSession;
- /**
- * @var Config
- */
- private $config;
- /**
- * @var ConfigProvider
- */
- private $configProvider;
- /**
- * @var MethodInterface
- */
- private $payment;
- /**
- * Constructor
- *
- * @param Context $context
- * @param ResolverInterface $localeResolver
- * @param Session $checkoutSession
- * @param Config $config
- * @param ConfigProvider $configProvider
- * @param MethodInterface $payment
- * @param array $data
- */
- public function __construct(
- Context $context,
- ResolverInterface $localeResolver,
- Session $checkoutSession,
- Config $config,
- ConfigProvider $configProvider,
- MethodInterface $payment,
- array $data = []
- ) {
- parent::__construct($context, $data);
- $this->localeResolver = $localeResolver;
- $this->checkoutSession = $checkoutSession;
- $this->config = $config;
- $this->configProvider = $configProvider;
- $this->payment = $payment;
- }
- /**
- * @inheritdoc
- */
- protected function _toHtml()
- {
- if ($this->isActive()) {
- return parent::_toHtml();
- }
- return '';
- }
- /**
- * @inheritdoc
- */
- public function getAlias()
- {
- return $this->getData(self::ALIAS_ELEMENT_INDEX);
- }
- /**
- * @return string
- */
- public function getContainerId()
- {
- return $this->getData(self::BUTTON_ELEMENT_INDEX);
- }
- /**
- * @return string
- */
- public function getLocale()
- {
- return $this->localeResolver->getLocale();
- }
- /**
- * @return string
- */
- public function getCurrency()
- {
- return $this->checkoutSession->getQuote()->getCurrency()->getBaseCurrencyCode();
- }
- /**
- * @return float
- */
- public function getAmount()
- {
- return $this->checkoutSession->getQuote()->getBaseGrandTotal();
- }
- /**
- * @return bool
- */
- public function isActive()
- {
- return $this->payment->isAvailable($this->checkoutSession->getQuote()) &&
- $this->config->isDisplayShoppingCart();
- }
- /**
- * @return string
- */
- public function getMerchantName()
- {
- return $this->config->getMerchantName();
- }
- /**
- * @return string|null
- */
- public function getClientToken()
- {
- return $this->configProvider->getClientToken();
- }
- /**
- * @return string
- */
- public function getActionSuccess()
- {
- return $this->getUrl(ConfigProvider::CODE . '/paypal/review', ['_secure' => true]);
- }
- }
|