Magento: How to get all active payment modules

Featured Image

This code bellow will get you all active Magento payment modules. This example below return an array which you can use to create drop down menu or something else in Magento’s front-end or admin sections.

class Inchoo_Vendor_Model_Activpayment
{

	public function getActivPaymentMethods()
	{
	   $payments = Mage::getSingleton('payment/config')->getActiveMethods();

	   $methods = array(array('value'=>'', 'label'=>Mage::helper('adminhtml')->__('--Please Select--')));

	   foreach ($payments as $paymentCode=>$paymentModel) {
            $paymentTitle = Mage::getStoreConfig('payment/'.$paymentCode.'/title');
            $methods[$paymentCode] = array(
                'label'   => $paymentTitle,
                'value' => $paymentCode,
            );
        }

        return $methods;

	} 

}
6
Top

Enjoyed this post?

Subscribe to our RSS Feed, Follow us on Twitter and spread it to your friends!

Author

Domagoj Potkoc

Magento Senior Developer

Domagoj Potkoc is part of the Casablanca team together with Ivan Weiler, Hrvoje and Vanja. Domagoj is Magento Certified Developer since March 2012.

Other posts from this author

Discussion 6 Comments

Add Comment
  1. Anton

    And getActiveMethods() method has a bug , dependent on store based settings in multi store/website environment “googlecheckout/payment” will always return as active method even if it’s disabled

  2. i m newbie in magento, how to use this module i want the paypal payment module to be shown to my customers while they shop
    can u suggest me some thing to do this paypal enable
    thanks

  3. This is relay helpful ,,
    I searched much , but i didn’t find…..

    anyway ,, thanks

  4. Hi,

    Very useful article. One of my college used this.

    Can you explain what is what in this code.

    I want to get all active shipping methods.

    Regards,
    Saurabh

  5. There is another “standard” and “cleaner” way of do it:

    Mage_Payment_Helper_Data has a method: getPaymentMethodList that returns an array. Returned array format depends on parameters passed to this method. This is used in different grids in Admin to show an HTML select of payment methods, and can be used in frontend also.

    To get an array of Payment Methods, with label and value to show a select in the front, you can use this code:

    Mage::helper("sales")->getPaymentMethodList(true, true, true);
    
  6. Thanks a lot for this code. And if anyone wants to have only the active payment methods which are enabled on the back end then they can check a condition given below

    
    if($paymentModel->canUseCheckout()==1):
    
    $paymentTitle = Mage::getStoreConfig('payment/'.$paymentCode.'/title');
    
    /*And followed by your code*/
    
    endif;
    

Add Your Comment

Please wrap all source codes with [code][/code] tags.
Top