I'm creating invoices programmatically by an own observer for the sales_order_save_after event.
Unfortunately, the invoice is immediately marked as paid.
How can I achieve that the new invoice is still open and a admin has to set it to paid state?
My code so far:
$invoiceId = Mage::getModel('sales/order_invoice_api')
->create($order->getIncrementId(), array());
$invoice = Mage::getModel('sales/order_invoice')
->loadByIncrementId($invoiceId);
$invoice->capture()->save();
EDIT: To make my comment to urfusion's answer understandable, here the code snippet:
public function order_placed($observer) {
$event = $observer->getEvent();
// ....
$emailInvoice = false;
$captureInvoice = false;
$order = Mage::getModel("sales/order")->load($data['entity_id']);
if($order->canInvoice() and $order->getIncrementId())
{
$invoiceApi = Mage::getModel('sales/order_invoice_api');
$invoiceId = $invoiceApi->create(
$order->getIncrementId(),
array(),
Mage::Helper('sales')->__('Pending Invoice created!'),
$emailInvoice,
false);
if($captureInvoice) {
$invoiceApi->capture($invoiceId);
}
}
}
After urfusion's answer was not working for me (after I couldn't use the two protected $_canCapture(Partial) = true; lines) I tried to find out more about the two protected variables.
I found them in app/code/core/Mage/Payment/Model/Method/Abstract.php. Since this class is abtract, I couldn't rewrite it globally, which is maybe good, since I would interfere with other payment methods.
For now, I just need the "unpaid invoice creation" for the payment method banktransfer (app/code/core/Mage/Payment/Model/Method/Banktransfer.php) which is extending the abstract class.
What did I do now to solve my problem?
Creating my own module to rewrite the class Mage_Payment_Model_Method_Banktransfer.
In the following, {MY_COMPANY/NAMESPACE} is a placeholder and can be replaced by your company name or some other namespace name in which your module will be placed.
1) Create the folder app/code/local/{MY_COMPANY/NAMESPACE}/Payment/
2) Create subfolder etc/ with file config.xml:
3) Create subfolder Model/Method/ with file Banktransfer.php to just override the two variables and inheritate all the rest of the original class:
4) Activate the module by adding {MY_COMPANY/NAMESPACE}_Payment.xml to app/etc/modules/
mainly it depend on the payment method settings that your invoice will be set as
paid
orpending
.if the payment method has specified:
check the below code for setting invoice as pending.