ShiftFast Docs

Stripe Setup

Create your prices, turn on plan switching, and connect webhooks — in test mode, then again in live mode.

Do this once in test mode for local development, and again in live mode before launch. The two modes don't share anything: products, prices, portal settings, and webhook endpoints all need setting up in each.

Create the products and prices

Every price in src/config/billing.ts needs a matching Stripe Price. For the sample plans, with the Stripe CLI:

# Pro: a monthly and a yearly subscription price
stripe products create --name="Pro"
stripe prices create --product=prod_... --unit-amount=9900 --currency=eur -d "recurring[interval]=month"
stripe prices create --product=prod_... --unit-amount=95040 --currency=eur -d "recurring[interval]=year"

# Lifetime: a one-time price (no recurring interval)
stripe prices create --unit-amount=29900 --currency=eur -d "product_data[name]=Lifetime"

Copy each returned price_... ID into its variable in .env (NEXT_PUBLIC_PRICE_PRO_MONTHLY, NEXT_PUBLIC_PRICE_PRO_YEARLY, NEXT_PUBLIC_PRICE_LIFETIME). Keep each --unit-amount equal to the plan's amount in billing.ts.

Turn on plan switching

Customers upgrade, downgrade, and cancel in Stripe's customer portal, opened from Manage Billing on the billing page. Plan switching is off by default:

  1. Open Settings → Billing → Customer portal.
  2. Under Subscriptions, turn on Customers can switch plans, and add the subscription prices customers can move between (Pro monthly and yearly in the sample plans). One-time plans are bought from the billing page instead.
  3. Set how changes are charged, then save:
    • When customers change plans: Prorate charges and credits, so an upgrade charges the difference for the rest of the period. The default gives upgrades away free until the next renewal.
    • Downgrades (a cheaper plan or shorter interval): Wait until the end of the billing period, so customers keep what they paid for.

Forward webhooks

The app only learns about payments through webhooks. It handles five events: checkout.session.completed, customer.subscription.updated, customer.subscription.deleted, invoice.paid, and invoice.payment_failed.

Locally, forward them with the Stripe CLI and leave it running in its own terminal while you work:

stripe listen --forward-to localhost:3000/api/webhooks/stripe \
  --events checkout.session.completed,customer.subscription.updated,customer.subscription.deleted,invoice.paid,invoice.payment_failed

It prints a signing secret (whsec_...) — copy it into STRIPE_WEBHOOK_SECRET.

In production, go to Developers → Webhooks, add an endpoint at https://your-domain/api/webhooks/stripe with the same five events, and use that endpoint's signing secret in production's STRIPE_WEBHOOK_SECRET.

Testing plan changes

Plan changes made in the portal reach the app through customer.subscription.updated once they take effect. To test an end-of-period downgrade without waiting, run the subscription on a Stripe test clock and advance it past the renewal date.

On this page