Prerequisites
- Next.js 14+ with App Router
- A Kelviq account with plans configured
- API keys from Settings → API keys in the dashboard
Step 1: Get Your API Keys
- Sign up at app.kelviq.com
- Navigate to Settings → API Keys
- Copy two keys:
- Server API Key — For API routes (keep secret)
- Client API Key — For React SDK (safe to expose)
Add to Environment Variables
Add these to your.env.local file:
Step 2: Define Your Plans
In Kelviq Dashboard
- Go to Plans section
- Create each subscription tier with:
- Plan Identifier:
base,pro,enterprise(code-friendly names) - Price: Monthly/yearly pricing
- Features: List of included features
- Plan Identifier:
Define Entitlements
For each plan, configure entitlements (feature access):
Example Plan Structure:
Step 3: Install the React SDK
Step 4: Create Customers (Optional)
You have two options for creating customers in Kelviq:Option 1: Auto-create during checkout
Skip this step entirely. When creating a checkout session, pass the customer’semail or customerId — Kelviq will automatically create the customer record if it doesn’t exist.
Option 2: Create customer explicitly
Create a customer record when a user signs up. This gives you more control and lets you track customers before they subscribe. Create API Route —app/api/customer/route.ts:
Step 5: Implement Checkout
Allow users to subscribe to a plan.Create Checkout API Route
Createapp/api/checkout/route.ts:
Pricing Page
Createapp/pricing/page.tsx:
Step 6: Manage Subscriptions
Fetch Current Subscription
Createapp/api/subscriptions/route.ts:
Update Subscription (Upgrade/Downgrade)
Createapp/api/subscriptions/update/route.ts:
Handle Upgrades/Downgrades in Client
activate_on_payment, the existing subscription remains active while payment is pending. If the payment method requires UPI approval or 3DS authentication, the updated subscription starts as incomplete. After payment succeeds, the updated subscription becomes active and the previous subscription becomes superseded. If an immediate charge fails, or the customer does not complete payment before expiry, the updated subscription becomes incomplete_expired and the existing subscription stays active.
Step 7: Gate Features with Entitlements
Dynamically enable/disable features based on subscription.Setup KelviqProvider
Wrap your app inapp/layout.tsx:
Access Entitlements in Components
Entitlement Response Structure (React SDK)
Common Patterns
Pattern 1: Feature Lock UI
Pattern 1: Feature Lock UI
Pattern 2: Usage Indicator
Pattern 2: Usage Indicator
Pattern 3: Conditional Rendering
Pattern 3: Conditional Rendering
Need Help?
Have questions or need implementation support?- Email us at hi@kelviq.com
- Book a demo