Prompt-to-PR: Adicionar Página de Preços
SOP para gerar uma página de preços de produção com alternância mensal/anual, matriz de recursos e links de Stripe Checkout em um projeto Next.js Tailwind.
CursorClaude CodeCodexWindsurf Next.jsTypeScriptTailwind
Uma das páginas mais geradas em sessões de codificação com IA. Este guia restringe o agente a produzir links reais e funcionais do Stripe Checkout, em vez de botões de espaço reservado.
1. Requisito
Adicione uma página /pricing com dois ou três planos, uma alternância de cobrança mensal/anual (anual dá 20% de desconto), uma matriz de comparação de recursos e integração com Stripe Checkout. Os preços devem vir de variáveis de ambiente, não sendo codificados em JSX.
2. Primeiro 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_ANNUALLY4. 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. Mudanças Esperadas nos Arquivos
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. Lista de Verificação
STRIPE_SECRET_KEYnunca é importado em um Componente Cliente ou exposto viaNEXT_PUBLIC_.- A Sessão de Checkout usa
mode: "subscription"e nãomode: "payment"para cobrança recorrente. - Os IDs de preço anual são objetos Stripe Price separados — não um desconto calculado no código.
- A alternância mostra claramente a economia anual (ex.: “Economize 20%”).
- O array
PLANSé a única fonte da verdade — a matriz de recursos reutiliza os mesmos dados, não uma tabela separada codificada. - Tratamento de erro no POST do checkout: retorna um 500 com uma mensagem se o Stripe lançar uma exceção.
- Nenhum
console.logde chaves Stripe ou dados do cliente deixados no código.
5. Comandos de Teste
bun dev
# Toggle monthly/annual — confirm prices update correctly# Confirm annual = monthly * 0.8
# Test checkout endpoint with a test price IDcurl -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 --noEmit6. Falhas Comuns
STRIPE_SECRET_KEYvazado no lado do cliente — o agente importastripeemPricingCards.tsx. Mova todas as chamadas Stripe para a rota da API.- Alternância anual mostra o mesmo preço que o mensal — o agente calcula
price * 0.8mas esquece de usar o estadoisAnnual. Confirme que o estado da alternância é passado para a exibição do preço. - Checkout retorna 500 com “No such price” — variável de ambiente do ID do preço não definida ou ambiente errado (teste vs produção). Verifique com
stripe prices retrieve <id>no Stripe CLI. success_urlé relativa — Stripe requer uma URL absoluta. Prefixe comNEXT_PUBLIC_APP_URL.
7. Prompt de Correção
The annual/monthly toggle renders correctly visually but the Subscribe buttonalways 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'sonClick handler calls the checkout API.8. Descrição do PR
## 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`)