Disable a Payment Method Programmatically in Magento 2

Payment system management can be considered as one of the cores of the Magento 2 store system as a good handling system can help you optimize your sales, profits as well as your efforts.

Disable payment method is a good way for you when you want to restrict specific payment methods based on the customer groups, product/order attributes, shipping parameters, etc. For example, with customers who are coming from India, you can deactivate other payment methods and only display the CCAvenue method.

In today’s article, I will show you 2 simple stages to disable payment method programmatically in Magento 2.

To Disable a Payment Method Programmically in Magento 2:

Step 1: Edit config.xml file

To disable the Payment Method Programmatically, firstly, you need to open the config.xml file and then add the following code to that file:


Step 2: Edit Observer.php file

In this step, the below code should be added in the Observer.php file

class Vendor_Extension_Model_Observer {
    public function paymentMethodIsActive(Varien_Event_Observer $observer) {
        $method = $observer->getMethodInstance();
        if ($method->getCode() == 'payment_method_code') {
            if (condition) {
                $result = $observer->getResult();
                $result->isAvailable = false;


In conclusion, above are the steps which can help you disable a Payment Method Programmically. Implement these stages correctly, you can control the payment methods choices at your checkout page according to different conditions. For the full solution to restrict payment choices, you can view Mageplaza Payment Restrictions module

Enjoyed the tutorial? Spread it to your friends!