Skip to main content

@latimer-woods-tech/stripe

Stripe billing primitives for Cloudflare Workers. Depends on @latimer-woods-tech/errors.

Installation

Secrets required

API

createStripeClient(secretKey)

Creates a Stripe client pre-configured with the Factory-standard API version and the Workers-native fetch HTTP client.

validateWebhook(request, webhookSecret, stripeClient)

Verifies a Stripe webhook signature and returns the parsed event. Throws ValidationError if the signature header is missing or invalid.

getSubscription(customerId, stripeClient)

Returns the current subscription status for a Stripe customer. status is 'none' when no subscription exists.

createCheckoutSession(opts)

Creates a Stripe Checkout session for a subscription or one-time payment. Returns the hosted Checkout URL.

createPortalSession(opts)

Creates a Stripe Customer Portal session for self-service subscription management. Returns the hosted portal URL.

stripeWebhookHandler(options)

Hono route handler for /webhooks/stripe. Validates the Stripe signature, classifies the subscription event, and dispatches to the matching handler.

priceToTier(priceId, tierMap)

Maps a Stripe price ID to an internal tier slug. Returns 'unknown' for unmapped IDs.

Full example: subscription + portal