Magento 1.9 – Create Invoice Not Paid Issue

ce-1.9.0.1event-observerinvoice

I followed this to create an invoice for an order and it worked. But the created newly invoice is marked as paid. Can I created it as unpaid?

$invoice = $order->prepareInvoice();
$invoice->register();
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();

Best Answer

You can use the sales/order_invoice_api to create an invoice for your order. Depending on the settings of the payment method the invoice will be marked as Paid or Pending.

if the payment method has specified:

protected $_canCapture                  = true;
protected $_canCapturePartial           = true;

it is possible to create an invoice that has the state 'Pending' with the following code:

$emailInvoice = true;
$captureInvoice = false;

$invoiceApi = Mage::getModel('sales/order_invoice_api');
$invoiceId = $invoiceApi->create(
    $order->getIncrementId(),
    array(),
    Mage::helper('sales')->__('Invoice created!'),
    $emailInvoice,
    false
);

if ($captureInvoice) {
    $invoiceApi->capture($invoiceId);
}
Related Topic