@paymint/nextjs
Next.js SDK for Paymint - subscription billing made simple.Installation
Quick Start
1. Create API Route
2. Add Provider
3. Use Hooks
4. Create Success Page
Imports
API Routes Created
ThenextRouteHandler creates these endpoints automatically:
| Route | Method | Description |
|---|---|---|
/api/billing/products | GET | List all products |
/api/billing/subscriptions | GET | Get customer subscriptions |
/api/billing/billing | GET | Get full billing state |
/api/billing/initialize | POST | Initialize Paddle checkout |
/api/billing/cancel/{id} | POST | Cancel subscription |
/api/billing/pause/{id} | POST | Pause subscription |
/api/billing/resume/{id} | POST | Resume subscription |
/api/billing/activate/{id} | POST | Activate trial |
Hooks
useBilling()
useCheckout()
useSubscription()
Post-Checkout Success Handling
After a successful checkout, you have two options:Option 1: Use onCheckoutComplete Callback
Option 2: Use Paddle’s successUrl
Fetching Latest Subscription on Success Page
Note: Subscriptions are created via Paddle webhooks. There may be a brief delay (1-5 seconds) between payment completion and subscription appearing in the database.
Server-Side Usage
Auth Integration
Clerk
NextAuth
Supabase
Security
Developer Responsibilities
The SDK handles most security concerns, but developers must ensure:1. getCustomerEmail - Get Email from Auth Session (CRITICAL)
2. Keep API Key Server-Side Only
3. Use HTTPS in Production
Always deploy with HTTPS to protect session cookies.What Paymint Handles
| Security Concern | Status |
|---|---|
| API key encryption at rest | ✓ Handled |
| Subscription ownership verification | ✓ Handled |
| Customer email validation | ✓ Handled |
| Paddle API authentication | ✓ Handled |
| Webhook signature verification | ✓ Handled |
What Developers Must Handle
| Security Concern | Requirement |
|---|---|
getCustomerEmail implementation | Must return email from auth session |
| API key storage | Keep server-side only |
| Auth session security | Use Clerk/NextAuth/Supabase properly |
| HTTPS | Enable in production |
Environment Variables
paymint_test_xxx→ Paddle Sandboxpaymint_live_xxx→ Paddle Production
NEXT_PUBLIC_PADDLE_ENVIRONMENT!
