Mitech Preloader
Magento

Get Payment Method name using Order ID

In this post we will see how how we can get Payment Method name using the Magento Order ID.

Payment method is critical in order to create custom extension for orders. We can easily get these required data from an order using Zend methods. In case of payment details, do you know how to fetch it by sales order id ? It is bit tricky to get the required data from a sales order.
We can fetch it by multiple simple methods. In Todays Magento quick tip would like to share some simple code to get Payment method from just an order id. Just paste it in your custom magneto module and edit your order id ($order->getId()).

This will be very useful when you dealing with creating your own extension. Here article title is self explanatory that we are trying to accomplish, so without wasting time let’s look at the code block.

[php]

/// Your Order Id
$order_id = ’12’;
$order = Mage::getModel(“sales/order”)->load($order_id);

/// you can also load sales order by increment id
// $order_increment_id = ‘10000002’;
// $order = Mage::getModel(“sales/order”)->loadByIncrementId($order_increment_id);

/// Get payment code of payment method used in sales order
$payment_method_code = $order->getPayment()->getMethodInstance()->getCode();

/// Get payment title of payment method used in sales order
$payment_method_title = $order->getPayment()->getMethodInstance()->getTitle();

/// Get card type of payment method used in sales order
$cc_type = $order->getPayment()->getData(‘cc_type’);

/// Get Credit Card information
$order->getPayment()->getMethodInstance()->getCardsStorage();
$order->getPayment()->getMethodInstance()->getCardsStorage()->getCards();
[/php]

If you find it helpful, Please like this post and share it with your friends.

blank