AbstractAction.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Braintree\Controller\Paypal;
  7. use Magento\Checkout\Model\Session;
  8. use Magento\Framework\App\Action\Action;
  9. use Magento\Framework\App\Action\Context;
  10. use Magento\Quote\Api\Data\CartInterface;
  11. use Magento\Framework\App\RequestInterface;
  12. use Magento\Framework\Controller\Result\Redirect;
  13. use Magento\Braintree\Gateway\Config\PayPal\Config;
  14. /**
  15. * Abstract class AbstractAction
  16. */
  17. abstract class AbstractAction extends Action
  18. {
  19. /**
  20. * @var Config
  21. */
  22. protected $config;
  23. /**
  24. * @var Session
  25. */
  26. protected $checkoutSession;
  27. /**
  28. * Constructor
  29. *
  30. * @param Context $context
  31. * @param Config $config
  32. * @param Session $checkoutSession
  33. */
  34. public function __construct(
  35. Context $context,
  36. Config $config,
  37. Session $checkoutSession
  38. ) {
  39. parent::__construct($context);
  40. $this->config = $config;
  41. $this->checkoutSession = $checkoutSession;
  42. }
  43. /**
  44. * Check whether payment method is enabled
  45. *
  46. * @inheritdoc
  47. */
  48. public function dispatch(RequestInterface $request)
  49. {
  50. if (!$this->config->isActive() || !$this->config->isDisplayShoppingCart()) {
  51. $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
  52. /** @var Redirect $resultRedirect */
  53. $resultRedirect = $this->resultRedirectFactory->create();
  54. $resultRedirect->setPath('noRoute');
  55. return $resultRedirect;
  56. }
  57. return parent::dispatch($request);
  58. }
  59. /**
  60. * @param CartInterface $quote
  61. * @return void
  62. * @throws \InvalidArgumentException
  63. */
  64. protected function validateQuote($quote)
  65. {
  66. if (!$quote || !$quote->getItemsCount()) {
  67. throw new \InvalidArgumentException(__('Checkout failed to initialize. Verify and try again.'));
  68. }
  69. }
  70. }