Wiring Stripe Checkout and DoorDash Delivery into One Marketplace

Order customization, payment intents and delivery dispatch: keeping three systems in sync without losing an order.
Caterbox is a catering marketplace: a host customizes an order, pays, and a courier delivers it. That means three systems must agree on the state of every order: our database, Stripe and the delivery provider.
Make the order the source of truth
Every order lives in our database with an explicit status: draft, awaiting_payment, paid, dispatched, delivered or failed. External systems only move an order from one status to the next; they never define it.
Payment intents and webhooks
The client confirms a Stripe PaymentIntent, but the order is only marked paid when the payment_intent.succeeded webhook arrives. The browser can close or lose connection; the webhook still fires.
app.post("/webhooks/stripe", express.raw({ type: "application/json" }), (req, res) => {
const event = stripe.webhooks.constructEvent(
req.body, req.headers["stripe-signature"], process.env.STRIPE_WEBHOOK_SECRET,
);
if (event.type === "payment_intent.succeeded") {
markPaidAndDispatch(event.data.object.metadata.orderId);
}
res.sendStatus(200);
});Idempotency everywhere
- Webhooks can arrive twice. Store processed event ids and skip duplicates.
- Use Stripe idempotency keys when creating intents from retries.
- Dispatch delivery only when moving from paid to dispatched, never from any other state.
Delivery dispatch
Once paid, the system requests a delivery quote, creates the delivery and stores the provider's id on the order. Delivery status webhooks then update the order. If dispatch fails, the order goes to a visible failed state for a human to handle, rather than silently retrying forever.
Takeaway
Integrations become predictable when one system owns the state and every external event is just a validated, idempotent transition.









