Skip to main content
8Space includes optional Stripe integration for payment processing. Configure Stripe to enable billing features in the landing site.
Billing is optional. If Stripe is not configured, payment features will be disabled.

Overview

The Stripe integration supports:
  • One-time payments (Stripe Checkout in payment mode)
  • Recurring subscriptions (Stripe Checkout in subscription mode)
  • Customer portal for subscription management
  • Webhook handling for payment events
  • Tax ID collection
  • Promotional codes

Environment Variables

Add Stripe credentials to packages/landing/.env.local:
string
required
Stripe secret key for API authentication.Test mode: sk_test_...Live mode: sk_live_...Get from: Stripe Dashboard → Developers → API keys
string
required
Webhook signing secret for verifying Stripe webhook events.Format: whsec_...Get from: Stripe Dashboard → Developers → Webhooks

Example Configuration

packages/landing/.env.local
Never commit Stripe secrets to version control. Add .env.local to .gitignore.

Stripe Setup

1

Create Stripe Account

Sign up at stripe.com if you don’t have an account.
2

Get API Keys

  1. Navigate to Developers → API keys
  2. Copy the Secret key (starts with sk_test_ or sk_live_)
  3. Add to .env.local as STRIPE_SECRET_KEY
3

Create Products & Prices

  1. Navigate to Products
  2. Click “Add product”
  3. Set name, description, and pricing
  4. Copy the Price ID (starts with price_)
Use this Price ID in your checkout calls.
4

Configure Webhooks

  1. Navigate to Developers → Webhooks
  2. Click “Add endpoint”
  3. Set endpoint URL:
    • Local: Use Stripe CLI
    • Production: https://yourdomain.com/api/stripe/webhook
  4. Select events to listen for
  5. Copy the Signing secret (starts with whsec_)
  6. Add to .env.local as STRIPE_WEBHOOK_SECRET

API Implementation

The Stripe integration is implemented in packages/landing/libs/stripe.ts and used by Next.js API routes.

Stripe Client

packages/landing/libs/stripe.ts

Checkout Session

Create a checkout session for payment or subscription:
packages/landing/libs/stripe.ts

Customer Portal

Create a customer portal session for subscription management:
packages/landing/libs/stripe.ts

API Routes

The landing package includes API routes for Stripe operations.

Create Checkout Route

Endpoint: POST /api/stripe/create-checkout Location: packages/landing/app/api/stripe/create-checkout/route.ts Request body:
Response:
Implementation:
packages/landing/app/api/stripe/create-checkout/route.ts

Create Portal Route

Endpoint: POST /api/stripe/create-portal Location: packages/landing/app/api/stripe/create-portal/route.ts Request body:
Response:
The portal route currently returns an error if no customerId is found. You’ll need to implement customer lookup from your database.
Implementation:
packages/landing/app/api/stripe/create-portal/route.ts

Customer Data Storage

The current implementation does not store Stripe customer IDs in the database. You’ll need to add this functionality.
Add a table to store Stripe customer data:

Update Customer Portal

Modify the portal route to look up the customer ID:

Webhook Handling

Webhooks notify your application of Stripe events (payment success, subscription canceled, etc.).

Webhook Route

Create packages/landing/app/api/stripe/webhook/route.ts:

Important Webhook Events

Local Testing with Stripe CLI

Test webhooks locally using the Stripe CLI.
1

Install Stripe CLI

Download from stripe.com/docs/stripe-cliOr install via package manager:
2

Authenticate

3

Forward Webhooks

Copy the webhook signing secret (starts with whsec_) and add to .env.local:
4

Trigger Test Events

Testing Payments

Test Cards

Stripe provides test cards for different scenarios: Use any future expiry date and any 3-digit CVC.

Test Checkout Flow

Production Checklist

1

Switch to Live Mode

  • Get live API keys from Stripe Dashboard
  • Update STRIPE_SECRET_KEY with sk_live_...
  • Update webhook secret with live endpoint secret
2

Configure Webhook Endpoint

  • Add production URL to Stripe Dashboard
  • Select events to listen for
  • Test webhook delivery
3

Test Payment Flow

  • Use real credit cards in test mode first
  • Verify webhooks are received
  • Check customer data is saved
4

Security Review

  • Verify webhook signature validation
  • Ensure secrets are not committed
  • Enable HTTPS only
  • Review Stripe security best practices

Troubleshooting

  • Verify STRIPE_WEBHOOK_SECRET matches the endpoint secret
  • For local testing, use Stripe CLI’s secret (starts with whsec_)
  • Check that you’re passing the raw request body to constructEvent
Implement customer ID storage:
  1. Create stripe_customers table
  2. Save customer ID on checkout completion
  3. Update portal route to look up customer ID
  • Verify STRIPE_SECRET_KEY is set correctly
  • Check that Price ID exists in Stripe Dashboard
  • Ensure mode matches price type (payment for one-time, subscription for recurring)

Next Steps

Environment Variables

Configure all required Stripe variables

Database Setup

Add customer table for Stripe IDs