惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
Martin Fowler
Martin Fowler
MyScale Blog
MyScale Blog
The GitHub Blog
The GitHub Blog
I
InfoQ
A
About on SuperTechFans
GbyAI
GbyAI
宝玉的分享
宝玉的分享
爱范儿
爱范儿
博客园 - 【当耐特】
博客园 - 司徒正美
博客园 - 聂微东
P
Proofpoint News Feed
WordPress大学
WordPress大学
云风的 BLOG
云风的 BLOG
Last Week in AI
Last Week in AI
阮一峰的网络日志
阮一峰的网络日志
B
Blog RSS Feed
Jina AI
Jina AI
aimingoo的专栏
aimingoo的专栏
J
Java Code Geeks
博客园 - 叶小钗

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
How I Added a Razorpay Paywall to My React App in 10 Minutes
IamAdhitya · 2026-06-06 · via DEV Community
Cover image for How I Added a Razorpay Paywall to My React App in 10 Minutes

IamAdhitya

Every time I built a new app, I copy-pasted the same paywall code.

The Razorpay subscription logic. The gate component that blocks UI for free users. The pricing modal with the monthly/yearly toggle. The usePro hook that checks localStorage and optionally pings a verification endpoint.

Same code. Every app. Every time.

So I extracted it all into react-premium-gate — a zero-dependency React library with three exports that handle the entire Razorpay subscription flow.

What's in the box

Three things and nothing else:

usePro — a hook that manages Pro status. It reads a subscription ID from localStorage, optionally verifies it against your backend, and gives you isPro, loading, activatePro, and deactivatePro.

PremiumGate — a component that replaces any Pro-only UI with a paywall card. Fully customisable title, description, icon, button text, and accent colour.

PricingModal — a bottom-sheet pricing modal with a monthly/yearly plan toggle, a save badge, and a loading state for while the Razorpay checkout is opening.

Plus three copy-paste Vercel API templates for creating subscriptions, verifying HMAC payment signatures, and checking subscription status server-side.

Install

npm install react-premium-gate

Zero runtime dependencies. Works with React 17+.

The flow in plain English

  1. User hits a Pro feature → PremiumGate shows instead of the real UI
  2. User clicks Upgrade → PricingModal opens
  3. User picks a plan → your handler calls /api/create-subscription
  4. Razorpay checkout opens → user pays
  5. Razorpay calls your handler → you call /api/verify-payment
  6. Signature is valid → call activatePro(subscriptionId)
  7. isPro flips to true → real UI renders, modal closes

That's the entire flow. The library handles steps 1, 2, and 7. The templates handle steps 3 and 5. You wire them together in about 10 minutes.

Why Razorpay

If you're building for Indian users, Razorpay is the only serious option. Stripe doesn't support INR subscriptions properly. Razorpay has native UPI, net banking, and card support, plus a generous free tier.

The HMAC signature verification in the template is the part most tutorials get wrong — they skip it entirely, which means anyone can fake a successful payment. The template handles it correctly with crypto.createHmac.

Customisation

Every visual element is a prop. Swap the accent colour from the default gold to match your brand. Change the icon from 👑 to whatever fits. Override the button text to show your price — "Upgrade to Pro — ₹399/mo" converts better than a generic label.

The usePro hook's storageKey is configurable so it doesn't clash if you're running multiple apps on the same domain.

Links

I use this in production across the Rewrite Labs app suite. If you're building a React SaaS with Razorpay and you want the paywall wired up without thinking about it, this is the library.