Get active payment methods in Magento 2.

In Magento 2 We can get only active payment methods using Magento\Payment\Model\Config class. You can get a list of all active payment method by Config.php class.

Return methods are both online and offline for a system. You can get it by simple code snippets.

Create Block file,

Call function in template file by below way,

Output is(Test in Magento 2.2.6),

You can get all payment methods in Magento 2 by, Get All Payment Methods in Magento 2.