Skip to content

Edge Runtimes + Stripe (Hono)

TL;DR / when to use this: A minimal payments stack: Hono on an edge runtime (Cloudflare Workers, AWS Lambda, Node) + Stripe Checkout + Stripe webhooks. This is the pattern behind Wildium's subscription flows — prefer Stripe-hosted UIs (Checkout, Customer Portal) over hand-rolled payment forms.

Pricing models worth knowing

  • Freemium — free tier with a premium upgrade
  • Free trial
  • One-time payment
  • Tiered subscriptions — Beginner / Professional / Enterprise
  • Seat-based — charge per user
  • Metered — charge on usage (tokens, credits; the AWS model)

Hono app

npm create hono@latest stripe-hono   # choose aws-lambda, cloudflare-workers, node.js, next.js
npm run dev
npm install stripe dotenv

Checkout endpoint

app.post('/checkout', async (c) => {
  try {
    const session = await stripe.checkout.sessions.create({
      payment_method_types: ['card'],
      line_items: [
        { price: 'price_...', quantity: 1 },   // price id from the Stripe product
      ],
      mode: 'payment',
      success_url: 'http://localhost:3000/success',
      cancel_url: 'http://localhost:3000/cancel',
    });
    return c.json(session);
  } catch (error: any) {
    console.error(error);
    throw new HTTPException(500, { message: error?.message });
  }
});

Webhooks

Stripe → your server events: checkout.session.completed, expired, canceled, created, delayed, customer.subscription.updated, customer.subscription.deleted.

Test locally with the Stripe CLI:

stripe login
stripe listen -e checkout.session.completed --forward-to http://localhost:3000/webhook
stripe listen -e customer.subscription.updated --forward-to http://localhost:9095/api/webhook

Verify signature headers on the webhook handler before trusting any event.

Next.js variant

npx create-next-app app-name
npm i stripe @stripe/stripe-js

stripe is the backend SDK; @stripe/stripe-js is the frontend. In a Next app, forward webhooks to the dev server with the same stripe listen command.

See also