Retrieve All Payment Methods list in Magento 2.

In Magento 2 You can retrieve all the available payment methods by Magento\Payment\Model\Config\Source\Allmethods class.

Using Allmethods class you can get all the payment methods in the system whether its enable or disable in the admin setting.

You can get only the active payment methods by Get all active payment methods in Magento 2.

List of all the payment methods in Magento 2 getting by below code snippets,

Create Block file,

<?php
namespace Rbj\Payment\Block;

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

    /**
	 * All Payment Method in Magento 2 backend
	 *
	 * @return Array
     */
    public function getAllPaymentMethods()
    {
        return $this->allPaymentMethod->toOptionArray();
    }

Get function in template file by below way using phtml template file,

<?php
$payments = $block->getAllPaymentMethods();
foreach($payments as $paymentCode => $payment) {
	echo "<pre>";print_r($payments);
}

The output will be like(Test in Magento 2.2.6),

Array
(
    [substitution] => Array
        (
            [value] => substitution
            [label] => 
        )

    [vault] => Array
        (
            [value] => vault
            [label] => 
        )

    [braintree] => Array
        (
            [value] => braintree
            [label] => Credit Card (Braintree)
        )

    [authorizenet_directpost] => Array
        (
            [value] => authorizenet_directpost
            [label] => Credit Card Direct Post (Authorize.net)
        )

    [klarna] => Array
        (
            [label] => Klarna
            [value] => Array
                (
                    [klarna_kp] => Array
                        (
                            [value] => klarna_kp
                            [label] => Klarna Payments
                        )

                )

        )

    [offline] => Array
        (
            [value] => Array
                (
                    [banktransfer] => Array
                        (
                            [value] => banktransfer
                            [label] => Bank Transfer Payment
                        )

                    [cashondelivery] => Array
                        (
                            [value] => cashondelivery
                            [label] => Cash On Delivery
                        )

                    [checkmo] => Array
                        (
                            [value] => checkmo
                            [label] => Check / Money order
                        )

                    [free] => Array
                        (
                            [value] => free
                            [label] => No Payment Information Required
                        )

                    [purchaseorder] => Array
                        (
                            [value] => purchaseorder
                            [label] => Purchase Order
                        )

                )

            [label] => Offline Payment Methods
        )

    [paypal] => Array
        (
            [value] => Array
                (
                    [payflow_link] => Array
                        (
                            [value] => payflow_link
                            [label] => Credit Card
                        )

                    [payflowpro] => Array
                        (
                            [value] => payflowpro
                            [label] => Credit Card
                        )

                    [payflow_advanced] => Array
                        (
                            [value] => payflow_advanced
                            [label] => Credit Card
                        )

                    [paypal_billing_agreement] => Array
                        (
                            [value] => paypal_billing_agreement
                            [label] => PayPal Billing Agreement
                        )

                    [payflow_express_bml] => Array
                        (
                            [value] => payflow_express_bml
                            [label] => PayPal Credit
                        )

                    [paypal_express_bml] => Array
                        (
                            [value] => paypal_express_bml
                            [label] => PayPal Credit
                        )

                    [paypal_express] => Array
                        (
                            [value] => paypal_express
                            [label] => PayPal Express Checkout
                        )

                    [payflow_express] => Array
                        (
                            [value] => payflow_express
                            [label] => PayPal Express Checkout Payflow Edition
                        )

                    [hosted_pro] => Array
                        (
                            [value] => hosted_pro
                            [label] => Payment by cards or by PayPal account
                        )

                )

            [label] => PayPal
        )

    [braintree_paypal] => Array
        (
            [value] => braintree_paypal
            [label] => PayPal (Braintree)
        )

    [braintree_paypal_vault] => Array
        (
            [value] => braintree_paypal_vault
            [label] => Stored Accounts (Braintree PayPal)
        )

    [braintree_cc_vault] => Array
        (
            [value] => braintree_cc_vault
            [label] => Stored Cards (Braintree)
        )

    [payflowpro_cc_vault] => Array
        (
            [value] => payflowpro_cc_vault
            [label] => Stored Cards (Payflow Pro)
        )

)