title: Magento 2 Success.phtml Show Payment Method
body: <p>I need to show payment method code or name in success.phtml page of my Magento 2 site.</p>
  
  <p>I create the module; and i add 'Your payment method is:' sentence in my success.phtml; but, couldn't write the payment method here.</p>
  
  <p>I just want to say something like below:</p>
  
  <pre><code>&lt;?= __('Your order method is:',$block-&gt;getPaymentMethod()) ?&gt;
  </code></pre>
  
  <p>Could you give an example for my modules function php to create paymentmethod() function?</p>
  
  <p>I tried everything in stackoverflow</p>
  
  <p>These links didnt help me:</p>
  
  <p><a href="https://magento.stackexchange.com/questions/153437/magento-2-payment-method-code-on-order-success-page">https://magento.stackexchange.com/questions/153437/magento-2-payment-method-code-on-order-success-page</a></p>
  
  <p><a href="https://magento.stackexchange.com/questions/156933/get-payment-method-title-of-an-order">https://magento.stackexchange.com/questions/156933/get-payment-method-title-of-an-order</a></p>
  
  <p>My recent code is this (returns nothing):</p>
  
  <pre><code>&lt;?php
  
  namespace MyFirm\Ordersuccess\Block\Checkout;
  
  use Magento\Checkout\Model\Session;
  use Magento\Framework\View\Element\Template\Context;
  use Magento\Sales\Model\OrderFactory;
  
  class Success extends \Magento\Checkout\Block\Success {
  
  protected $checkoutSession;
  protected $_customerSession;
  
  public function __construct(
      Context $context,
      OrderFactory $orderFactory,
      Session $session,
      array $data = []
  ) {
      $this-&gt;checkoutSession = $session;
      parent::__construct($context, $orderFactory, $data);
  }
  
  public function getPaymentMethod() {
  
      $payment = $this-&gt;checkoutSession-&gt;getLastRealOrder()-&gt;getPayment();
  return $payment;
  }
  
  }
  </code></pre>