123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Paypal\Block\Bml;
- use Magento\Catalog\Block as CatalogBlock;
- use Magento\Paypal\Helper\Shortcut\ValidatorInterface;
- use Magento\Paypal\Model\ConfigFactory;
- use Magento\Paypal\Model\Config;
- use Magento\Framework\App\ObjectManager;
- /**
- * Class shortcut
- */
- class Shortcut extends \Magento\Framework\View\Element\Template implements CatalogBlock\ShortcutInterface
- {
- /**
- * Whether the block should be eventually rendered
- *
- * @var bool
- */
- protected $_shouldRender = true;
- /**
- * Payment method code
- *
- * @var string
- */
- private $_paymentMethodCode = '';
- /**
- * Shortcut alias
- *
- * @var string
- */
- private $_alias = '';
- /**
- * Start express action
- *
- * @var string
- */
- private $_startAction = '';
- /**
- * @var \Magento\Payment\Helper\Data
- */
- private $_paymentData;
- /**
- * @var \Magento\Framework\Math\Random
- */
- private $_mathRandom;
- /**
- * Bml method code
- *
- * @var string
- */
- private $_bmlMethodCode = '';
- /**
- * Shortcut image path
- */
- const SHORTCUT_IMAGE = 'https://www.paypalobjects.com/webstatic/en_US/i/buttons/ppcredit-logo-medium.png';
- /**
- * @var ValidatorInterface
- */
- private $_shortcutValidator;
- /**
- * @var Config
- */
- private $config;
- /**
- * @param \Magento\Framework\View\Element\Template\Context $context
- * @param \Magento\Payment\Helper\Data $paymentData
- * @param \Magento\Framework\Math\Random $mathRandom
- * @param ValidatorInterface $shortcutValidator
- * @param string $paymentMethodCode
- * @param string $startAction
- * @param string $alias
- * @param string $bmlMethodCode
- * @param string $shortcutTemplate
- * @param array $data
- * @param ConfigFactory|null $config
- * @SuppressWarnings(PHPMD.ExcessiveParameterList)
- * @codingStandardsIgnoreStart
- */
- public function __construct(
- \Magento\Framework\View\Element\Template\Context $context,
- \Magento\Payment\Helper\Data $paymentData,
- \Magento\Framework\Math\Random $mathRandom,
- ValidatorInterface $shortcutValidator,
- $paymentMethodCode,
- $startAction,
- $alias,
- $bmlMethodCode,
- $shortcutTemplate,
- array $data = [],
- ConfigFactory $config = null
- ) {
- $this->_paymentData = $paymentData;
- $this->_mathRandom = $mathRandom;
- $this->_shortcutValidator = $shortcutValidator;
- $this->_paymentMethodCode = $paymentMethodCode;
- $this->_startAction = $startAction;
- $this->_alias = $alias;
- $this->setTemplate($shortcutTemplate);
- $this->_bmlMethodCode = $bmlMethodCode;
- $this->config = $config
- ? $config->create()
- : ObjectManager::getInstance()->get(ConfigFactory::class)->create();
- $this->config->setMethod($this->_paymentMethodCode);
- parent::__construct($context, $data);
- }
- //@codingStandardsIgnoreEnd
- /**
- * @inheritdoc
- */
- protected function _beforeToHtml()
- {
- $result = parent::_beforeToHtml();
- $isInCatalog = $this->getIsInCatalogProduct();
- if (!$this->_shortcutValidator->validate($this->_paymentMethodCode, $isInCatalog)
- || (bool)(int)$this->config->getValue('in_context')
- ) {
- $this->_shouldRender = false;
- return $result;
- }
- /** @var \Magento\Paypal\Model\Express $method */
- $method = $this->_paymentData->getMethodInstance($this->_bmlMethodCode);
- if (!$method->isAvailable()) {
- $this->_shouldRender = false;
- return $result;
- }
- $this->setShortcutHtmlId($this->_mathRandom->getUniqueHash('ec_shortcut_bml_'))
- ->setCheckoutUrl($this->getUrl($this->_startAction))
- ->setImageUrl(self::SHORTCUT_IMAGE)
- ->setAdditionalLinkImage(
- [
- 'href' => 'https://www.securecheckout.billmelater.com/paycapture-content/'
- . 'fetch?hash=AU826TU8&content=/bmlweb/ppwpsiw.html',
- 'src' => 'https://www.paypalobjects.com/webstatic/en_US/btn/btn_bml_text.png',
- ]
- );
- return $result;
- }
- /**
- * Render the block if needed
- *
- * @return string
- */
- protected function _toHtml()
- {
- if (!$this->_shouldRender) {
- return '';
- }
- return parent::_toHtml();
- }
- /**
- * Check is "OR" label position before shortcut
- *
- * @return bool
- */
- public function isOrPositionBefore()
- {
- return $this->getShowOrPosition() == CatalogBlock\ShortcutButtons::POSITION_BEFORE;
- }
- /**
- * Check is "OR" label position after shortcut
- *
- * @return bool
- */
- public function isOrPositionAfter()
- {
- return $this->getShowOrPosition() == CatalogBlock\ShortcutButtons::POSITION_AFTER;
- }
- /**
- * Get shortcut alias
- *
- * @return string
- */
- public function getAlias()
- {
- return $this->_alias;
- }
- }
|