Dynamically Enable/Disable Payment Method in Magento

In my recent Magento project I faced a situation in which the Payment methods needed to be enabled/disabled dynamically based on the some conditions. I googled a bit around I found some interesting solutions. I am wrapping up the solution in this article. Magento provides the isAvailable() method in the model of the each payment method. This method tell Magento if the corresponding payment method is available or not for checkout.
Suppose we want to do it for ‘PurchaseOrder’ payment method. Then go to the model file ‘appcodecoreMagePaymentModelMethodPurchaseorder.php’. But the isAvailable() method is not present there. It is generally available for other payment methods. So we will rewrite the model file in our custom module.

Step 1:

Open the config.xml in your custom module do following changes:

<!-- Rewrite the Purchase order model -->

Step 2:

Create the new Model file in your custom module at the location: appcodelocalMyprojectMymoduleModelMethodPurchaseorder.php. In this file create the isAvailable() method as:

class Myproject_Mymodule_Model_Method_Purchaseorder extends Mage_Payment_Model_Method_Purchaseorder
* Check if payment method is available for use
* @param type $quote
* @return boolean
public function isAvailable($quote = null) {
//Here write your logic for enabling/disabling the method
//if this
return true;
rerturn false;

And this is all. All you custom logic goes in the isAvailable() methos for enabling/disabling the payment method.

Written by Arvind Bhardwaj

Arvind is a certified Magento 2 expert with more than 10 years of industry-wide experience.

Website: http://www.webspeaks.in/

One thought on “Dynamically Enable/Disable Payment Method in Magento

  1. I constantly spent my half an hour to read this website’s articles all the
    time along with a cup of coffee.

    Also visit my blog post – test

Comments are closed.