Magento 1.9.X

Need a code to do the following: Run function "Get Payment Update" for each order that has status "Pending Payment Review" if order on authorize.net is approved, save order and update order status to Processing.

I could then set up the cron to run above function every hour or so.

Here is the code I have right now, but I had this code running for just changing all Order statuses to Processing, which is not convenient:

     include_once './app/Mage.php';

     $orders = Mage::getModel('sales/order')->getCollection()
     ->addFieldToFilter('status', array('nin' => array('pending_payment','payment_review')));

     foreach ($orders as $order) {
        $orderId = $order->getId();
        $fullOrder = Mage::getModel('sales/order')->load($orderId);
        $fullOrder->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true);
        $fullOrder->setStatus('processing', false);

        try {
          if(!$fullOrder->canInvoice()) {
             Mage::throwException(Mage::helper('core')->__('Cannot create an invoice.'));
          $invoice = Mage::getModel('sales/service_order', $fullOrder)->prepareInvoice();
          if (!$invoice->getTotalQty()) {
             Mage::throwException(Mage::helper('core')->__('Cannot create an invoice without products.'));
          $transactionSave = Mage::getModel('core/resource_transaction')->addObject($invoice)->addObject($invoice->getOrder());
        catch (Mage_Core_Exception $e) {


Thanks in advance!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.