{"id":7188,"date":"2019-09-18T16:43:01","date_gmt":"2019-09-18T11:13:01","guid":{"rendered":"https:\/\/www.hiddentechies.com\/blog\/?p=7188"},"modified":"2019-09-27T09:51:31","modified_gmt":"2019-09-27T04:21:31","slug":"magento-2-get-all-active-payment-methods","status":"publish","type":"post","link":"https:\/\/www.hiddentechies.com\/blog\/magento-2\/magento-2-get-all-active-payment-methods\/","title":{"rendered":"Magento 2 &#8211; How to Get All Active Payment Methods"},"content":{"rendered":"<p>In this post I am going to explain how to get all active payment methods in magento 2.<\/p>\n<p><strong>1. Using Dependency Injection<\/strong><\/p>\n<p>Add below code snippet in Block class.<\/p>\n<pre class=\"lang:default decode:true \">protected $_paymentConfig;\r\nprotected $_scopeConfigInterface;\r\n\r\npublic function __construct(\r\n\t\\Magento\\Backend\\Block\\Template\\Context $context,\r\n\t\\Magento\\Payment\\Model\\Config $paymentConfig,\r\n\t\\Magento\\Framework\\App\\Config\\ScopeConfigInterface $scopeConfigInterface,\r\n\tarray $data = []\r\n) \r\n{\r\n\t$this-&gt;_paymentConfig = $paymentConfig;\r\n\t$this-&gt;_scopeConfigInterface = $scopeConfigInterface;\r\n\tparent::__construct($context, $data);\r\n}\r\n\r\npublic function getAllActivePaymentMethods() {\r\n\t$activePaymentMethods = $this-&gt;_paymentConfig-&gt;getActiveMethods();\r\n\t$activeMethods = array();\r\n\tif ($activePaymentMethods &amp;&amp; count($activePaymentMethods) &gt; 0) {\r\n\t\tforeach ($activePaymentMethods as $methodCode =&gt; $paymentModel) {\r\n\t\t\t$methodTitle = $this-&gt;_scopeConfigInterface-&gt;getValue('payment\/' . $methodCode . '\/title');\r\n\t\t\t$activeMethods[$methodCode] = array(\r\n\t\t\t\t'label' =&gt; $methodTitle,\r\n\t\t\t\t'value' =&gt; $methodCode\r\n\t\t\t);\r\n\t\t}\r\n\t}\r\n\treturn $activeMethods;\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>Add below code snippet in template file.<\/p>\n<pre class=\"lang:default decode:true \">\/\/get all active payment methods\r\n$allActivePaymentMethods = $block-&gt;getAllActivePaymentMethods();\r\n\r\necho \"&lt;pre&gt;\";\r\nprint_r($allActivePaymentMethods);\r\necho \"&lt;\/pre&gt;\";<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>2. Using Object Manager<\/strong><\/p>\n<pre class=\"lang:default decode:true \">$objectManager = \\Magento\\Framework\\App\\ObjectManager::getInstance();\r\n\r\n$paymentConfig = $objectManager-&gt;get('Magento\\Payment\\Model\\Config');\r\n$scopeConfigInterface = $objectManager-&gt;get('Magento\\Framework\\App\\Config\\ScopeConfigInterface');\r\n\r\n\/\/get all active payment methods\r\n$activePaymentMethods = $paymentConfig-&gt;getActiveMethods();\r\n\r\n$activeMethods = array();\r\n\r\nif ($activePaymentMethods &amp;&amp; count($activePaymentMethods) &gt; 0) {\r\n    foreach ($activePaymentMethods as $methodCode =&gt; $paymentModel) {\r\n        $methodTitle = $scopeConfigInterface-&gt;getValue('payment\/' . $methodCode . '\/title');\r\n        $activeMethods[$methodCode] = array(\r\n            'label' =&gt; $methodTitle,\r\n            'value' =&gt; $methodCode\r\n        );\r\n    }\r\n}\r\n\r\necho \"&lt;pre&gt;\";\r\nprint_r($activeMethods);\r\necho \"&lt;\/pre&gt;\";<\/pre>\n<p>Thats it. Enjoy Magento 2!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post I am going to explain how to get all active payment methods in magento 2. 1. Using Dependency Injection Add below code snippet in Block class. protected $_paymentConfig; protected $_scopeConfigInterface; public function __construct( \\Magento\\Backend\\Block\\Template\\Context $context, \\Magento\\Payment\\Model\\Config $paymentConfig, \\Magento\\Framework\\App\\Config\\ScopeConfigInterface $scopeConfigInterface, array $data = [] ) { $this-&gt;_paymentConfig = $paymentConfig; $this-&gt;_scopeConfigInterface = $scopeConfigInterface; parent::__construct($context,&#8230; <\/p>\n<div class=\"actions\"><a href=\"https:\/\/www.hiddentechies.com\/blog\/magento-2\/magento-2-get-all-active-payment-methods\/\">Continue Reading<\/a><\/div>\n","protected":false},"author":1,"featured_media":7314,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[59],"tags":[661,10,28,27],"_links":{"self":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/7188"}],"collection":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/comments?post=7188"}],"version-history":[{"count":1,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/7188\/revisions"}],"predecessor-version":[{"id":7189,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/7188\/revisions\/7189"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media\/7314"}],"wp:attachment":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media?parent=7188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/categories?post=7188"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/tags?post=7188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}