2

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();

1 Answer 1

3

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);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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