0

I want to get the list of all active offline payment methods like cashondelivery, checkmo, banktransfer etc.

2
  • did you get any way to list out all active offline payment methods? Commented Jul 9, 2018 at 11:24
  • just try with this blog.chapagain.com.np/… Commented Nov 19, 2018 at 6:54

1 Answer 1

0

Although the question is very old, but since it has not been answered yet, I would like to answer.

I assume that we need to get the active offline payment methods in a controller file and the controller has been defined in the routes.xml already.

To get the active offline payment methods, we need to first inject the \Magento\Payment\Helper\Data class in the constructor and then use the getPaymentMethods() function to get all payment methods.

After this the class should look something like this:

<?php namespace {Package}\{Module}\Controller\Index; class Index extends \Magento\Framework\App\Action\Action { protected $_paymentHelper; public function __construct(\Magento\Framework\App\Action\Context $context, \Magento\Payment\Helper\Data $paymentHelper) { $this->_paymentHelper = $paymentHelper; parent::__construct($context); } public function execute() { $paymentMethods = $this->_paymentHelper->getPaymentMethods(); if (count($paymentMethods)) { foreach ($paymentMethods as $paymentMethod) { if (isset($paymentMethod['active']) && $paymentMethod['active'] == 1 && isset($paymentMethod['group']) && $paymentMethod['group'] == 'offline') { echo "<pre>"; print_r($paymentMethod); echo "</pre>"; } } } } } 

I hope, this should help.

Help Source: http://blog.chapagain.com.np/magento-2-get-payment-methods-all-active-used/

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.