How can I display the payment method in the success page using a code? If anyone can help me, it would be great. Thankyou.

  • What is the exact magento 2 version you are using? Commented Jan 3, 2019 at 11:15
  • @SukumarGorai I am using Magento ver. 2.1.7
    – Meera
    Commented Jan 3, 2019 at 11:17

2 Answers 2


Copy the success.phtml from:


to your theme location:


Now add the following code to your success.phtml

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();       
$payment = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($block->getOrderId())->getPayment();
echo $paymentMethodTitle = $payment->getMethodInstance()->getTitle();

You can also create one block which extends Success block and then create one method which should return the above code.

Note: Use of Objectmanager directly in phtml file is not a good practice. you need to create block and adjust those according to your requirement.

Hope this helps!


As pointed out above using the object manager is the incorrect way to achieve this in Magento 2. To achieve this you need to create a module:


(Module can we whatever you want) You then need to extend the \Magento\Checkout\Block\Onepage\Success block inside of your own module and for consistency add it to:


You then add the dependancies to this. Here is an example of the extended block:


namespace MyModule\CustomerPaymentType\Block\Checkout\Onepage;

class Success
extends \Magento\Checkout\Block\Onepage\Success
    protected $order;

    public function __construct(
        \Magento\Sales\Model\Order $order
    ) {
        $this->order = $order;

    public function getOrder(){
       $orderTitle = $this->order->getTitle();

Then inside of your:


You can now call $block->getOrder()

If you get:

Type Error occurred when creating object: MyModule/CustomerPaymentType\Block\Checkout\Onepage\Success\Interceptor

Don't forget to clear your Generated folder

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.