Skip to main content
Skip to Content
Cresora Commerce
Integration Guides

Webhooks Guide

Build a signed webhook receiver, verify signatures, and handle retries.

This guide walks through building a production-grade webhook receiver for Cresora events. For the full event catalog, see Event types.

1. Register your endpoint

In the Partner Portal → Settings → Webhooks, add an endpoint. Enter your public HTTPS URL and copy the signing secret — it is displayed once.

2. Implement the receiver

Your endpoint must:

  • Accept POST requests with Content-Type: application/json
  • Return 2xx within 30 seconds
  • Verify the HMAC-SHA256 signature before processing

See Signature verification for the complete verification code.

3. Handle events idempotently

Cresora retries most non-2xx responses, so your handler must be idempotent — processing the same event twice must produce the same outcome. Note that 400, 401, 404, 405, 410 and 422 are treated as permanent rejections and are never retried; see Retry handling.

// Use the envelope's event_id as an idempotency key. db, tx, insertIfAbsent and
// processEvent are placeholders for your own code; insertIfAbsent stands for
// INSERT … ON CONFLICT (event_id) DO NOTHING on a table with a
// unique index on event_id; no row inserted means the event was already processed.
async function handleWebhook(event) {
  await db.transaction(async (tx) => {
    const claimed = await tx.webhookEvents.insertIfAbsent({ eventId: event.event_id });
    if (!claimed) return;          // already processed
    await processEvent(event, tx); // a throw rolls the claim back, so the next attempt processes it again
  });
}

If you process from a queue after answering 200 (below), Cresora does not retry a failure: your queue must. Inside processEvent, read the resource from the API and act on its current state, not on data: retries and redeliveries can arrive out of order. One event is the exception: after hpp_session.payment_unresolved the session still reads PENDING, and later EXPIRED, so act on the event and do not ask the payer to pay again (see Hosted Payment Page).

A throw rolls back only the work inside tx. Anything processEvent does outside it, such as a call to the Cresora API, a shipment or an email, runs again on the next attempt, so make it idempotent too, for example by deriving the Idempotency-Key of a Cresora write from event_id.

4. Respond quickly, process async

Return 200 OK as fast as possible, then process the event in a background job:

// verifyWebhook is on Signature verification and reads the raw body bytes, so capture them:
// app.use(express.json({ verify: (req, _res, buf) => { req.rawBody = buf; } }))
// secret (the endpoint's signing secret) and queue (your job queue) are placeholders.
app.post("/webhooks/cresora", async (req, res) => {
  try {
    verifyWebhook(req, secret);    // throws if it cannot verify; while you rotate secrets, a 500 gets it retried
    await queue.enqueue(req.body); // queue it before you acknowledge it
  } catch (err) {
    console.error("webhook not accepted", err); // log it: a bug here fails every delivery
    return res.sendStatus(500);    // a clean rejection, never an unhandled rejection
  }
  res.sendStatus(200);             // then respond, well inside 30 seconds
});

Retry schedule

AttemptDelay after failure
1st retry30 seconds
2nd retry5 minutes
3rd retry30 minutes
Total4 attempts over roughly 35 minutes

After the 3rd retry the delivery is recorded EXHAUSTED and Cresora stops. No webhook or email is sent; a Webhook delivery failing notification appears under Notifications in your Partner Portal. See Retry handling and Failed deliveries.

Testing locally

Use ngrok or any tunnel service to expose localhost, then register the tunnel URL in the Portal. See Testing webhooks →.