public function sales_order_place_after($event) { $order = $event->getOrder(); $doTheStuff = true; //in_array($order->getPayment()->getMethodInstance()->getCode(), Mage::getStoreConfig('evoc/order/auto_invoicing_payment_methods')); // Mage::getModel('payment/config')->getAllMethods(); if ($doTheStuff) { if ($order->canInvoice()) { $invoice = $order->prepareInvoice(); $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE); $invoice->register(); $invoice->getOrder()->setCustomerNoteNotify(false); $invoice->getOrder()->setIsInProcess(true); $order->addStatusHistoryComment('Automatically invoiced by EVO Connector', false); Mage::getModel('core/resource_transaction')->addObject($invoice)->addObject($invoice->getOrder())->save(); $invoice->sendEmail(true, ''); $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true); $order->save(); } else { Vikont_EVOConnector_Model_Log::logWarning(sprintf('Order #%s cannot be invoiced', $order->getIncrementId())); } } return $this; }
public function postauthAction() { $this->_authenticate(); $orderHelper = Mage::helper('evoc/order'); Vikont_EVOConnector_Model_Log::log(sprintf('postAuth action, request is: %s', $_SERVER['REQUEST_URI'])); $marker = 'evoc/index/postauth/'; $paramURIPart = trim(substr($_SERVER['REQUEST_URI'], strlen($marker) + stripos($_SERVER['REQUEST_URI'], $marker)), '/'); $parts = explode('/', $paramURIPart); if (count($parts) >= 3) { list($orderId, $paymentId, $amount) = $parts; $comment = sprintf('Post Authorization for %s %s %s', $orderId, $paymentId, $amount); $orderHelper->addOrderComment($orderId, $comment); $orderHelper->sendAcknowledgeResponse('SUCCESS'); return; } else { Vikont_EVOConnector_Model_Log::log(sprintf('not enough parameters, %d of required 3 passed: %s', count($parts), $_SERVER['REQUEST_URI'])); $orderHelper->sendAcknowledgeResponse('FAILURE'); } }
public static function parseXML($xmlText) { libxml_use_internal_errors(true); $xml = simplexml_load_string($xmlText); if (!$xml) { Vikont_EVOConnector_Model_Log::log('XML parsing errors: '); foreach (libxml_get_errors() as $error) { Vikont_EVOConnector_Model_Log::log("\t" . trim($error->message, " \n\\l\t")); } Vikont_EVOConnector_Model_Log::log('XML text:' . ($xmlText ? "\n" . $xmlText : ' empty')); } return $xml; }
public function orderVoid($orderId, $requestXML) { /** <order> <action>VOID</action> <date>2013-06-05 13:39:34.406</date> <reason>Phone void</reason> </order> /**/ if ('order' != strtolower((string) $requestXML->getName()) || 'void' != strtolower((string) $requestXML->action)) { $this->sendAcknowledgeResponse('FAILURE'); return; } $message = sprintf('EVO VOID request to order #%s at %s, reason: %s', $orderId, (string) $requestXML->date, (string) $requestXML->reason); try { $order = Mage::getModel('sales/order')->loadByIncrementId($orderId); if (!$order->getId()) { Vikont_EVOConnector_Model_Log::log(sprintf('ERROR: order does not exist at %s', $message)); $this->sendAcknowledgeResponse('FAILURE'); return; } if ($order->canCancel()) { $order->getPayment()->cancel(); $order->registerCancellation($message, false); // let's raise an exception in case anything's wrong Mage::dispatchEvent('order_cancel_after', array('order' => $this)); $order->save(); Vikont_EVOConnector_Model_Log::log(sprintf('SUCCESS cancel on %s', $message)); $this->sendAcknowledgeResponse('SUCCESS'); return; } else { if ($order->canCreditmemo()) { $result = Mage::helper('evoc/creditmemo')->creditMemo($order, $message); if ($result) { Vikont_EVOConnector_Model_Log::log(sprintf('SUCCESS credit memo on %s', $message)); $this->sendAcknowledgeResponse('SUCCESS'); } else { Vikont_EVOConnector_Model_Log::log(sprintf('ERROR credit memo on %s', $message)); $this->sendAcknowledgeResponse('FAILURE'); } return; } } $this->changeOrderState($order, Mage_Sales_Model_Order::STATE_CANCELED, 'canceled', $message); $this->sendAcknowledgeResponse('SUCCESS'); } catch (Exception $e) { Mage::logException($e); Vikont_EVOConnector_Model_Log::log(sprintf('%s ERROR: %s', $message, $e->getMessage())); } }