Tutorialsplane

Magento 2 get payment method from order


Magento 2 get payment method from order- We can get payment method code from order object in Mageto 2. We can use dependency injection or object manager to get the order object. Here in this article, we are going to explain how you can get the payment details such as – payment method title, method code and cc_type etc.


Magento 2 get payment method from order Example

First of all load order object by order id then get payment object, Using payment object you can get the payment details simply as below-

Example:

$orderId = 9999;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('\Magento\Sales\Model\Order')                           ->load($orderId);
$payment = $order->getPayment();
$method = $payment->getMethodInstance();

$paymentMethod = $method->getTitle();

$ccType = $method->getCcType();

On the same way you can get other details about payment method.