Documentation

Payments

Learn how to set up and use Stripe for handling payments and subscriptions

Dirstarter uses Stripe for payment processing and subscription management. This integration handles standard listings, premium spots, and recurring subscriptions.

Stripe Setup

  1. Create a Stripe account at stripe.com
  2. Get your API keys from the dashboard
  3. Add the following environment variables:
.env
STRIPE_SECRET_KEY=sk_test_...

We only use the secret key. No need to create a publishable key.

Stripe is optional, and turns on when both STRIPE_SECRET_KEY and STRIPE_WEBHOOK_SECRET are set. Without it, every submission is free: the tier cards, checkout, billing portal and upgrade buttons are hidden, and the webhook route returns 404.

Product Configuration

We recommend creating the following products in your Stripe dashboard:

Free

{
  name: "Free Listing",
  description: "Free listing with wait time",
  amount: 0,
  currency: "usd",
  type: "one_time",
  features: [
    "• {queue} processing time", // will be replaced with the actual wait time
    "✗ No content updates",
    "✗ Do-follow link to your website",
    "✗ No featured spot",
    "✗ No prominent placement",
  ]
}

Standard (One-time payment)

{
  name: "Standard Listing",
  description: "Do-follow link with faster processing",
  amount: 97, // set your own price
  currency: "usd",
  type: "one_time",
  features: [
    "✓ 24h processing time",
    "✓ Unlimited content updates",
    "✓ Do-follow link to your website",
    "✗ No featured spot",
    "✗ No prominent placement",
  ]
}

Premium (Subscription)

{
  name: "Premium Listing",
  description: "Featured placement with do-follow link",
  amount: 197, // set your own price
  currency: "usd",
  type: "recurring",
  interval: "month",
  features: [
    "✓ 12h processing time",
    "✓ Unlimited content updates",
    "✓ Do-follow link to your website",
    "✓ Featured spot on homepage",
    "✓ Prominent placement"
  ]
}

The icons at the beginning of each feature are optional, but recommended for better readability. They are rendered using proper colors and icons.

Populating Stripe Products

You can quickly set up the recommended Stripe products and prices using the provided script in your project at scripts/setup-stripe-products.ts. This script will create all necessary products and prices in your Stripe account as defined for Dirstarter.

To run the script, use:

bun run scripts/setup-stripe-products.ts

If you are not using Bun, you can install the ts-node package to run the script.

Make sure your environment variables are set up with your Stripe secret key before running the script. This is useful for initial setup or replicating your Stripe environment.

Webhook Setup

Stripe webhooks are used to handle asynchronous events like successful payments and subscription changes.

Local Development

In local development, you can use the Stripe CLI to forward events to your local server.

Install Stripe CLI

Terminal
brew install stripe/stripe-cli/stripe

Login to Stripe

stripe login

Forward Events

stripe listen --forward-to localhost:5173/api/stripe/webhooks

The webhook secret is printed in the terminal. Copy it and add it to your environment variables.

.env
STRIPE_WEBHOOK_SECRET=whsec_...

Trigger Test Events

stripe trigger checkout.session.completed
stripe trigger customer.subscription.deleted

Production

Add endpoint: https://your-domain.com/api/stripe/webhooks

Select events to listen for:

  • checkout.session.completed
  • customer.subscription.deleted

Copy the webhook secret and add it to your environment variables.

.env
STRIPE_WEBHOOK_SECRET=whsec_...

Webhook Events

The boilerplate handles these webhook events:

  1. Paid Listings (Standard / Premium)

    app/api/stripe/webhooks/route.ts
    case "checkout.session.completed":
      // Skip delayed payments (SEPA, bank transfer) that have not settled yet
      // Read the tier from the session metadata the server wrote at checkout
      // Upgrade the tool and make the payer its owner if it has none
      // Send tool.tier_upgraded (emails the owner and the admin)
      // Fill in missing content and media for the paid listing
      await upgradeListing(session)
      break

    The payer becomes the tool's owner when the tool has no owner yet. A payer whose verified email is on the tool's domain also verifies it. See ownership and verification.

  2. Subscription Cancellation

    case "customer.subscription.deleted":
      // Return the tool to the tier it had before the subscription
      // Send tool.tier_downgraded (emails the owner and the admin)
      await downgradeListing(event.data.object)
      break

    The tool goes back to the tier it had before the subscription, so an earlier one-time purchase survives the cancellation. A tool an admin has since moved to another tier keeps that tier.

Last updated on

On this page

Join hundreds of directory builders

Build your directory, launch, earn

Don't waste time on Stripe subscriptions or designing a pricing section. Get started today with our battle-tested stack and built-in monetization features.

Get Lifetime Access
30-day money-back guarantee