DEV Community

Cover image for How to Disable Specific Payment Methods in Razorpay Using Custom Code (MERN Stack)
Vijay Kumar
Vijay Kumar

Posted on

How to Disable Specific Payment Methods in Razorpay Using Custom Code (MERN Stack)

When integrating payments in a MERN app, sometimes you don’t want to show every payment option.

Maybe:

  • You want to disable UPI for high-value orders
  • Disable Wallets temporarily
  • Allow only Cards for international payments
  • Or apply business rules dynamically

Razorpay allows you to control this using the method option in Checkout.

In this guide, I’ll show you how to disable specific payment methods using custom logic in a MERN stack app.


🏗 Tech Stack

  • MongoDB
  • Express
  • React
  • Node.js
  • Razorpay Checkout

Step 1: Install Razorpay (Backend)

npm install razorpay
Enter fullscreen mode Exit fullscreen mode

Step 2: Create Order in Backend (Node + Express)

const Razorpay = require("razorpay");

const razorpay = new Razorpay({
  key_id: process.env.RAZORPAY_KEY_ID,
  key_secret: process.env.RAZORPAY_KEY_SECRET,
});

app.post("/create-order", async (req, res) => {
  const { amount } = req.body;

  const options = {
    amount: amount * 100, // convert to paise
    currency: "INR",
    receipt: "receipt_order_1",
  };

  const order = await razorpay.orders.create(options);

  res.json({
    order,
    // 👇 Send custom flags to frontend
    paymentConfig: {
      allowUPI: false,
      allowWallet: false,
      allowCard: true,
      allowNetbanking: true,
    },
  });
});
Enter fullscreen mode Exit fullscreen mode

Now we control which payment methods are allowed dynamically.


Step 3: Configure Razorpay Checkout (React Frontend)

const options = {
  key: "YOUR_RAZORPAY_KEY",
  amount: order.amount,
  currency: "INR",
  order_id: order.id,

  method: {
    upi: paymentConfig.allowUPI,
    wallet: paymentConfig.allowWallet,
    card: paymentConfig.allowCard,
    netbanking: paymentConfig.allowNetbanking,
  },

  handler: function (response) {
    console.log("Payment Successful:", response);
  },

  theme: {
    color: "#3399cc",
  },
};

const rzp = new window.Razorpay(options);
rzp.open();
Enter fullscreen mode Exit fullscreen mode

That’s it.

You’ve now dynamically disabled payment methods using backend logic.


🔥 Real-World Use Cases

Here’s where this becomes powerful:

1️⃣ High-Value Orders

Disable UPI for payments above ₹50,000.

2️⃣ Subscription-Only Card Payments

Allow only cards for recurring billing.

3️⃣ Region-Based Restrictions

Disable netbanking for international users.

4️⃣ Feature Flags

Turn payment methods on/off without redeploying frontend.


⚠ Important Notes

  • Always create orders from backend (never from frontend).
  • Never expose your Razorpay secret key.
  • Verify payment signature after success.
  • Keep method logic business-driven, not hardcoded.

💡 Pro Tip (Production Level)

Instead of hardcoding:

allowUPI: false
Enter fullscreen mode Exit fullscreen mode

Use business logic:

allowUPI: amount < 50000
Enter fullscreen mode Exit fullscreen mode

Or fetch config from database:

const config = await PaymentSettings.findOne();
Enter fullscreen mode Exit fullscreen mode

This makes your system scalable.


Final Thoughts

Most developers just integrate Razorpay and leave all payment methods enabled.

But real-world systems need control.

Using the method option in Razorpay Checkout, combined with backend-driven logic in MERN, gives you full flexibility over your payment flow.

If you're building serious production apps, this level of control matters.

Top comments (0)