Get active payment methods list in Magento 2.

Magento 2, You can get list of active payment methods using Magento\Payment\Model\Config class.

You need to instantiate Config Class in the construct method of the class to fetch list of active payment methods.

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

Create Block file,

<?php
namespace Rbj\Payment\Block;

class ActivePayment extends \Magento\Framework\View\Element\Template
{
    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Payment\Model\Config $paymentModelConfig,
        array $data = []
    ) {
        $this->paymentModelConfig = $paymentModelConfig;
        parent::__construct($context, $data);
    }

    /**
	 * Active Payment Method in Magento 2
	 *
	 * @return Object
     */
    public function getActivePaymentMethods()
    {
        return $this->paymentModelConfig->getActiveMethods();
    }

Call function in template file by below way,

<?php
$payments = $block->getActivePaymentMethods();
echo "Active Payment Method Number is".count($payments);
foreach($payments as $paymentCode => $payment) {
	echo $paymentCode;echo "<br>";
}

Output is(Test in Magento 2.2.6),

Active Payment Method Number is 7

free
payflow_express
payflowpro
payflowpro_cc_vault
paypal_billing_agreement
checkmo
cashondelivery

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