*/ class Mage_Authorizenet_Model_Directpost_Observer { /** * Save order into registry to use it in the overloaded controller. * * @param Varien_Event_Observer $observer * @return Mage_Authorizenet_Model_Directpost_Observer */ public function saveOrderAfterSubmit(Varien_Event_Observer $observer) { /* @var $order Mage_Sales_Model_Order */ $order = $observer->getEvent()->getData('order'); Mage::register('directpost_order', $order, true); return $this; } /** * Set data for response of frontend saveOrder action * * @param Varien_Event_Observer $observer * @return Mage_Authorizenet_Model_Directpost_Observer */ public function addAdditionalFieldsToResponseFrontend(Varien_Event_Observer $observer) { /* @var $order Mage_Sales_Model_Order */ $order = Mage::registry('directpost_order'); if ($order && $order->getId()) { $payment = $order->getPayment(); if ($payment && $payment->getMethod() == Mage::getModel('authorizenet/directpost')->getCode()) { /* @var $controller Mage_Core_Controller_Varien_Action */ $controller = $observer->getEvent()->getData('controller_action'); $result = Mage::helper('core')->jsonDecode( $controller->getResponse()->getBody('default'), Zend_Json::TYPE_ARRAY ); if (empty($result['error'])) { $payment = $order->getPayment(); //if success, then set order to session and add new fields $session = Mage::getSingleton('authorizenet/directpost_session'); $session->addCheckoutOrderIncrementId($order->getIncrementId()); $session->setLastOrderIncrementId($order->getIncrementId()); $requestToPaygate = $payment->getMethodInstance()->generateRequestFromOrder($order); $requestToPaygate->setControllerActionName($controller->getRequest()->getControllerName()); $requestToPaygate->setIsSecure((string)Mage::app()->getStore()->isCurrentlySecure()); $result['directpost'] = array('fields' => $requestToPaygate->getData()); $controller->getResponse()->clearHeader('Location'); $controller->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); } } } return $this; } /** * Update all edit increments for all orders if module is enabled. * Needed for correct work of edit orders in Admin area. * * @param Varien_Event_Observer $observer * @return Mage_Authorizenet_Model_Directpost_Observer */ public function updateAllEditIncrements(Varien_Event_Observer $observer) { /* @var $order Mage_Sales_Model_Order */ $order = $observer->getEvent()->getData('order'); Mage::helper('authorizenet')->updateOrderEditIncrements($order); return $this; } }