Filter Payment Methods in Magento onepage checkout

Filter Payment Methods in Magento onepage checkout

How-to-Post-SAP-ECC-Item-Master-to-eCommerce

As a developer or, a store owner, we face the mentioned situation very often.
How to filter payment methods based on some conditions applicable for my magento store?

[imageframe lightbox=”yes” style_type=”none” bordercolor=”” bordersize=”0px” stylecolor=”” align=”none” link=”” linktarget=”_self” animation_type=”0″ animation_direction=”down” animation_speed=”0.1″ class=”” id=””][/imageframe]

There are many of ways of creating it;

  1. By creating an observer for the event payment_method_is_active. Which is in fact the best technique to use.
  2. By overriding your theme’s default template files: app/design/frontend/[PACKAGE]/[THEME]/template/checkout/onepage/payment/methods.phtml
  3. By overriding method: Mage_Payment_Model_Method_Abstract::isAvailable()
  4. By overriding method: Mage_Checkout_Block_Onepage_Payment_Methods::_canUseMethod()
  5. By overriding method: Mage_Checkout_Block_Onepage_Payment_Methods::getMethods()

Among all the above methods, I’m discussing the first technique, i.e. creating an observer for the event payment_method_is_active.
Case Study: I have a magento store with two currencies, i.e. INR and USD, so, I would like to filter payment methods based on the currency customer has chosen. I will show only Saved CC Payment method for customers using USD as their currency.

Step 1

Create a Module in app/code/local/Insync/ Paymentfilter

Step 2

Register the event: payment_method_is_active in config.xml.
Add the following xml code in app/code/local/Insync/Paymentfilter/etc/config.xml




		
			1.0
		
	
	
		
			
				
					
						singleton
						Insync_Paymentfilter_Model_Observer
						paymentMethodIsActive
					
				
			
		
	

Step 3
Now, we need to create the observer file, where actual logic will be implemented.
Create observer file: app/code/local/Insync/Paymentfilter/Model/Observer.php and paste the following code:


Step 4 Now in this final step, enable & register your module with magento. Create the module xml file: app/etc/modules/Insync_Paymentfilter.xml and paste the following code:




	
		
			true
			local
			0.1.0
		
	

Now test it and Enjoy. Please let me know if you face any problem regarding this.[imageframe lightbox=”yes” style_type=”none” bordercolor=”” bordersize=”0px” stylecolor=”” align=”none” link=”” linktarget=”_self” animation_type=”0″ animation_direction=”down” animation_speed=”0.1″ class=”” id=””][/imageframe]

Rahul Das

Rahul is a software developer and front-end designer. He's currently engaged with Magento, WordPress and JavaScript.

Our integrations are dynamic in nature. The mentioned offerings are the cumulative possibilities of the platform (actual scenarios are specifically organization/business-dependent). For any disparity, please refer to the latest version of the integration brochures.