Webhooks

Get a signed POST to your server when something happens, instead of polling.

Set it up

Save your endpoint URL in your app's Integration section in the dashboard. You get a signing secret, whsec_..., shown once.

Handle an event

import { verifyWebhook } from "kredo";
 
app.post("/credits-webhook", express.raw({ type: "application/json" }), (req, res) => {
  const event = verifyWebhook(req.body, req.header("x-credits-signature"), process.env.CREDITS_WEBHOOK_SECRET!);
  if (event.type === "charge.succeeded") console.log(event.data.amount.credits);
  res.sendStatus(200);
});

verifyWebhook checks the signature and throws on anything fake or older than five minutes. Pass the raw body, not parsed JSON.

Events

EventWhen
charge.succeededA charge went through
hold.created, hold.captured, hold.releasedA hold was made, charged or returned
refund.succeededYou refunded a user
connection.approved, connection.revokedA user connected or disconnected your app
payout.paidYour earnings were paid out

Answer with any 2xx. Anything else is retried, so handle the same event id twice safely.