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,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <?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,
1 2 3 4 5 | <?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),
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | 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) ) ) |