I have a function which is creating an invoice, just the status of the invoice created is "pending". How can I create the invoice with the status "Complete"?
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
if (!$invoice->getTotalQty())
Mage::throwException(Mage::helper('core')->__('Cannot create an invoice without products.'));
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::STATE_PAID);
$invoice->register();
$transactionSave = Mage::getModel('core/resource_transaction')
->addObject($invoice)
->addObject($invoice->getOrder());
$transactionSave->save();
CE 1.9