3

I have used Magento version 1.9, when order is placed then order status is pending. when submit invoice then order status changes to processing but invoice status is showing paid.

But I want to change invoice status paid to pending_payment while order status processing and when ship order then invoice status change to paid.

How to do that?

  • My invoice[capture_case] was missing in invoice create form. I have added invoice[capture_case] in invoice form. Now there is no problem with creating invoice. – Vinaya Maheshwari Mar 31 '16 at 11:42
  • Processing status means that the payment method has been captured. If you want your status to be pending, you should ensure that your payment method doesn't get captured/charged in the processing of creating your invoice. This is likely to be a configuration issue, and you should not hack up the Magento orders/payments framework to undo business logic like this - you will regret it later on. – Robbie Averill Jun 14 '16 at 7:58
-1

Solution 1

Working with an existing invoice

To change an existing invoice status from paid to pending is actually quite simple despite all the complexity built around it.

To do this, pay no attention to the invoice status but focus solely on the invoice state. All you have to do is change the invoice state to the new desired state and the status gets updated as well.

Since the invoice has already been paid for, you probably want to reset the total_paid and base_total_paid fields of the particular order the invoice was for so you at some point later on mark it as paid.

This should do just that:

<?php

    $incrementId = '100014637';
    $invoiceModel = Mage::getModel('sales/order_invoice');
    try {
        $invoice = $invoiceModel->loadByIncrementId($incrementId);
        $order = Mage::getModel('sales/order')->load((int)$invoice->getOrderId());
        $order->setTotalPaid(0)
                ->setBaseTotalPaid(0)
                ->save();

        $invoice->setState(1)
                ->save();
    } catch (Exception $ex) {
        var_dump($ex->getMessage()); die;
    }

To later mark it as paid on shipping, all you need do is simply get the invoice and call the pay method on it.

Solution 2

Working with a new invoice

In order to create a pending invoice, the payment method you use for the order must allow you to do such. For that you need to override the payment method model and add these membere:

protected $_canCapture = true; // sets state to open
protected $_canCapturePartial = true; // lets you invoice partially

For example if you want to do this for Check/money order or Cash On Delivery you need to override either app/code/core/Mage/Payment/Model/Method/Checkmo.php or app/code/core/Mage/Payment/Model/Method/Cashondelivery.php and add the above attribute.

After this when you create an invoice you will have an option near the save button to set the invoice status. To create a pending invoice select Not capture as seen below.

enter image description here

If you want to mark it later as paid edit the invoice and between the buttons on to one called Capture.

enter image description here

Since what you want to do is mark it as paid on shipping, all you need do is simply get the invoice and call the pay method on it.

Hope it helps someone.

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.