Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Authorizenet_Block_Directpost_Form
  • Mage_Authorizenet_Block_Directpost_Iframe
  • Mage_Authorizenet_Directpost_PaymentController
  • Mage_Authorizenet_Helper_Data
  • Mage_Authorizenet_Model_Directpost
  • Mage_Authorizenet_Model_Directpost_Observer
  • Mage_Authorizenet_Model_Directpost_Request
  • Mage_Authorizenet_Model_Directpost_Response
  • Mage_Authorizenet_Model_Directpost_Session
  • Overview
  • Package
  • Class
  • Tree
  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:  * DirtectPost Payment Controller
 29:  *
 30:  * @category   Mage
 31:  * @package    Mage_Authorizenet
 32:  * @author     Magento Core Team <core@magentocommerce.com>
 33:  */
 34: class Mage_Authorizenet_Directpost_PaymentController extends Mage_Core_Controller_Front_Action
 35: {
 36:     /**
 37:      * @return Mage_Checkout_Model_Session
 38:      */
 39:     protected function _getCheckout()
 40:     {
 41:         return Mage::getSingleton('checkout/session');
 42:     }
 43: 
 44:     /**
 45:      * Get session model
 46: 
 47:      * @return Mage_Authorizenet_Model_Directpost_Session
 48:      */
 49:     protected function _getDirectPostSession()
 50:     {
 51:         return Mage::getSingleton('authorizenet/directpost_session');
 52:     }
 53: 
 54:     /**
 55:      * Get iframe block instance
 56:      *
 57:      * @return Mage_Authorizenet_Block_Directpost_Iframe
 58:      */
 59:     protected function _getIframeBlock()
 60:     {
 61:         return $this->getLayout()->createBlock('directpost/iframe');
 62:     }
 63: 
 64:     /**
 65:      * Response action.
 66:      * Action for Authorize.net SIM Relay Request.
 67:      */
 68:     public function responseAction()
 69:     {
 70:         $data = $this->getRequest()->getPost();
 71:         /* @var $paymentMethod Mage_Authorizenet_Model_DirectPost */
 72:         $paymentMethod = Mage::getModel('authorizenet/directpost');
 73: 
 74:         $result = array();
 75:         if (!empty($data['x_invoice_num'])) {
 76:             $result['x_invoice_num'] = $data['x_invoice_num'];
 77:         }
 78: 
 79:         try {
 80:             if (!empty($data['store_id'])) {
 81:                 $paymentMethod->setStore($data['store_id']);
 82:             }
 83:             $paymentMethod->process($data);
 84:             $result['success'] = 1;
 85:         }
 86:         catch (Mage_Core_Exception $e) {
 87:             Mage::logException($e);
 88:             $result['success'] = 0;
 89:             $result['error_msg'] = $e->getMessage();
 90:         }
 91:         catch (Exception $e) {
 92:             Mage::logException($e);
 93:             $result['success'] = 0;
 94:             $result['error_msg'] = $this->__('There was an error processing your order. Please contact us or try again later.');
 95:         }
 96: 
 97:         if (!empty($data['controller_action_name'])) {
 98:             if (!empty($data['key'])) {
 99:                 $result['key'] = $data['key'];
100:             }
101:             $result['controller_action_name'] = $data['controller_action_name'];
102:             $result['is_secure'] = isset($data['is_secure']) ? $data['is_secure'] : false;
103:             $params['redirect'] = Mage::helper('authorizenet')->getRedirectIframeUrl($result);
104:         }
105:         $block = $this->_getIframeBlock()->setParams($params);
106:         $this->getResponse()->setBody($block->toHtml());
107:     }
108: 
109:     /**
110:      * Retrieve params and put javascript into iframe
111:      *
112:      */
113:     public function redirectAction()
114:     {
115:         $redirectParams = $this->getRequest()->getParams();
116:         $params = array();
117:         if (!empty($redirectParams['success'])
118:             && isset($redirectParams['x_invoice_num'])
119:             && isset($redirectParams['controller_action_name'])
120:         ) {
121:             $this->_getDirectPostSession()->unsetData('quote_id');
122:             $params['redirect_parent'] = Mage::helper('authorizenet')->getSuccessOrderUrl($redirectParams);
123:         }
124:         if (!empty($redirectParams['error_msg'])) {
125:             $cancelOrder = empty($redirectParams['x_invoice_num']);
126:             $this->_returnCustomerQuote($cancelOrder, $redirectParams['error_msg']);
127:         }
128:         $block = $this->_getIframeBlock()->setParams(array_merge($params, $redirectParams));
129:         $this->getResponse()->setBody($block->toHtml());
130:     }
131: 
132:     /**
133:      * Send request to authorize.net
134:      *
135:      */
136:     public function placeAction()
137:     {
138:         $paymentParam = $this->getRequest()->getParam('payment');
139:         $controller = $this->getRequest()->getParam('controller');
140:         if (isset($paymentParam['method'])) {
141:             $params = Mage::helper('authorizenet')->getSaveOrderUrlParams($controller);
142:             $this->_getDirectPostSession()->setQuoteId($this->_getCheckout()->getQuote()->getId());
143:             $this->_forward(
144:                 $params['action'],
145:                 $params['controller'],
146:                 $params['module'],
147:                 $this->getRequest()->getParams()
148:             );
149:         } else {
150:             $result = array(
151:                 'error_messages' => $this->__('Please, choose payment method'),
152:                 'goto_section'   => 'payment'
153:             );
154:             $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
155:         }
156:     }
157: 
158:     /**
159:      * Return customer quote by ajax
160:      *
161:      */
162:     public function returnQuoteAction()
163:     {
164:         $this->_returnCustomerQuote();
165:         $this->getResponse()->setBody(Mage::helper('core')->jsonEncode(array('success' => 1)));
166:     }
167: 
168:     /**
169:      * Return customer quote
170:      *
171:      * @param bool $cancelOrder
172:      * @param string $errorMsg
173:      */
174:     protected function _returnCustomerQuote($cancelOrder = false, $errorMsg = '')
175:     {
176:         $incrementId = $this->_getDirectPostSession()->getLastOrderIncrementId();
177:         if ($incrementId &&
178:             $this->_getDirectPostSession()
179:                 ->isCheckoutOrderIncrementIdExist($incrementId)
180:         ) {
181:             /* @var $order Mage_Sales_Model_Order */
182:             $order = Mage::getModel('sales/order')->loadByIncrementId($incrementId);
183:             if ($order->getId()) {
184:                 $quote = Mage::getModel('sales/quote')
185:                     ->load($order->getQuoteId());
186:                 if ($quote->getId()) {
187:                     $quote->setIsActive(1)
188:                         ->setReservedOrderId(NULL)
189:                         ->save();
190:                     $this->_getCheckout()->replaceQuote($quote);
191:                 }
192:                 $this->_getDirectPostSession()->removeCheckoutOrderIncrementId($incrementId);
193:                 $this->_getDirectPostSession()->unsetData('quote_id');
194:                 if ($cancelOrder) {
195:                     $order->registerCancellation($errorMsg)->save();
196:                 }
197:             }
198:         }
199:     }
200: }
201: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0