elements
Start Docs Blog Demos UI Pricing
Elements Manual
  • Getting Started
  • CLI
  • Build
  • Browser
  • Packages
  • TypeScript
  • Elements HTML
  • Assets
  • RPC
  • Router
  • Session
  • Database
  • Migrations
  • LiveTable
  • Channel
  • Jobs
  • Email
  • Payments
    • Payments Setup
    • Checkout
    • The Webhook
    • Subscriptions
    • Going Live
  • JSON
  • Async
  • Style
  • UI
  • JSOC
  • Config
  • Tests
  • Logs
  • Deploy
  • Editors
  • Recipes
  • Licenses
  • Issues
  • Changelog
Manual / Payments/ Payments Setup

Payments Setup

elements man payments/setup

On This Page

  • Config
  • The Client
  • The Stripe Account Step in the Final Report
  • Related

One env value, STRIPE_SECRET_KEY, connects the app to Stripe. Development runs without it, on the test checkout. Production refuses to start without it.

Config

config.jsoc
{ // ... stripe: { // Empty in development, which runs on the test checkout. Production // checks it at startup (see The Client). secretKey: env("STRIPE_SECRET_KEY", ""), // Development only, printed by `stripe listen`. Production registers its // own endpoint and stores the secret (see `payments/webhook`). webhookSecret: env("STRIPE_WEBHOOK_SECRET", ""), }, }

Put empty placeholders in config/env/development.env, and nothing else:

config/env/development.env
STRIPE_SECRET_KEY= STRIPE_WEBHOOK_SECRET=

development.env is committed, so the owner's key goes in their copy, or in the shell environment, which env values read first. An edit to the env file rebuilds the config and hot reloads the app and its open pages, so pay buttons switch from the test checkout to Stripe the moment the key is saved. Live keys go in config/env/production.env, which is gitignored. Production checks the key at startup (see The Client), so an app without it never serves a request.

The Client

app/shared/stripe.ts
import Stripe from "stripe"; import { env } from "@elements/app"; import config from "#config"; let client: Stripe | undefined; export function stripeConfigured(): boolean { return config.stripe.secretKey !== ""; } /** True when payments go through the in-app test checkout instead of Stripe. */ export function testCheckout(): boolean { return !stripeConfigured() && env() !== "production"; } export function stripe(): Stripe { client ??= new Stripe(config.stripe.secretKey); return client; }

An empty key in production is refused at startup, before the app serves a request. Put the check in index.ts, ahead of app.start:

index.ts
if (env() === "production" && !stripeConfigured()) { throw new Error("STRIPE_SECRET_KEY is required in production."); }

So a running app can always take a payment: through Stripe when the key is set, through the test checkout when it is not. Pay buttons are always shown; there is no "not set up" state to build.

The Stripe Account Step in the Final Report

The final report names the one step left: create a free Stripe account at dashboard.stripe.com/register (opens in a new tab) (a sandbox works right away, with no business details), open Developers, API keys, copy the secret key (sk_test_...), and add it to config/env/development.env as STRIPE_SECRET_KEY=. Until then payments go through the test checkout. Do not build a settings or setup page for this; the env file is the setting.

Related

  • payments/checkout: the checkout rpc, the test checkout, and fulfillment.
  • payments/webhook: the webhook route and its registration.
  • config: env files and env().
Prev PaymentsNext Checkout
Product
Manual Pricing Compare
Company
History Contact
Legal
Privacy Policy Acceptable Use Terms License Agreement
© Elements Dev Corporation 2026