0

I am creating an invoice by running cron job after order completion, but it creates an invoice with status 'Paid'. I want invoice to be created with status 'Pending'. This is the code i am using for creating invoice

$invoice = $order->prepareInvoice();
$invoice->register();
Mage::getModel('core/resource_transaction')
    ->addObject($invoice)
    ->addObject($invoice->getOrder())
    ->save();
2

Try this code:

    $capture = Mage_Sales_Model_Order_Invoice::NOT_CAPTURE;
    /** @var Mage_Sales_Model_Order_Invoice $invoice */
    $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
    $invoice->setRequestedCaptureCase($capture);
    $invoice->register();

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

    $transaction->save();

The $capture is one of the Mage_Sales_Model_Order_Invoice predefined values (const):

const CAPTURE_ONLINE   = 'online';
const CAPTURE_OFFLINE  = 'offline';
const NOT_CAPTURE      = 'not_capture';

UPDATE:

If you want to have ability to manage capture of the COD payment method, you need to rewrite the Mage_Payment_Model_Method_Cashondelivery and add to it:

protected $_canCapture = true;

After that you can use "capture case" with no capture value when creating a new invoice and capture that invoice later using the capture button on the invoice view page:

Result

7
  • Same result . Invoice created with status 'Paid' .
    – Seefan
    Apr 29 '16 at 6:34
  • @Nafees What payment method you are using for order? Apr 29 '16 at 6:37
  • Cash on Delivery
    – Seefan
    Apr 29 '16 at 6:38
  • @Nafees Unfortunately it is inaccessible for the COD method, because the COD method can't be captured later by default Apr 29 '16 at 7:15
  • @Nafees I've updated my answer Apr 29 '16 at 7:29

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.