Fetch.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Sales\Controller\Adminhtml\Transactions;
  8. use Magento\Backend\App\Action;
  9. use Magento\Backend\Model\View\Result\Redirect;
  10. use Magento\Framework\Controller\ResultFactory;
  11. class Fetch extends \Magento\Sales\Controller\Adminhtml\Transactions
  12. {
  13. /**
  14. * Authorization level of a basic admin session
  15. *
  16. * @see _isAllowed()
  17. */
  18. const ADMIN_RESOURCE = 'Magento_Sales::transactions_fetch';
  19. /**
  20. * Fetch transaction details action
  21. *
  22. * @return Redirect
  23. */
  24. public function execute()
  25. {
  26. $txn = $this->_initTransaction();
  27. /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
  28. $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
  29. if (!$txn) {
  30. return $resultRedirect->setPath('sales/*/');
  31. }
  32. try {
  33. $this->orderPaymentRepository
  34. ->get($txn->getPaymentId())
  35. ->setOrder($txn->getOrder())
  36. ->importTransactionInfo($txn);
  37. $txn->save();
  38. $this->messageManager->addSuccessMessage(__('The transaction details have been updated.'));
  39. } catch (\Magento\Framework\Exception\LocalizedException $e) {
  40. $this->messageManager->addErrorMessage($e->getMessage());
  41. } catch (\Exception $e) {
  42. $this->messageManager->addErrorMessage(__('We can\'t update the transaction details.'));
  43. $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
  44. }
  45. return $resultRedirect->setPath('sales/transactions/view', ['_current' => true]);
  46. }
  47. }