Express & Next.js

Start with a route.
Keep the context.

The request is small. The operation identity, storage, authorization and worker setup are the parts that make it recoverable.

Server-side checkout

Same billing service.
Your framework.

These route fragments assume an initialized billing service and application-owned authentication. They are not complete applications.

checkout.tsServer only
// billing uses your storage and authorization policy.
// Middleware authenticates the user and loads the order.
app.post(
  '/checkout',
  requireUser,
  loadOrder,
  async (req, res) => {
    const session = await billing.createCheckout(
      actorFor(req.user, 'checkout:' + req.order.id),
      {
        customerId: req.order.stripeCustomerId,
        items: [{ priceId: req.order.priceId, quantity: 1 }],
        reference: req.order.id,
      },
    );
    res.json({ url: session.url });
  },
);
export const runtime = 'nodejs';

// billing uses your storage and authorization policy.
export async function POST(request: Request) {
  const { user, order } = await authorizedOrder(request);
  const session = await billing.createCheckout(
    actorFor(user, 'checkout:' + order.id),
    {
      customerId: order.stripeCustomerId,
      items: [{ priceId: order.priceId, quantity: 1 }],
      reference: order.id,
    },
  );
  return Response.json({ url: session.url });
}
A stable order identity is reused on retry. Prices and customer ownership are checked on the server.

Choose the store you run

The same contracts.
Different deployment requirements.

Install the driver for your chosen adapter. MongoDB needs a replica set; SQLite is for local development. Each production deployment still needs recovery and capacity validation.