Magento – Onepage Checkout – Get selected payment method

onepage-checkoutpayment-methods

I'm trying to get user's current selected payment method, in onepage checkout page. I tried the following

$paymentMethod = Mage::getSingleton('checkout/session')->getQuote()->getPayment()->getMethodInstance()->getCode();

but the payment method returned is not correct. Actually it's a method that's not even activated in my store (check/money order).

Why is this happening and how can I get the correct value?

Best Answer

Try this code,

$session  = Mage::getSingleton('checkout/session');

$quote_id = $session->getQuoteId();

$quote = Mage::getModel('sales/quote')->load($quote_id );

$paymentcode = $quote->getPayment()->getMethodInstance()->getCode();