1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Adminhtml
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Adminhtml sales transactions controller
29: *
30: * @author Magento Core Team <core@magentocommerce.com>
31: */
32: class Mage_Adminhtml_Sales_TransactionsController extends Mage_Adminhtml_Controller_Action
33: {
34: /**
35: * Initialize payment transaction model
36: *
37: * @return Mage_Sales_Model_Order_Payment_Transaction | bool
38: */
39: protected function _initTransaction()
40: {
41: $txn = Mage::getModel('sales/order_payment_transaction')->load(
42: $this->getRequest()->getParam('txn_id')
43: );
44:
45: if (!$txn->getId()) {
46: $this->_getSession()->addError($this->__('Wrong transaction ID specified.'));
47: $this->_redirect('*/*/');
48: $this->setFlag('', self::FLAG_NO_DISPATCH, true);
49: return false;
50: }
51: $orderId = $this->getRequest()->getParam('order_id');
52: if ($orderId) {
53: $txn->setOrderUrl(
54: $this->getUrl('*/sales_order/view', array('order_id' => $orderId))
55: );
56: }
57:
58: Mage::register('current_transaction', $txn);
59: return $txn;
60: }
61:
62: public function indexAction()
63: {
64: $this->_title($this->__('Sales'))
65: ->_title($this->__('Transactions'));
66:
67: $this->loadLayout()
68: ->_setActiveMenu('sales/transactions')
69: ->renderLayout();
70: }
71:
72: /**
73: * Ajax grid action
74: */
75: public function gridAction()
76: {
77: $this->loadLayout(false);
78: $this->renderLayout();
79: }
80:
81: /**
82: * View Transaction Details action
83: */
84: public function viewAction()
85: {
86: $txn = $this->_initTransaction();
87: if (!$txn) {
88: return;
89: }
90: $this->_title($this->__('Sales'))
91: ->_title($this->__('Transactions'))
92: ->_title(sprintf("#%s", $txn->getTxnId()));
93:
94: $this->loadLayout()
95: ->_setActiveMenu('sales/transactions')
96: ->renderLayout();
97: }
98:
99: /**
100: * Fetch transaction details action
101: */
102: public function fetchAction()
103: {
104: $txn = $this->_initTransaction();
105: if (!$txn) {
106: return;
107: }
108: try {
109: $txn->getOrderPaymentObject()
110: ->setOrder($txn->getOrder())
111: ->importTransactionInfo($txn);
112: $txn->save();
113: Mage::getSingleton('adminhtml/session')->addSuccess(
114: Mage::helper('adminhtml')->__('The transaction details have been updated.')
115: );
116: } catch (Mage_Core_Exception $e) {
117: Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
118: } catch (Exception $e) {
119: Mage::getSingleton('adminhtml/session')->addError(
120: Mage::helper('adminhtml')->__('Unable to update transaction details.')
121: );
122: Mage::logException($e);
123: }
124: $this->_redirect('*/sales_transactions/view', array('_current' => true));
125: }
126:
127: /**
128: * Check currently called action by permissions for current user
129: *
130: */
131: protected function _isAllowed()
132: {
133: switch ($this->getRequest()->getActionName()) {
134: case 'fetch':
135: return Mage::getSingleton('admin/session')->isAllowed('sales/transactions/fetch');
136: break;
137: default:
138: return Mage::getSingleton('admin/session')->isAllowed('sales/transactions');
139: break;
140: }
141: }
142: }
143: