Skip to main content
Webhooks allow your application to be notified automatically when changes happen in payments and cashouts.

How it works

When you create a payment or cashout with callbackUrl, Safefy sends an HTTP POST request to that URL whenever status reaches a relevant state. For full domain-specific payloads, see:

Payment events


Cashout events


MED (dispute) events

Delivered through the webhooks registered in the dashboard (Webhooks), not through callbackUrl. Format, fields and best practices in MED webhooks.

Sent headers


Signature

Every callback sent to your callbackUrl is signed with a secret unique to your account. Only Safefy and you know it: a callback with a valid signature came from Safefy and was not changed on the way.
Change on 2026-09-29: the legacy signature (X-Safefy-Signature) used the payment or payout ID as the key, and the payer knows that ID. It stops being sent on 2026-10-29. Until then both headers are sent. Switch to validating X-Safefy-Signature-V2 before that date.

Where to get the secret

  1. In the Safefy dashboard, open Webhooks.
  2. In the Payment and payout callback signature box, click Show secret (“Mostrar segredo”).
  3. Store the value (it starts with whsec_) on your server, for example in an environment variable. Never put it in a browser or mobile app.
The secret belongs to the organization and covers all of its charges and payouts. If it leaks, use Rotate secret (“Trocar segredo”): the old one stops working immediately and the next callbacks already use the new one.

How to validate

The X-Safefy-Signature-V2 header looks like:
  1. Read the raw request body, exactly as received (before parsing JSON).
  2. Split t (timestamp) and v1 (signature) from the header.
  3. Build the string "{t}.{body}": the timestamp, a dot and the raw body.
  4. Compute HMAC-SHA256 of that string with your secret, as lowercase hex.
  5. Compare it with v1 using a constant-time comparison.
  6. Reject the callback if the signature does not match or if t is more than 5 minutes away from your clock. This blocks replays of old callbacks.
  7. Only then process the event.
Even with a valid signature, before releasing a high-value order you can confirm the status through the API (Get transaction). If validation fails, do not release the order: query the API.

Legacy signature (until 2026-10-29)

During the transition, X-Safefy-Signature is still sent as sha256={hex(HMAC-SHA256(key, body))}, where the key is the paymentId (payment.* events) or the payoutId (cashout.* events). Do not use it in new integrations. From 2026-10-29 only X-Safefy-Signature-V2 is sent.

Retries

If your endpoint does not return 2xx, Safefy retries:
  1. Attempt 1 (immediate)
  2. Attempt 2 after ~2 seconds
  3. Attempt 3 after ~4 seconds
Recommendation: acknowledge quickly (200 OK) and process asynchronously.

Idempotency

Because retries can happen, your webhook processing must be idempotent.
  • Recommended key: id (delivery id) or data.id + type
  • Ignore already-processed events

Quick example


Payment status flow

Understand the transaction lifecycle and when each webhook is fired:

Best practices

Respond quickly

Return 200 OK immediately and process the webhook asynchronously.

Be idempotent

Use the webhook id to avoid processing the same event twice.

Validate the signature

Verify X-Safefy-Signature-V2 and reject callbacks older than 5 minutes before trusting the payload.

Use HTTPS

Configure your callbackUrl with HTTPS in production.