Start.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Controller\Express\AbstractExpress;
  7. use Magento\Paypal\Controller\Express\GetToken;
  8. /**
  9. * Class Start
  10. */
  11. class Start extends GetToken
  12. {
  13. /**
  14. * Start Express Checkout by requesting initial token and dispatching customer to PayPal
  15. *
  16. * @return void
  17. * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  18. */
  19. public function execute()
  20. {
  21. try {
  22. $token = $this->getToken();
  23. if ($token === null) {
  24. return;
  25. }
  26. $url = $this->_checkout->getRedirectUrl();
  27. if ($token && $url) {
  28. $this->_initToken($token);
  29. $this->getResponse()->setRedirect($url);
  30. return;
  31. }
  32. } catch (\Magento\Framework\Exception\LocalizedException $e) {
  33. $this->messageManager->addExceptionMessage($e, $e->getMessage());
  34. } catch (\Exception $e) {
  35. $this->messageManager->addExceptionMessage(
  36. $e,
  37. __('We can\'t start Express Checkout.')
  38. );
  39. }
  40. $this->_redirect('checkout/cart');
  41. }
  42. }