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.
// 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 });
}Run the local payment app.
Website, checkout route, webhook endpoint and worker. No Docker or database server required.
Next.js · Node runtimeWire up the route handlers.
Keep webhook bytes intact and run the durable worker outside short-lived requests.
Express · FirestoreTry the deployed npm consumer.
The online sandbox runs the published package with actual Stripe test records and signed receipts.
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.
npm install pgMongoDBReplica-set transactions; standalone servers are insufficientnpm install mongodbCloud FirestoreService credentials, indexes and transaction contentionnpm install @google-cloud/firestoreSQLiteLocal development with one active workerIncluded with supported Node.js