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
| Event | When |
|---|---|
charge.succeeded | A charge went through |
hold.created, hold.captured, hold.released | A hold was made, charged or returned |
refund.succeeded | You refunded a user |
connection.approved, connection.revoked | A user connected or disconnected your app |
payout.paid | Your earnings were paid out |
Answer with any 2xx. Anything else is retried, so handle the same event id twice safely.