Delete.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Paypal\Controller\Adminhtml\Billing\Agreement;
  8. class Delete extends \Magento\Paypal\Controller\Adminhtml\Billing\Agreement
  9. {
  10. /**
  11. * Authorization level of a basic admin session
  12. *
  13. * @see _isAllowed()
  14. */
  15. const ADMIN_RESOURCE = 'Magento_Paypal::actions_manage';
  16. /**
  17. * Delete billing agreement action
  18. *
  19. * @return void
  20. */
  21. public function execute()
  22. {
  23. $agreementModel = $this->_initBillingAgreement();
  24. if ($agreementModel) {
  25. try {
  26. $agreementModel->delete();
  27. $this->messageManager->addSuccessMessage(
  28. __('You deleted the billing agreement.')
  29. );
  30. $this->_redirect('paypal/*/');
  31. return;
  32. } catch (\Magento\Framework\Exception\LocalizedException $e) {
  33. $this->messageManager->addExceptionMessage(
  34. $e,
  35. $e->getMessage()
  36. );
  37. } catch (\Exception $e) {
  38. $this->messageManager->addExceptionMessage(
  39. $e,
  40. __('We can\'t delete the billing agreement.')
  41. );
  42. }
  43. $this->_redirect('paypal/*/view', ['_current' => true]);
  44. }
  45. $this->_redirect('paypal/*/');
  46. }
  47. }