Transactions.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Controller\Adminhtml;
  7. use Magento\Backend\App\Action;
  8. use Magento\Framework\Registry;
  9. use Magento\Framework\View\Result\PageFactory;
  10. use Magento\Framework\View\Result\LayoutFactory;
  11. use Magento\Sales\Api\OrderPaymentRepositoryInterface;
  12. /**
  13. * Adminhtml sales transactions controller
  14. *
  15. * @author Magento Core Team <core@magentocommerce.com>
  16. */
  17. abstract class Transactions extends \Magento\Backend\App\Action
  18. {
  19. /**
  20. * Authorization level of a basic admin session
  21. *
  22. * @see _isAllowed()
  23. */
  24. const ADMIN_RESOURCE = 'Magento_Sales::transactions';
  25. /**
  26. * Core registry
  27. *
  28. * @var Registry
  29. */
  30. protected $_coreRegistry = null;
  31. /**
  32. * @var PageFactory
  33. */
  34. protected $resultPageFactory;
  35. /**
  36. * @var LayoutFactory
  37. */
  38. protected $resultLayoutFactory;
  39. /**
  40. * @var OrderPaymentRepositoryInterface
  41. */
  42. protected $orderPaymentRepository;
  43. /**
  44. * @param \Magento\Backend\App\Action\Context $context
  45. * @param Registry $coreRegistry
  46. * @param PageFactory $resultPageFactory
  47. * @param LayoutFactory $resultLayoutFactory
  48. * @param OrderPaymentRepositoryInterface $orderPaymentRepository
  49. */
  50. public function __construct(
  51. \Magento\Backend\App\Action\Context $context,
  52. Registry $coreRegistry,
  53. PageFactory $resultPageFactory,
  54. LayoutFactory $resultLayoutFactory,
  55. OrderPaymentRepositoryInterface $orderPaymentRepository
  56. ) {
  57. $this->_coreRegistry = $coreRegistry;
  58. $this->resultPageFactory = $resultPageFactory;
  59. $this->resultLayoutFactory = $resultLayoutFactory;
  60. $this->orderPaymentRepository = $orderPaymentRepository;
  61. parent::__construct($context);
  62. }
  63. /**
  64. * Initialize payment transaction model
  65. *
  66. * @return \Magento\Sales\Model\Order\Payment\Transaction|bool
  67. */
  68. protected function _initTransaction()
  69. {
  70. $txn = $this->_objectManager->create(
  71. \Magento\Sales\Model\Order\Payment\Transaction::class
  72. )->load(
  73. $this->getRequest()->getParam('txn_id')
  74. );
  75. if (!$txn->getId()) {
  76. $this->messageManager->addErrorMessage(__('Please correct the transaction ID and try again.'));
  77. $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
  78. return false;
  79. }
  80. $orderId = $this->getRequest()->getParam('order_id');
  81. if ($orderId) {
  82. $txn->setOrderUrl($this->getUrl('sales/order/view', ['order_id' => $orderId]));
  83. }
  84. $this->_coreRegistry->register('current_transaction', $txn);
  85. return $txn;
  86. }
  87. }