P PasteCode
Playbook

Prompt-to-PR: Add a Pricing Page

SOP for generating a production pricing page with monthly/annual toggle, feature matrix, and Stripe Checkout links in a Next.js Tailwind project.

CursorClaude CodeCodexWindsurf Next.jsTypeScriptTailwind
.md .json Difficulty: Easy Updated Jun 8, 2026

One of the most-generated pages in AI coding sessions. This playbook constrains the agent to produce real, wired-up Stripe Checkout links rather than placeholder buttons.

1. Requirement

Add a /pricing page with two or three tiers, a monthly/annual billing toggle (annual gives a 20% discount), a feature comparison matrix, and Stripe Checkout integration. Prices must come from environment variables, not be hardcoded in JSX.

2. First Prompt

First Prompt
Add a /pricing page to this Next.js 15 App Router project with Tailwind.
Requirements:
1. Create `src/app/pricing/page.tsx` — a Server Component that renders
`<PricingCards>`.
2. Create `src/components/PricingCards.tsx` — a Client Component with:
- Monthly/annual toggle (useState). Annual prices are monthly × 0.8.
- Three tiers: Hobby (free), Pro, Business. Read plan data from
`src/config/pricing.ts` — not hardcoded in JSX.
- A feature matrix table below the cards showing which features each tier
includes. Use checkmarks and dashes; do not use emojis in code.
- A "Get started" CTA for Hobby (links to /sign-up) and "Subscribe" for
paid tiers.
3. Create `src/config/pricing.ts` exporting a `PLANS` array. Each plan has:
{ id, name, monthlyPriceUsd, stripePriceIdMonthly, stripePriceIdAnnually,
features: string[], highlighted: boolean }
Read Stripe price IDs from env vars:
NEXT_PUBLIC_STRIPE_PRICE_PRO_MONTHLY
NEXT_PUBLIC_STRIPE_PRICE_PRO_ANNUALLY
NEXT_PUBLIC_STRIPE_PRICE_BIZ_MONTHLY
NEXT_PUBLIC_STRIPE_PRICE_BIZ_ANNUALLY
4. Create `src/app/api/checkout/route.ts` (POST). Accept `{ priceId, userId }`.
Create a Stripe Checkout Session (mode: "subscription") with:
- success_url: NEXT_PUBLIC_APP_URL + /dashboard?checkout=success
- cancel_url: NEXT_PUBLIC_APP_URL + /pricing
Return `{ url }`.
5. In PricingCards, the Subscribe button POSTs to /api/checkout and redirects
to the returned url.
6. Install `stripe` package. Use env var STRIPE_SECRET_KEY.

3. Expected File Changes

package.json (stripe)
src/app/pricing/page.tsx (new — Server Component shell)
src/components/PricingCards.tsx (new — Client Component with toggle)
src/config/pricing.ts (new — plan definitions)
src/app/api/checkout/route.ts (new — Stripe Checkout Session)
.env.local.example (STRIPE_* and NEXT_PUBLIC_* vars)

4. Review Checklist

  • STRIPE_SECRET_KEY is never imported in a Client Component or exposed via NEXT_PUBLIC_.
  • The Checkout Session uses mode: "subscription" not mode: "payment" for recurring billing.
  • Annual price IDs are separate Stripe Price objects — not a computed discount in code.
  • The toggle shows annual savings clearly (e.g. “Save 20%”).
  • The PLANS array is the single source of truth — feature matrix re-uses the same data, not a separate hardcoded table.
  • Error handling on the checkout POST: returns a 500 with a message if Stripe throws.
  • No console.log of Stripe keys or customer data left in the code.

5. Test Commands

3000/pricing
bun dev
# Toggle monthly/annual — confirm prices update correctly
# Confirm annual = monthly * 0.8
# Test checkout endpoint with a test price ID
curl -X POST http://localhost:3000/api/checkout \
-H "Content-Type: application/json" \
-d '{"priceId":"price_test_xxx","userId":"user_1"}' | jq .url
# Expect a Stripe Checkout URL
bun tsc --noEmit

6. Common Failures

  • STRIPE_SECRET_KEY leaked client-side — agent imports stripe in PricingCards.tsx. Move all Stripe calls to the API route.
  • Annual toggle shows same price as monthly — agent calculates price * 0.8 but forgets to use the isAnnual state. Confirm the toggle state is passed to the price display.
  • Checkout returns 500 with “No such price” — price ID env var not set or wrong environment (test vs live). Verify with stripe prices retrieve <id> in the Stripe CLI.
  • success_url is relative — Stripe requires an absolute URL. Prefix with NEXT_PUBLIC_APP_URL.

7. Fix Prompt

Fix Prompt
The annual/monthly toggle renders correctly visually but the Subscribe button
always sends the monthly priceId regardless of which toggle state is active.
In PricingCards.tsx, the `priceId` passed to the checkout POST must be
`isAnnual ? plan.stripePriceIdAnnually : plan.stripePriceIdMonthly`.
Check that the isAnnual state variable is read at the point the button's
onClick handler calls the checkout API.

8. PR Description

PR description
## Feature: Pricing page with Stripe Checkout
- `/pricing` page with monthly/annual toggle and three tiers (Hobby, Pro, Business)
- Feature matrix driven from `src/config/pricing.ts` — one source of truth
- POST `/api/checkout` creates a Stripe Subscription Checkout Session
- Price IDs read from env vars — no hardcoded Stripe IDs in code
- Annual plan = 20% discount via separate Stripe Price objects
**Required env vars**: `STRIPE_SECRET_KEY`, `NEXT_PUBLIC_STRIPE_PRICE_*`,
`NEXT_PUBLIC_APP_URL` (see `.env.local.example`)