Documentation
Integration/Payments (Stripe)

Payments (Stripe)

How to connect Stripe webhooks to reserve policy, sweeps, and exits.

Events Consumed

  • payment_intent.succeeded → compute reserve & sweep surplus.
  • charge.refunded → quote exit paths → execute best → post journals.

Idempotency

Use event.id as idempotency key. Don’t re-sweep if reserve is already met.

Example Handler (TypeScript)

app.post('/stripe/webhook', rawBody, async (req, res) => {
  const event = stripe.webhooks.constructEvent(req.body, sig, process.env.STRIPE_WEBHOOK_SECRET!);
  switch (event.type) {
    case 'payment_intent.succeeded':
      await computeReserveAndSweep();
      break;
    case 'charge.refunded':
      await quoteAndExecuteExit();
      break;
  }
  res.json({ received: true });
});