Get the title of an order’s payment method in Magento

Apr 8, 2011

MagentoI have been writing a magento based site for a client and they have a few requirements for their despatch system that I had not seen before. One of them is to set a flag in their dispatch system indicating the payment method chosen by the customer (seems sensible, I just haven’t had to do it before). Anyway, turns out as it often is with Magento, that this is a really simple thing to do, once you find the information.

You can see in the following lines of code, once you have loaded your order you can simply access the payment and the payment’s method object. Unfortunately I still haven’t managed to uncover a list of attributes or methods for these classes but I did managed to establish that the method instance has a title that refers to the title you set when you enable the payment method in the admin.

$order = new Mage_Sales_Model_Order();
$incrementId = Mage::getSingleton('checkout/session')->getLastRealOrderId();

$payment = $order->getPayment()->getMethodInstance()->getTitle();

If anyone reads this and can elaborate on methods available for payments and/or payment method classes then let me know and I will add the information here as an ongoing reference.