Scaffold Polar billing (checkout + webhooks) behind feature flag (Vibe Kanban)#119
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: baa3dc9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
WalkthroughThis pull request adds a Polar billing integration scaffold behind a feature flag. Changes include a Prisma migration and schema additions for subscription metadata and Polar IDs, a new dependency ( Sequence Diagram(s)sequenceDiagram
participant User as User/Browser
participant App as App (Next.js)
participant DB as Database
User->>App: GET /api/billing/me
App->>App: Check enablePolarBillingFlag
App->>App: Verify session
App->>DB: Query user metadata
DB-->>App: Return billing data (tier, status, dates, IDs)
App-->>User: Return BillingMeResponse (tier, status, dates)
sequenceDiagram
participant User as User/Browser
participant App as App (Next.js)
participant PolarAPI as Polar API
User->>App: GET /api/billing/polar/checkout
App->>App: Check enablePolarBillingFlag
App->>App: Verify session & email
App->>PolarAPI: POST /v1/checkouts (email, product, return URLs, metadata)
PolarAPI-->>App: Return checkout_url
App-->>User: 303 Redirect to Polar checkout_url
User->>PolarAPI: Complete checkout
PolarAPI-->>User: Redirect to success_url (?checkout=success)
sequenceDiagram
participant PolarAPI as Polar API
participant App as App (Webhook Handler)
participant DB as Database
PolarAPI->>App: POST /api/webhooks/polar (subscription event)
App->>App: Check enablePolarBillingFlag
App->>App: Verify webhook signature
App->>App: Validate event type (subscription.*)
App->>App: Resolve user (external_id, metadata.user_id, or email)
App->>App: Derive tier & status
App->>DB: Upsert user metadata (tier, status, cancel flag, dates, polar IDs)
DB-->>App: Confirm update
App-->>PolarAPI: Return 202 Accepted
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Free 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (3)
✏️ Tip: You can disable this entire section by setting Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
…ehind a static feature flag** (`enablePolarBillingFlag`) that currently always returns `false`. - Feature flag: `apps/app/src/lib/feature-flags.ts` - Webhook handler (signature-verified via `@polar-sh/sdk/webhooks`): `apps/app/src/app/api/webhooks/polar/route.ts` - Checkout + portal redirects: `apps/app/src/app/api/billing/polar/checkout/route.ts`, `apps/app/src/app/api/billing/polar/portal/route.ts` - Logged-in billing status endpoint (used by UI): `apps/app/src/app/api/billing/me/route.ts` - Upgrade UI component: `apps/app/src/components/auth/upgrade-prompt.tsx` (also mounted in `apps/app/src/components/brand/brand-panel.tsx`) - Billing settings page (404s while flag is off): `apps/app/src/app/settings/billing/page.tsx` - DB fields + migration for subscription state: `apps/app/prisma/schema.prisma`, `apps/app/prisma/migrations/20260112123000_add_polar_billing_fields/migration.sql` - Polar-side setup doc: `docs/development/POLAR_SETUP.md`
…ot-app` as a `patch`).
dd2e512 to
6f08609
Compare
Implements the deferred Task 0.3 (Polar Integration) end-to-end, while keeping every codepath completely hidden behind a static feature flag until brand features are ready.
What changed
enablePolarBillingFlag(billing.enable-polar) that currently always evaluates tofalse.GET /api/billing/meto expose current plan/status to the UI.GET /api/billing/polar/checkoutto create a Polar checkout session and redirect.GET /api/billing/polar/portalto create a Polar customer session and redirect to the customer portal.POST /api/webhooks/polarto react tosubscription.*events./settings/billing(gated by the feature flag).UpgradePromptUI component (mounted in the Brand panel) that becomes visible only when billing is enabled.user_metadatato store Polar + subscription state and added a Prisma migration.docs/development/POLAR_SETUP.md.Why
This task is intentionally deferred until all brand features are verified via manual tier setting (Task 0.1). Shipping the billing plumbing now (but hidden) reduces future integration risk and makes enabling payments a deliberate, single-flag change when we’re ready.
Implementation details
404.external_customer_id(and metadata) to the appuserId, so webhook events can be mapped back to users reliably.@polar-sh/sdk/webhooks(Standard Webhooks headers).user_metadata;past_dueis treated asbrand(status recorded aspast_due), and cancellation/revocation downgrades appropriately.external_customer_id.POLAR_ACCESS_TOKEN,POLAR_PRODUCT_ID, andPOLAR_WEBHOOK_SECRET(plus optional sandbox settings) — seedocs/development/POLAR_SETUP.md.This PR was written using Vibe Kanban
Summary by CodeRabbit
New Features
Documentation
✏️ Tip: You can customize this high-level summary in your review settings.