Skip to main content
Stripe is a powerful payment platform offering comprehensive billing, subscription management, and global payment support. It’s the most feature-rich option in ShipFree.

Prerequisites

  • A Stripe account (sign up here)
  • Your ShipFree application running locally or deployed

Setup Instructions

Step 1: Get Your API Keys

  1. Log in to your Stripe Dashboard
  2. Navigate to Developers → API keys
  3. Copy your Secret key (starts with sk_test_ for test mode)
  4. You’ll also need the Publishable key later (starts with pk_test_)
Never commit your secret key to version control. Use environment variables.

Step 2: Create Products and Prices

You need to create products in Stripe for each pricing plan.
  1. Go to Products in your Stripe Dashboard
  2. Click Add product
  3. Create products matching your plans (Starter, Pro, Enterprise)
For each product:
  • Set the name (e.g., “Starter Plan”)
  • Set the description
  • Add pricing:
    • Monthly: $9.90/month (recurring)
    • Yearly: $99/year (recurring)
  • Set the billing period
  • Save and copy the Price ID (starts with price_)

Step 3: Configure Environment Variables

Add these variables to your .env file:
The NEXT_PUBLIC_ prefix makes these variables accessible in the browser. Only use it for non-sensitive data like Price IDs.

Step 4: Update Payment Configuration

The price IDs are automatically read from environment variables in src/config/payments.ts. Verify your configuration:

Step 5: Set Up Webhooks

Stripe uses webhooks to notify your application about events (payments, subscription changes, etc.).

For Local Development

  1. Install the Stripe CLI:
  2. Log in to Stripe CLI:
  3. Forward webhooks to your local server:
  4. The CLI will output a webhook signing secret (starts with whsec_). Add it to your .env:

For Production

  1. Go to Developers → Webhooks in your Stripe Dashboard
  2. Click Add endpoint
  3. Set the endpoint URL: https://yourdomain.com/api/webhooks/payments
  4. Select events to listen for:
    • customer.created
    • customer.updated
    • customer.deleted
    • customer.subscription.created
    • customer.subscription.updated
    • customer.subscription.deleted
    • invoice.payment_succeeded
    • invoice.payment_failed
    • checkout.session.completed
  5. Click Add endpoint
  6. Copy the Signing secret and add it to your production environment variables

Testing in Development

Test Mode

Stripe provides test mode by default. Use test API keys (starting with sk_test_ and pk_test_).

Test Cards

Use these test card numbers for testing:
  • Use any future expiration date
  • Use any 3-digit CVC
  • Use any valid ZIP code

Testing Subscriptions

  1. Start your development server:
  2. In another terminal, start Stripe webhook forwarding:
  3. Navigate to your pricing page and create a checkout session
  4. Use a test card to complete the payment
  5. Verify the webhook events are received and processed

Testing the Customer Portal

The Stripe Customer Portal allows customers to manage their subscriptions:
The portal allows customers to:
  • Update payment methods
  • View invoices
  • Cancel subscriptions
  • Update billing information

Stripe Implementation Details

The Stripe adapter is implemented in src/lib/payments/providers/stripe.ts.

Key Features

Checkout Sessions

Creates Stripe Checkout sessions with:
  • Support for one-time and recurring payments
  • Trial periods
  • Promotional codes
  • Automatic tax calculation (if configured)

Customer Management

  • Automatically creates or retrieves customers
  • Links customers to your user records
  • Stores customer metadata

Subscription Handling

  • Retrieves subscription details
  • Maps Stripe status to unified status
  • Handles seat-based billing
  • Supports immediate or end-of-period cancellation

Webhook Processing

The adapter processes these Stripe webhook events:
  • customer.created, customer.updated, customer.deleted
  • customer.subscription.created, customer.subscription.updated, customer.subscription.deleted
  • invoice.payment_succeeded, invoice.payment_failed
  • checkout.session.completed
Webhook signature validation:

Going Live

Pre-Launch Checklist

  • Replace test API keys with live keys (sk_live_, pk_live_)
  • Create live products and prices in Stripe
  • Update environment variables with live price IDs
  • Configure production webhook endpoint
  • Set up webhook signing secret for production
  • Enable Stripe Radar for fraud prevention
  • Configure email receipts in Stripe Dashboard
  • Set up tax settings (if applicable)
  • Test the complete checkout flow in production

Security Best Practices

  1. Never expose secret keys: Keep STRIPE_SECRET_KEY server-side only
  2. Validate webhooks: Always verify webhook signatures
  3. Use HTTPS: Stripe requires HTTPS for production webhooks
  4. Handle errors gracefully: Don’t expose Stripe errors to users
  5. Log securely: Don’t log sensitive payment information

Troubleshooting

Webhook Not Received

  1. Check that Stripe CLI is running (for local dev)
  2. Verify webhook endpoint is accessible
  3. Check webhook logs in Stripe Dashboard
  4. Ensure STRIPE_WEBHOOK_SECRET is set correctly

Checkout Session Fails

  1. Verify STRIPE_SECRET_KEY is set
  2. Check that price IDs exist and are correct
  3. Ensure products are active in Stripe Dashboard
  4. Check Stripe Dashboard logs for detailed errors

Customer Portal Not Working

  1. Ensure customer exists in Stripe
  2. Verify customer ID format (remove stripe_ prefix if present)
  3. Check that customer has an active subscription

Additional Resources

Support

For Stripe-specific issues: For ShipFree integration issues:
  • Check the source code in src/lib/payments/providers/stripe.ts
  • Review webhook handling in src/app/api/webhooks/payments/route.ts