Magento – How to Invoice and Capture Multiple Orders

magento-1.7magento-1.8magento-enterprise

We're using Authorization, then Capture method for Credit Card payments. After we've quickly glanced over a batch of orders we'd like to invoice them all at once.

Step 1: Invoicing is easy. "Sales" -> "Orders". Click on the orders you'd like to invoice. Go to "Actions [Invoice]". "Submit". Multiple orders have just been invoiced!

Step 2 (Capturing) is the problem — none of the invoices get Captured and the created invoices are given the status "Pending". From the "Sales"->"Invoices" lists, we can manually click into each Invoice, we can click the option "Capture" and that works . We can also go to "Sales" -> "Orders" and click "Invoice" and that will capture as well. But clicking into the orders manually kind of defeats the purpose of Step 1.

Is there some sort of Pending Invoice scheduler that captures pending CC invoices and I'm not aware of it??

Best Answer

Currently, this functionality doesn't exist but there are plugins that do it. However, if you're feeling fancy you can run some code that will capture all invoices from orders that are in a pending status:

<?php

require('app/Mage.php');
Mage::app();

$_helper = Mage::helper('core');

$orders = Mage::getModel('sales/order')
            ->getCollection()
            ->addAttributeToFilter('status',array('eq'=>'pending'));

foreach($orders as $order){

    try {
        if(!$order->canInvoice()){
            Mage::throwException($_helper->__('Cannot create an invoice.'));
        }
        $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
        if (!$invoice->getTotalQty()){
            Mage::throwException($_helper->__('Cannot create an invoice without products.'));
        }

        $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
        $invoice->register();

        $transactionSave = Mage::getModel('core/resource_transaction')
            ->addObject($invoice)
            ->addObject($invoice->getOrder());

        $transactionSave->save();
    } catch (Mage_Core_Exception $e) {
        //do something meaningful here?
        Mage::logException($e->getMessage());
    }

}

Source (invoice capture portion) Inchoo: http://inchoo.net/ecommerce/magento/how-to-create-magento-invoice-from-order/

Related Topic