How to Get Payment Method Title/Code from order in Magento 2?

You can get the payment method title from the Order in Magento 2 by the order repository interface.

Load an Order by API OrderRepositoryInterface with Order ID, Get Payment Object, and fetch Payment-related stuff from the Payment Data.

You can get the payment method title of an order by below code snippets below,

<?php
namespace Rbj\Order\Model;

use Magento\Sales\Api\OrderRepositoryInterface;

class Data
{
    public function __construct(
        private readonly OrderRepositoryInterface $orderRepository
    ) {
    }

    public function getPaymentData()
    {
        $orderId = 1;
        $order = $this->orderRepository->get($orderId);
        $payment = $order->getPayment();
        $method = $payment->getMethodInstance();
        echo $method->getTitle(); // Cash On Delivery
        echo $method->getCode(); // cashondelivery
    }

}

Using the above method you can get any payment method title or code.