← Developer Guides

Webhooks#

Webhooks let you receive real-time HTTP notifications when events happen in your account — like a successful purchase or a failed transaction.

How Webhooks Work#

  1. You register a webhook URL in the Merchant Portal → Settings → Webhooks tab
  2. When an event occurs, we send a POST request to your URL with the event data
  3. Your server processes the event and returns a 200 status code
  4. If delivery fails, we retry up to 4 more times with exponential backoff: 30s, 2min, 10min, 1hr

Each endpoint retries independently, so a single failing URL never causes a duplicate delivery to your other endpoints.

Setting Up#

  1. Go to Merchant Portal → Settings → Webhooks
  2. Click Add webhook
  3. Enter your endpoint URL. Use HTTPS: plain http:// URLs are accepted (handy for a local tunnel while developing), but the payload and its signature then travel unencrypted
  4. Choose the environment: Live endpoints receive live purchases only, Test endpoints receive purchases made with your sk_test_ key only
  5. Select the events you want to receive
  6. Click Create — the signing secret, beginning whsec_, is shown

The signing secret is shown once, when the endpoint is created. Store it then. If you lose it, Rotate secret on the endpoint issues a new one — the previous secret stops verifying immediately. Managing endpoints is done in the portal, signed in; your API key cannot create, rotate or replay webhooks.

There is no account-wide webhook secret. Each endpoint has its own signing secret, and only that value verifies deliveries from that endpoint.

Webhook Payload#

Every webhook delivery includes these headers:

HeaderDescription
X-Webhook-SignatureHMAC-SHA256 signature of the raw body, keyed with your signing_secret
X-Event-IdUnique delivery ID — use this to deduplicate
X-Event-TimeUnix timestamp of the event
Content-Typeapplication/json

Example Payload#

Every delivery has the same envelope: id (the event id, also sent as X-Event-Id), time (Unix seconds, also sent as X-Event-Time), event, and data. For a purchase event, data.purchase is the purchase exactly as GET /api/v1/purchases/{id} returns it:

JSON
{
  "id": "01kw46b8t1z6n0q3x2v9c4m7ra",
  "time": 1751270405,
  "event": "purchase.success",
  "data": {
    "purchase": {
      "id": "01kw463z1czwnst3yknbkzczn2",
      "reference": "01kw463z1czwnst3yknbkzczn2",
      "status": "success",
      "feature": "airtime",
      "amount": 50000,
      "amount_paid": 50000,
      "fee": 0,
      "currency_code": "NGN",
      "provider_reference": "DIST2349054079391",
      "failure_reason": null,
      "is_test": false,
      "platform_meta": {
        "phone_number": "+2348012345678",
        "network": "mtn"
      },
      "created_at": 1751270400,
      "updated_at": 1751270403
    }
  }
}
FieldDescription
idEvent id. A retry or a replay of the same delivery keeps it — deduplicate on it
timeUnix timestamp (seconds) when the event was raised
eventOne of the event types below
data.purchase.statusAlways matches the event: success for purchase.success, and so on
data.purchase.failure_reasonA customer-safe reason on purchase.failed; null on every other event
data.purchase.provider_dataOnly on purchase.success for a product that vends a code (a WAEC PIN, an electricity token); absent otherwise
data.purchase.is_testtrue for a purchase made with your test key — delivered to your Test endpoints only

Amounts are in the smallest currency unit, beside their currency_code.

Verifying Signatures#

Always verify webhook signatures to ensure the request came from us. Compute the HMAC-SHA256 of the raw request body using your webhook secret:

JavaScript
const crypto = require("crypto");

function verifyWebhook(payload, signature, secret) {
  const expected = crypto
    .createHmac("sha256", secret)
    .update(payload)
    .digest("hex");
  return crypto.timingSafeEqual(
    Buffer.from(signature),
    Buffer.from(expected)
  );
}

// In your webhook handler:
app.post("/webhooks", (req, res) => {
  const signature = req.headers["x-webhook-signature"];
  const isValid = verifyWebhook(req.rawBody, signature, WEBHOOK_SECRET);

  if (!isValid) {
    return res.status(401).json({ error: "Invalid signature" });
  }

  const { id, event, data } = req.body;
  // Deduplicate on `id`, then act on data.purchase...

  res.status(200).json({ received: true });
});
Python
import hmac
import hashlib

def verify_webhook(payload: bytes, signature: str, secret: str) -> bool:
    expected = hmac.new(
        secret.encode(),
        payload,
        hashlib.sha256,
    ).hexdigest()
    return hmac.compare_digest(signature, expected)
PHP
function verifyWebhook(string $payload, string $signature, string $secret): bool
{
    $expected = hash_hmac('sha256', $payload, $secret);
    return hash_equals($expected, $signature);
}

// In your controller:
$payload = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_WEBHOOK_SIGNATURE'];

if (!verifyWebhook($payload, $signature, $webhookSecret)) {
    http_response_code(401);
    exit;
}

$event = json_decode($payload, true);
// Process the event...

Event Types#

These are the events the platform emits. Subscribing to anything not on this list is rejected at write time, so a typo fails immediately instead of silently never firing.

EventDescription
purchase.pendingA purchase was created and the buyer debited, not yet sent to the provider
purchase.processingThe outcome is not yet final: the provider accepted the request, or the purchase is held for manual review
purchase.successThe purchase was fulfilled
purchase.failedThe purchase failed and the buyer was refunded

webhook.test is also delivered, but only on demand from the Test button — you do not subscribe to it.

The event name is purchase. followed by the purchase status, and the body's status always matches the event name. One exception: a purchase held for manual review (review on GET /purchases) is announced as purchase.processing; there is no purchase.review event. Its purchase.success or purchase.failed follows when it is settled. Only success and failed are final, so order events by name, not by updated_at.

Retry Policy#

If your endpoint doesn't respond with a 2xx status code, we retry:

AttemptDelay
1st retry30 seconds
2nd retry2 minutes
3rd retry10 minutes
4th retry1 hour

After 5 total attempts the delivery is marked failed. Retries are per endpoint: a URL that is down does not cause repeat deliveries to your other endpoints.

A purchase.processing delivery not yet sent when its purchase ends (a first attempt, a retry or a replay) is dropped rather than sent late: the purchase.success or purchase.failed event carries the outcome. One already queued is listed in the deliveries with status superseded.

Deliveries on an endpoint in Settings → Webhooks lists past attempts, with the response code and the attempt count for each, and re-sends a failed one.

Best Practices#

  1. Respond quickly — return 200 immediately, process asynchronously
  2. Handle duplicates — use the X-Event-Id to deduplicate
  3. Verify signatures — always validate before processing
  4. Use HTTPS — http:// URLs are accepted, but only HTTPS keeps the payload and its signature private in transit
  5. Log everything — keep records for debugging