Agreement.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Controller\Adminhtml\Billing;
  7. /**
  8. * Adminhtml billing agreement controller
  9. */
  10. abstract class Agreement extends \Magento\Backend\App\Action
  11. {
  12. /**
  13. * Authorization level of a basic admin session
  14. *
  15. * @see _isAllowed()
  16. */
  17. const ADMIN_RESOURCE = 'Magento_Paypal::billing_agreement';
  18. /**
  19. * Core registry
  20. *
  21. * @var \Magento\Framework\Registry
  22. */
  23. protected $_coreRegistry = null;
  24. /**
  25. * @param \Magento\Backend\App\Action\Context $context
  26. * @param \Magento\Framework\Registry $coreRegistry
  27. */
  28. public function __construct(\Magento\Backend\App\Action\Context $context, \Magento\Framework\Registry $coreRegistry)
  29. {
  30. $this->_coreRegistry = $coreRegistry;
  31. parent::__construct($context);
  32. }
  33. /**
  34. * Initialize billing agreement by ID specified in request
  35. *
  36. * @return \Magento\Paypal\Model\Billing\Agreement|false
  37. */
  38. protected function _initBillingAgreement()
  39. {
  40. $agreementId = $this->getRequest()->getParam('agreement');
  41. $agreementModel = $this->_objectManager->create(
  42. \Magento\Paypal\Model\Billing\Agreement::class
  43. )->load($agreementId);
  44. if (!$agreementModel->getId()) {
  45. $this->messageManager->addErrorMessage(
  46. __('Please specify the correct billing agreement ID and try again.')
  47. );
  48. return false;
  49. }
  50. $this->_coreRegistry->register('current_billing_agreement', $agreementModel);
  51. return $agreementModel;
  52. }
  53. }