Detail.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Block\Adminhtml\Transactions;
  7. use Magento\Sales\Api\OrderPaymentRepositoryInterface;
  8. /**
  9. * Adminhtml transaction detail
  10. *
  11. * @api
  12. * @author Magento Core Team <core@magentocommerce.com>
  13. * @since 100.0.2
  14. */
  15. class Detail extends \Magento\Backend\Block\Widget\Container
  16. {
  17. /**
  18. * Transaction model
  19. *
  20. * @var \Magento\Sales\Model\Order\Payment\Transaction
  21. */
  22. protected $_txn;
  23. /**
  24. * Core registry
  25. *
  26. * @var \Magento\Framework\Registry
  27. */
  28. protected $_coreRegistry = null;
  29. /**
  30. * @var \Magento\Sales\Helper\Admin
  31. */
  32. private $adminHelper;
  33. /**
  34. * @var OrderPaymentRepositoryInterface
  35. */
  36. protected $orderPaymentRepository;
  37. /**
  38. * @param \Magento\Backend\Block\Widget\Context $context
  39. * @param \Magento\Framework\Registry $registry
  40. * @param \Magento\Sales\Helper\Admin $adminHelper
  41. * @param \Magento\Sales\Api\OrderPaymentRepositoryInterface $orderPaymentRepository
  42. * @param array $data
  43. */
  44. public function __construct(
  45. \Magento\Backend\Block\Widget\Context $context,
  46. \Magento\Framework\Registry $registry,
  47. \Magento\Sales\Helper\Admin $adminHelper,
  48. OrderPaymentRepositoryInterface $orderPaymentRepository,
  49. array $data = []
  50. ) {
  51. $this->_coreRegistry = $registry;
  52. $this->adminHelper = $adminHelper;
  53. $this->orderPaymentRepository = $orderPaymentRepository;
  54. parent::__construct($context, $data);
  55. }
  56. /**
  57. * Add control buttons
  58. *
  59. * @return void
  60. */
  61. protected function _construct()
  62. {
  63. parent::_construct();
  64. $this->_txn = $this->_coreRegistry->registry('current_transaction');
  65. if (!$this->_txn) {
  66. return;
  67. }
  68. $backUrl = $this->_txn->getOrderUrl() ? $this->_txn->getOrderUrl() : $this->getUrl('sales/*/');
  69. $this->buttonList->add(
  70. 'back',
  71. ['label' => __('Back'), 'onclick' => "setLocation('{$backUrl}')", 'class' => 'back']
  72. );
  73. $fetchTransactionAllowed = $this->_authorization->isAllowed('Magento_Sales::transactions_fetch');
  74. $canFetchTransaction = $this->orderPaymentRepository->get($this->_txn->getPaymentId())
  75. ->getMethodInstance()
  76. ->canFetchTransactionInfo();
  77. if ($fetchTransactionAllowed && $canFetchTransaction) {
  78. $fetchUrl = $this->getUrl('sales/*/fetch', ['_current' => true]);
  79. $this->buttonList->add(
  80. 'fetch',
  81. ['label' => __('Fetch'), 'onclick' => "setLocation('{$fetchUrl}')", 'class' => 'button']
  82. );
  83. }
  84. }
  85. /**
  86. * Retrieve header text
  87. *
  88. * @return \Magento\Framework\Phrase
  89. */
  90. public function getHeaderText()
  91. {
  92. return __(
  93. "Transaction # %1 | %2",
  94. $this->_txn->getTxnId(),
  95. $this->formatDate(
  96. $this->_txn->getCreatedAt(),
  97. \IntlDateFormatter::MEDIUM,
  98. true
  99. )
  100. );
  101. }
  102. /**
  103. * Render block html
  104. *
  105. * @return string
  106. */
  107. protected function _toHtml()
  108. {
  109. $this->setTxnIdHtml($this->adminHelper->escapeHtmlWithLinks(
  110. $this->_txn->getHtmlTxnId(),
  111. ['a']
  112. ));
  113. $this->setParentTxnIdUrlHtml(
  114. $this->escapeHtml($this->getUrl('sales/transactions/view', ['txn_id' => $this->_txn->getParentId()]))
  115. );
  116. $this->setParentTxnIdHtml($this->escapeHtml($this->_txn->getParentTxnId()));
  117. $this->setOrderIncrementIdHtml($this->escapeHtml($this->_txn->getOrder()->getIncrementId()));
  118. $this->setTxnTypeHtml($this->escapeHtml(__($this->_txn->getTxnType())));
  119. $this->setOrderIdUrlHtml(
  120. $this->escapeHtml($this->getUrl('sales/order/view', ['order_id' => $this->_txn->getOrderId()]))
  121. );
  122. $this->setIsClosedHtml($this->_txn->getIsClosed() ? __('Yes') : __('No'));
  123. $createdAt = strtotime(
  124. $this->_txn->getCreatedAt()
  125. ) ? $this->formatDate(
  126. $this->_txn->getCreatedAt(),
  127. \IntlDateFormatter::MEDIUM,
  128. true
  129. ) : __(
  130. 'N/A'
  131. );
  132. $this->setCreatedAtHtml($this->escapeHtml($createdAt));
  133. return parent::_toHtml();
  134. }
  135. }