Skip to content

Billing (Stripe)

@delightstack/stripe is Stripe billing for SvelteKit apps on Cloudflare Workers — define your plans and meters in code, sync them to Stripe, handle webhooks, and gate features by subscription.

  • Config-driven plans & meters — declare them once with defineBillingConfig; sync to Stripe.
  • Subscriptions — checkout, subscription state, and a webhook-driven sync into your database.
  • Metered usage — report usage events for usage-based pricing.
  • Webhooks — verified webhook handling with handleWebhook.
  • Subscription guards — gate SvelteKit routes by plan/entitlement.
Terminal window
pnpm add @delightstack/stripe stripe
ImportUse
@delightstack/stripe/serverdefineBillingConfig, createBillingHandle, syncSubscription, syncAll, reportMeterEvent, handleWebhook, getStripe
@delightstack/stripe/sveltekitcreateBillingGuards
@delightstack/stripe/clientreactive Svelte 5 billing client
import { defineBillingConfig } from '@delightstack/stripe/server';
export const billing = defineBillingConfig({
secret_key: env.STRIPE_SECRET_KEY,
plans: [
{ id: 'pro', name: 'Pro', price: 2000, interval: 'month', entitlements: ['premium'] },
],
meters: [
{ id: 'ai-tokens', name: 'AI tokens', event_name: 'ai_tokens' },
],
});
hooks.server.ts
import { createBillingHandle } from '@delightstack/stripe/server';
export const billingHandle = createBillingHandle({
config: billing,
getDb: (event) => event.platform.env.DB,
});

syncAll() pushes your plans/meters to Stripe; handleWebhook() verifies incoming events and syncSubscription() reconciles them into your database.

+page.server.ts
import { createBillingGuards } from '@delightstack/stripe/sveltekit';
const { requirePlan } = createBillingGuards(billing);
export const load = (event) => {
requirePlan(event, 'pro'); // redirect / 402 if not subscribed
};
import { reportMeterEvent } from '@delightstack/stripe/server';
await reportMeterEvent(billing, { meter: 'ai-tokens', value: 1200, customer });