StartWizard.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Paypal\Controller\Billing\Agreement;
  8. class StartWizard extends \Magento\Paypal\Controller\Billing\Agreement
  9. {
  10. /**
  11. * Wizard start action
  12. *
  13. * @return \Magento\Framework\App\Response\Http
  14. */
  15. public function execute()
  16. {
  17. $agreement = $this->_objectManager->create(\Magento\Paypal\Model\Billing\Agreement::class);
  18. $paymentCode = $this->getRequest()->getParam('payment_method');
  19. if ($paymentCode) {
  20. try {
  21. $agreement->setStoreId(
  22. $this->_objectManager->get(\Magento\Store\Model\StoreManager::class)->getStore()->getId()
  23. )->setMethodCode(
  24. $paymentCode
  25. )->setReturnUrl(
  26. $this->_objectManager->create(
  27. \Magento\Framework\UrlInterface::class
  28. )->getUrl('*/*/returnWizard', ['payment_method' => $paymentCode])
  29. )->setCancelUrl(
  30. $this->_objectManager->create(\Magento\Framework\UrlInterface::class)
  31. ->getUrl('*/*/cancelWizard', ['payment_method' => $paymentCode])
  32. );
  33. return $this->getResponse()->setRedirect($agreement->initToken());
  34. } catch (\Magento\Framework\Exception\LocalizedException $e) {
  35. $this->messageManager->addExceptionMessage($e, $e->getMessage());
  36. } catch (\Exception $e) {
  37. $this->messageManager->addExceptionMessage(
  38. $e,
  39. __('We can\'t start the billing agreement wizard.')
  40. );
  41. }
  42. }
  43. $this->_redirect('*/*/');
  44. }
  45. }