123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Sales\Block\Adminhtml\Transactions;
- use Magento\Sales\Api\OrderPaymentRepositoryInterface;
- /**
- * Adminhtml transaction detail
- *
- * @api
- * @author Magento Core Team <core@magentocommerce.com>
- * @since 100.0.2
- */
- class Detail extends \Magento\Backend\Block\Widget\Container
- {
- /**
- * Transaction model
- *
- * @var \Magento\Sales\Model\Order\Payment\Transaction
- */
- protected $_txn;
- /**
- * Core registry
- *
- * @var \Magento\Framework\Registry
- */
- protected $_coreRegistry = null;
- /**
- * @var \Magento\Sales\Helper\Admin
- */
- private $adminHelper;
- /**
- * @var OrderPaymentRepositoryInterface
- */
- protected $orderPaymentRepository;
- /**
- * @param \Magento\Backend\Block\Widget\Context $context
- * @param \Magento\Framework\Registry $registry
- * @param \Magento\Sales\Helper\Admin $adminHelper
- * @param \Magento\Sales\Api\OrderPaymentRepositoryInterface $orderPaymentRepository
- * @param array $data
- */
- public function __construct(
- \Magento\Backend\Block\Widget\Context $context,
- \Magento\Framework\Registry $registry,
- \Magento\Sales\Helper\Admin $adminHelper,
- OrderPaymentRepositoryInterface $orderPaymentRepository,
- array $data = []
- ) {
- $this->_coreRegistry = $registry;
- $this->adminHelper = $adminHelper;
- $this->orderPaymentRepository = $orderPaymentRepository;
- parent::__construct($context, $data);
- }
- /**
- * Add control buttons
- *
- * @return void
- */
- protected function _construct()
- {
- parent::_construct();
- $this->_txn = $this->_coreRegistry->registry('current_transaction');
- if (!$this->_txn) {
- return;
- }
- $backUrl = $this->_txn->getOrderUrl() ? $this->_txn->getOrderUrl() : $this->getUrl('sales/*/');
- $this->buttonList->add(
- 'back',
- ['label' => __('Back'), 'onclick' => "setLocation('{$backUrl}')", 'class' => 'back']
- );
- $fetchTransactionAllowed = $this->_authorization->isAllowed('Magento_Sales::transactions_fetch');
- $canFetchTransaction = $this->orderPaymentRepository->get($this->_txn->getPaymentId())
- ->getMethodInstance()
- ->canFetchTransactionInfo();
- if ($fetchTransactionAllowed && $canFetchTransaction) {
- $fetchUrl = $this->getUrl('sales/*/fetch', ['_current' => true]);
- $this->buttonList->add(
- 'fetch',
- ['label' => __('Fetch'), 'onclick' => "setLocation('{$fetchUrl}')", 'class' => 'button']
- );
- }
- }
- /**
- * Retrieve header text
- *
- * @return \Magento\Framework\Phrase
- */
- public function getHeaderText()
- {
- return __(
- "Transaction # %1 | %2",
- $this->_txn->getTxnId(),
- $this->formatDate(
- $this->_txn->getCreatedAt(),
- \IntlDateFormatter::MEDIUM,
- true
- )
- );
- }
- /**
- * Render block html
- *
- * @return string
- */
- protected function _toHtml()
- {
- $this->setTxnIdHtml($this->adminHelper->escapeHtmlWithLinks(
- $this->_txn->getHtmlTxnId(),
- ['a']
- ));
- $this->setParentTxnIdUrlHtml(
- $this->escapeHtml($this->getUrl('sales/transactions/view', ['txn_id' => $this->_txn->getParentId()]))
- );
- $this->setParentTxnIdHtml($this->escapeHtml($this->_txn->getParentTxnId()));
- $this->setOrderIncrementIdHtml($this->escapeHtml($this->_txn->getOrder()->getIncrementId()));
- $this->setTxnTypeHtml($this->escapeHtml(__($this->_txn->getTxnType())));
- $this->setOrderIdUrlHtml(
- $this->escapeHtml($this->getUrl('sales/order/view', ['order_id' => $this->_txn->getOrderId()]))
- );
- $this->setIsClosedHtml($this->_txn->getIsClosed() ? __('Yes') : __('No'));
- $createdAt = strtotime(
- $this->_txn->getCreatedAt()
- ) ? $this->formatDate(
- $this->_txn->getCreatedAt(),
- \IntlDateFormatter::MEDIUM,
- true
- ) : __(
- 'N/A'
- );
- $this->setCreatedAtHtml($this->escapeHtml($createdAt));
- return parent::_toHtml();
- }
- }
|