✨ Install with AI
✨ Install with AI
Copy this prompt to your AI code editor (Cursor, Copilot, Claude Code, etc.) to set up the integration automatically:
What You’ll Build
A complete checkout integration in Next.js including:- Server-side checkout session creation
- Client-side redirect to hosted checkout
- Webhook handling for payment confirmation
- Protected routes based on payment status
Prerequisites
- Next.js 13+ with App Router
- Waffo Pancake account with API keys
- A product created in Dashboard
Project Setup
1. Install Dependencies
2. Environment Variables
Create Checkout API Route
Create an API route to generate checkout sessions using the SDK:The SDK automatically handles request signing and deterministic idempotency keys — no manual header setup needed.
Pricing Page Component
Create a pricing page with checkout buttons:Webhook Handler
Handle payment confirmations using the SDK’s built-inverifyWebhook() — it has embedded public keys for both test and production environments, so you don’t need to manage webhook secrets:
The SDK’s
verifyWebhook() uses embedded public keys — no WAFFO_WEBHOOK_SECRET environment variable needed. It also includes replay protection by default.Success Page
Show confirmation after successful payment:Protected Routes Middleware
Protect routes based on subscription status:Server Component: Check Subscription
Customer Portal Link
Let users manage their subscription:Complete File Structure
Testing Checklist
Before going live:- Test checkout flow with test card
4576 7500 0000 0110 - Verify webhooks are received (check Dashboard logs)
- Test declined payment with
4576 7500 0000 0220 - Confirm success page displays correctly
- Switch to live API keys
- Update webhook URL to production endpoint
Next Steps
Handle Webhooks
Deep dive into webhook handling
Subscription Management
Advanced subscription features