Payment

Set up Stripe for handling payments and subscriptions

Payment

LaunchSaaS uses Stripe for payment management, handling both one-time payments and recurring subscriptions.

Setup

1. Create Stripe Account

  1. Sign up at stripe.com
  2. Complete account verification (required for production)
  3. You can start development with test mode immediately

2. Get API Keys

  1. Go to Stripe DashboardDevelopersAPI keys
  2. Copy your Secret key (starts with sk_test_ for test mode)
  3. Add to your .env file:
STRIPE_SECRET_KEY="sk_test_..."

Use test keys (sk_test_...) for development and live keys (sk_live_...) for production.

3. Create Products and Prices

  1. Go to Stripe DashboardProduct Catalog
  2. Click Add product
  3. Fill in product details:
    • Name: e.g., "Lifetime Access"
    • Description: Your product description
    • Price: Set your price (one-time or recurring)
  4. Click "Save product"
  5. Copy the Price ID (starts with price_)

4. Configure Products

Update the product configuration in src/config/product.ts:

  • For subscriptions: Configure plans with priceId from Stripe
  • For one-time payments: Configure products with priceId from Stripe
  • Customize onPaymentComplete hooks for post-payment actions

5. Set Up Webhooks

Webhooks notify your application of payment events in real-time.

Development (Local Testing)

Use the Stripe CLI to forward webhooks to your local server:

  1. Install Stripe CLI:
# macOS
brew install stripe/stripe-cli/stripe

# Other platforms: https://stripe.com/docs/stripe-cli
  1. Login to Stripe:
stripe login
  1. Forward webhooks:
stripe listen --forward-to localhost:3000/api/auth/stripe/webhook
  1. Copy the webhook secret (starts with whsec_) and add to your .env file:
STRIPE_WEBHOOK_SECRET="whsec_..."

Keep the stripe listen command running while developing.

Production

  1. Go to Stripe DashboardDevelopersWebhooks
  2. Click Add endpoint
  3. Set endpoint URL: https://yourdomain.com/api/auth/stripe/webhook
  4. Select events to listen to:
    • checkout.session.completed
    • customer.subscription.created
    • customer.subscription.updated
    • customer.subscription.deleted
    • invoice.payment_succeeded
    • invoice.payment_failed
  5. Click Add endpoint
  6. Copy the Signing secret and add to your production environment

If you are setting up the environment, now you can go back to the Environment Setup guide and continue.

Payment Completion Hooks

LaunchSaaS allows you to run custom code when a payment completes. Configure in src/config/product.ts:

One-Time Payments

oneOff: [
  {
    name: "Lifetime",
    priceId: "price_...",
    onPaymentComplete: async ({ stripeSession, payment, product }) => {
      // Custom logic after payment
      // e.g., grant access, send welcome email, add to repository
    },
  },
];

Subscriptions

recurring: {
  plans: [...],
  onSubscriptionComplete: async ({ subscription, plan }) => {
    // Custom logic after subscription created
  },
  onSubscriptionCancel: async ({ subscription }) => {
    // Custom logic after subscription cancelled
  },
}

GitHub Integration (Optional)

LaunchSaaS can automatically add customers as GitHub collaborators after payment:

  1. Enable in .env:
GITHUB_INTEGRATION_ENABLED=true
GITHUB_TOKEN="your-personal-access-token"
GITHUB_REPO="owner/repo"
  1. Generate a GitHub Personal Access Token with admin:org and repo scopes at GitHub Settings

Testing Cards

For testing Stripe integration, use test credit cards:

Card NumberDescription
4242 4242 4242 4242Successful payment
4000 0000 0000 32203D Secure required
4000 0000 0000 9995Insufficient funds

Use any future expiration date and any 3-digit CVC.

References

Next Steps