Lumn + Next.js
Stripe payments with one SDK. Checkout, billing, and webhooks.
Install
npm install @lumnsh/stripe @lumnsh/nextjs
Checkout
Create a Stripe checkout session and redirect the customer.
import Lumn from '@lumnsh/stripe';
const lumn = new Lumn(process.env.LUMN_API_KEY!);
const session = await lumn.checkout.create({
customer_id: 'user_42',
product_slug: 'pro',
price_interval: 'monthly',
success_url: 'https://example.com/checkout/success',
cancel_url: 'https://example.com/checkout/cancel',
});
// Redirect to session.checkout_urlUsage-based billing
Check entitlements and record metered usage.
import Lumn from '@lumnsh/stripe';
const lumn = new Lumn(process.env.LUMN_API_KEY!);
const access = await lumn.entitlements.check({
customer_id, feature_key: 'ai_generations',
});
await lumn.meter.record({
customer_id,
feature_key: 'ai_generations',
idempotency_key: crypto.randomUUID(),
});Webhooks
import { Webhooks } from '@lumnsh/nextjs';
export const POST = Webhooks({
onCheckoutCompleted: async (payload) => { /* provision access */ },
onPaymentSucceeded: async (payload) => { /* confirm payment */ },
onSubscriptionCreated: async (payload) => { /* activate plan */ },
});Try it
# Create a checkout session
curl -X POST http://localhost:3000/api/checkout \
-H "Content-Type: application/json" \
-d '{"customer_id":"user_42","product_slug":"pro","price_interval":"monthly"}'
# Usage-based billing
curl -X POST http://localhost:3000/api/ai/generate \
-H "Content-Type: application/json" \
-d '{"customer_id":"user_42","prompt":"Hello world"}'