Add payment method handling cost

Posted on August 9th, 2009, by Cristian in Magento

This week I worked at a Magento downpayment payment module which required a way to add handling fee. My problem was that the fee should be added to checkout total once the payment method was check. After looking at Magento API I come with a solution.

The order has a method setShippingAmount and a method getShippingAmount and I tried to use them. I adjust the total shipping amount by increading with my module handling fee.

$shipping_amount = $order->getShippingAmount();
$order->setShippingAmount( $shipping_amount + $mine_handling_amount );

The way that I did it was to create a method updateShippingAmount and add it as observe for checkout_type_onepage_save_order event in the module/etc/config.xml file:

public function updateShippingAmount( $observer )
{
   $MyPaymentMethod = Mage::getSingleton('namespace/mypaymentmethod');

   $order = $observer->getEvent()->getOrder();
   $payment = $order->getPayment()->getData();

   if( $payment['method'] == $MyPaymentMethod->getCode() )
   {
       $shipping_amount =  $order->getShippingAmount();
       $order->setShippingAmount( $shipping_amount + $MyPaymentMethod->getPostHandlingCost() );
   }
}

There may be a few other ways to do it, but this is my way of doing it and wanted to share with other Magento developer. If you know other way to do it please write it below.

9 comments

  1. Alpha on September 25th, 2009 at 10:20 am
  2. Cristian on September 29th, 2009 at 9:11 am
  3. Alpha on September 29th, 2009 at 9:44 am
  4. Cristian on September 29th, 2009 at 9:51 am
  5. Alpha on September 29th, 2009 at 1:32 pm
  6. Cristian on September 29th, 2009 at 1:46 pm
  7. Magnus_A on October 24th, 2009 at 10:41 am
  8. Cristian on October 24th, 2009 at 11:06 am
  9. jord on January 22nd, 2010 at 1:54 pm

Leave a comment

Comments RSS Feed

Recent Comments

  • luciano: Is there any way to fit the submenu elements to the widthest element in each one? I don´t know if I make...
  • g25: I agree that Apple should implement a homescreen like this. Personally though the lock screen should be like...
  • wildspirit: C++ : http://wallpaper.wallpedia.org /24__boat_destroyer.htm
  • tom: Hello, this menue is great, but i noticed that it does not work in Opera perfectly. The “hover”...
  • medbrooro: adam ant shoes http://topcitystyle.com/dark-b rown-women-color29.html graphic designer gucci purses...