Cancel.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  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 Cancel extends \Magento\Paypal\Controller\Billing\Agreement
  9. {
  10. /**
  11. * Cancel action
  12. * Set billing agreement status to 'Canceled'
  13. *
  14. * @return void
  15. */
  16. public function execute()
  17. {
  18. $agreement = $this->_initAgreement();
  19. if (!$agreement) {
  20. return;
  21. }
  22. if ($agreement->canCancel()) {
  23. try {
  24. $agreement->cancel();
  25. $this->messageManager->addNoticeMessage(
  26. __('The billing agreement "%1" has been canceled.', $agreement->getReferenceId())
  27. );
  28. } catch (\Magento\Framework\Exception\LocalizedException $e) {
  29. $this->messageManager->addExceptionMessage($e, $e->getMessage());
  30. } catch (\Exception $e) {
  31. $this->messageManager->addExceptionMessage($e, __('We can\'t cancel the billing agreement.'));
  32. }
  33. }
  34. $this->_redirect('*/*/view', ['_current' => true]);
  35. }
  36. }