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.

13 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
  10. Tours Guy on November 27th, 2010 at 3:08 am
  11. Miko on June 15th, 2011 at 7:23 am
  12. Cristian on June 15th, 2011 at 8:31 am
  13. Fredrik on August 9th, 2011 at 7:20 pm

Leave a comment

Advertise / Sponsors

Comments RSS Feed

Recent Comments

  • yuci: ok, i solved the problem, but i will search for a better one. i just noticed, hidden div doesnt show itself...
  • yuci: hey, yeah i downloaded well, and i edited a lot this application, and i can say that, it is a wonderful app....
  • Cristian: No, it’s working as I tested.
  • yuci: is link dead, or just some temporary problem? i cant download zip files.
  • Fredrik: I can’t get this to work. It seems to fail at $order->setShippingAmount( $shipping_amount +...