Payment Integration

Set up subscription payments with Polar (recommended) or Stripe for your ChatRAG application.

Polar Integration

RECOMMENDED

Polar is built for developers selling software. No complex webhook setup required—just create products and copy the checkout links. Setup takes less than 10 minutes.

Step 1: Create a Polar Account

  1. Visit polar.sh
  2. Sign up with GitHub (takes 2 minutes)
  3. Create your organization
  4. Complete your profile and payment settings

Step 2: Create Your Products

Create subscription products for each tier (Starter, Pro, Enterprise). Here's the recommended structure:

Starter Plan

  • • Price: $9/month
  • • Basic RAG chatbot functionality
  • • Limited messages per day
  • • Public documents only

Pro Plan

  • • Price: $19/month
  • • Unlimited messages
  • • Private document uploads
  • • Priority support
  • • Custom embedding models

Enterprise Plan

  • • Price: $49/month
  • • Team collaboration
  • • Advanced analytics
  • • Custom models
  • • 24/7 Support

Step 3: Create Checkout Links

For each product in your Polar dashboard:

  1. Navigate to your product
  2. Click "Create Checkout Link"
  3. Configure success/cancel URLs (optional)
  4. Copy both the Price ID and Checkout URL

Step 4: Get Your API Token

  1. Go to Polar Settings → API Tokens
  2. Create a new token with appropriate permissions
  3. Copy the token (starts with polar_oat_)

Step 5: Configure Environment Variables

Add these variables to your .env.local file:

# -----------------------------
# PAYMENTS - POLAR
# -----------------------------
POLAR_ACCESS_TOKEN=polar_oat_your_token_here

# Starter Plan
NEXT_PUBLIC_POLAR_PRICE_ID_STARTER=e5603bf0-d155-4e93-8b89-b32952d6f10d
NEXT_PUBLIC_POLAR_CHECKOUT_STARTER=https://buy.polar.sh/polar_cl_1iIjg4vlfkGHL7gO6nnOECblSfUsKZ6IRcsbq4c1OvJ

# Pro Plan
NEXT_PUBLIC_POLAR_PRICE_ID_PRO=82bef751-c308-4a11-b5b9-2589bc335c25
NEXT_PUBLIC_POLAR_CHECKOUT_PRO=https://buy.polar.sh/polar_cl_pTRx8sbL0NuCcgnhZXmJLEGrTrNs6JFQyeynL1qnID3

# Enterprise Plan
NEXT_PUBLIC_POLAR_PRICE_ID_ENTERPRISE=4836f931-0bf6-47fc-9b96-bb7a49e422a1
NEXT_PUBLIC_POLAR_CHECKOUT_ENTERPRISE=https://buy.polar.sh/polar_cl_kFjdC5Glc2AuRUvvaW9zyAHlZTmOl01yeg0bq39al2h

# Optional - only needed for webhook processing (future use)
POLAR_ORGANIZATION_ID=
POLAR_WEBHOOK_SECRET=
POLAR_ORGANIZATION_SLUG=

Step 6: Update Pricing Page

Your src/app/pricing/page.tsx should automatically pick up these environment variables. Verify the Starter plan uses:

{
  name: "Starter",
  price: "9",
  description: "Perfect for trying out the RAG chatbot",
  features: [...],
  polarPriceId: process.env.NEXT_PUBLIC_POLAR_PRICE_ID_STARTER || null
}

Step 7: Test Your Integration

  1. Restart your dev server: npm run dev
  2. Navigate to http://localhost:3000/pricing
  3. Click "Subscribe" on any plan
  4. Verify you're redirected to Polar checkout (not signup page)
  5. Complete a test purchase using Polar's test mode

What You Get with Polar

  • Pre-built checkout pages with branding
  • Automatic subscription management
  • Customer portal for upgrades/downgrades
  • Invoice generation and email notifications
  • Developer-friendly dashboard and API
  • No complex webhook setup required

Stripe Integration (Alternative)

If you prefer Stripe or need more advanced payment features, you can configure Stripe instead of Polar.

Stripe Configuration

# -----------------------------
# PAYMENTS - STRIPE
# -----------------------------
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_...
STRIPE_SECRET_KEY=sk_test_...
STRIPE_WEBHOOK_SECRET=whsec_...
NEXT_PUBLIC_STRIPE_PRICE_ID_PRO=price_...
NEXT_PUBLIC_STRIPE_PRICE_ID_ENTERPRISE=price_...

Note: Stripe requires webhook configuration and additional setup. Refer to the Stripe documentation for detailed integration steps.

Troubleshooting

Redirected to signup page instead of checkout

This means your Price ID or Checkout URL is missing. Verify all environment variables are set correctly and restart your dev server.

Error: "Checkout link not found"

The pricing page code requires BOTH the Price ID AND Checkout URL for each plan. Double-check your .env.local file has both variables populated.

Changes not reflecting

Always restart your dev server after modifying environment variables:Ctrl+C thennpm run dev

Production Deployment

When deploying to production (Vercel, etc.), remember to:

  • Add all Polar environment variables to your hosting platform's environment settings
  • Switch from Polar sandbox to production mode if applicable
  • Update NEXT_PUBLIC_SITE_URL to your production domain
  • Test the complete checkout flow in production
  • Configure success/cancel redirect URLs in Polar to match your production URLs