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_Authorizenet
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: * Authorizenet Data Helper
29: *
30: * @category Mage
31: * @package Mage_Authorizenet
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Authorizenet_Helper_Data extends Mage_Core_Helper_Abstract
35: {
36: /**
37: * Return URL for admin area
38: *
39: * @param string $route
40: * @param array $params
41: * @return string
42: */
43: public function getAdminUrl($route, $params)
44: {
45: return Mage::getModel('adminhtml/url')->getUrl($route, $params);
46: }
47:
48: /**
49: * Set secure url checkout is secure for current store.
50: *
51: * @param string $route
52: * @param array $params
53: * @return string
54: */
55: protected function _getUrl($route, $params = array())
56: {
57: $params['_type'] = Mage_Core_Model_Store::URL_TYPE_LINK;
58: if (isset($params['is_secure'])) {
59: $params['_secure'] = (bool)$params['is_secure'];
60: } elseif (Mage::app()->getStore()->isCurrentlySecure()) {
61: $params['_secure'] = true;
62: }
63: return parent::_getUrl($route, $params);
64: }
65:
66: /**
67: * Retrieve save order url params
68: *
69: * @param string $controller
70: * @return array
71: */
72: public function getSaveOrderUrlParams($controller)
73: {
74: $route = array();
75: switch ($controller) {
76: case 'onepage':
77: $route['action'] = 'saveOrder';
78: $route['controller'] = 'onepage';
79: $route['module'] = 'checkout';
80: break;
81:
82: case 'sales_order_create':
83: case 'sales_order_edit':
84: $route['action'] = 'save';
85: $route['controller'] = 'sales_order_create';
86: $route['module'] = 'admin';
87: break;
88:
89: default:
90: break;
91: }
92:
93: return $route;
94: }
95:
96: /**
97: * Retrieve redirect ifrmae url
98: *
99: * @param array params
100: * @return string
101: */
102: public function getRedirectIframeUrl($params)
103: {
104: switch ($params['controller_action_name']) {
105: case 'onepage':
106: $route = 'authorizenet/directpost_payment/redirect';
107: break;
108:
109: case 'sales_order_create':
110: case 'sales_order_edit':
111: $route = 'adminhtml/authorizenet_directpost_payment/redirect';
112: break;
113:
114: default:
115: $route = 'authorizenet/directpost_payment/redirect';
116: break;
117: }
118:
119: return $this->_getUrl($route, $params);
120: }
121:
122: /**
123: * Retrieve place order url on front
124: *
125: * @return string
126: */
127: public function getPlaceOrderFrontUrl()
128: {
129: return $this->_getUrl('authorizenet/directpost_payment/place');
130: }
131:
132: /**
133: * Retrieve place order url in admin
134: *
135: * @return string
136: */
137: public function getPlaceOrderAdminUrl()
138: {
139: return $this->getAdminUrl('*/authorizenet_directpost_payment/place', array());
140: }
141:
142: /**
143: * Retrieve place order url
144: *
145: * @param array params
146: * @return string
147: */
148: public function getSuccessOrderUrl($params)
149: {
150: $param = array();
151: switch ($params['controller_action_name']) {
152: case 'onepage':
153: $route = 'checkout/onepage/success';
154: break;
155:
156: case 'sales_order_create':
157: case 'sales_order_edit':
158: $route = 'adminhtml/sales_order/view';
159: $order = Mage::getModel('sales/order')->loadByIncrementId($params['x_invoice_num']);
160: $param['order_id'] = $order->getId();
161: return $this->getAdminUrl($route, $param);
162:
163: default :
164: $route = 'checkout/onepage/success';
165: break;
166: }
167:
168: return $this->_getUrl($route, $param);
169: }
170:
171: /**
172: * Get controller name
173: *
174: * @return string
175: */
176: public function getControllerName()
177: {
178: return Mage::app()->getFrontController()->getRequest()->getControllerName();
179: }
180:
181: /**
182: * Update all child and parent order's edit increment numbers.
183: * Needed for Admin area.
184: *
185: * @param Mage_Sales_Model_Order $order
186: */
187: public function updateOrderEditIncrements(Mage_Sales_Model_Order $order)
188: {
189: if ($order->getId() && $order->getOriginalIncrementId()) {
190: $collection = $order->getCollection();
191: $quotedIncrId = $collection->getConnection()->quote($order->getOriginalIncrementId());
192: $collection->getSelect()->where(
193: "original_increment_id = {$quotedIncrId} OR increment_id = {$quotedIncrId}"
194: );
195:
196: foreach ($collection as $orderToUpdate) {
197: $orderToUpdate->setEditIncrement($order->getEditIncrement());
198: $orderToUpdate->save();
199: }
200: }
201: }
202: }
203: