3

I'm using a custom payment module Billdesk and I want the order status to be processing automatically when payment is completed using this module. In all other cases order status should be pending which is available in Magento by default.

While using Billdesk module if there is a due amount in that case also, I want order status to be pending by default. Here is my observer function for checkout_onepage_controller_success_action event

 <?php
class Embitel_Billdesk_Model_Observer {
    public function updateStatus($observer){        
        $order_id=Mage::getSingleton('checkout/session')->getLastOrderId(); 
        $order = Mage::getModel('sales/order')->load($order_id);           

        if($order_id){
        $order = Mage::getModel('sales/order')->load($order_id);
        $payment_method_code = $order->getPayment()->getMethodInstance()->getCode();

            if('embitel_billdesk' == $payment_method_code ){
            $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true)->save();
            }
        }
    }
}

I'm not sure, how I can add the validation that order status will be set to processing when card type is credit and there is no due amount. Is there a way to check the due amount on frontend? If I'm using credit cart, will the order amount be the due amount?

2 Answers 2

1

I can give you an example how to add additional status to existed payment method.

Magento by default in system / configuration has such as 'New Order Status'.

Let's look at SavedCC:

enter image description here

Now we change system.xml file.

Original:

                    <order_status translate="label">
                        <label>New Order Status</label>
                        <frontend_type>select</frontend_type>
                        <source_model>adminhtml/system_config_source_order_status_new</source_model>
                        <sort_order>2</sort_order>
                        <show_in_default>1</show_in_default>
                        <show_in_website>1</show_in_website>
                        <show_in_store>0</show_in_store>
                    </order_status>

You need to replace

<source_model>adminhtml/system_config_source_order_status_new</source_model>

with:

<source_model>adminhtml/system_config_source_order_status_newprocessing</source_model>

And you will get:

enter image description here

1

As per as your question,order status become processing whenever " card type is credit and there is no due amount" this two condition is total depends on what payment gatway return after payment done or failed and you extension code.

First you need to check what params will coming when customer is return from paymemt gateway.Depend on this params,you can dietect payment is done not etc.

Also, i have optimized code:

<?php
class Embitel_Billdesk_Model_Observer {
    public function updateStatus($observer){

        $orderIds = $observer->getEvent()->getOrderIds();
        if (empty($orderIds) || !is_array($orderIds)) {
            return;
        }

        $orderIds = $observer->getEvent()->getOrderIds();

        foreach($orderIds as $eachOrderId){
        $order = Mage::getModel('sales/order')->load($eachOrderId);           
            if($order->getId()){
            $order = Mage::getModel('sales/order')->load($order_id);
                if($order->getPayment()->getMethodInstance()->getCode()=='embitel_billdesk'  ){

                    $state  = Mage_Sales_Model_Order::STATE_PROCESSING;
                    $status = true;
                    $order->setState($state, $status);
                    $order->save();

                }
            }
        }
    }

}
2
  • thanks amit, though I was going to implement this code on new upcoming orders. not the existing once.
    – amitshree
    Commented Apr 27, 2015 at 13:19
  • why down vote,cannot understand
    – Amit Bera
    Commented Apr 27, 2015 at 17:07

Your Answer

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

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