Chapa
Webhooks

Webhook Overview

Authenticate webhook deliveries and route payment, payout, and refund events.

Chapa sends webhook notifications when payments, payouts, and refunds change state. Use the resource pages for event names, payload fields, and examples:

  • Payment Webhooks: successful, failed, cancelled, incomplete, authentication-required, and blocked payments.
  • Payout Webhooks: payout completion, failures, reversals, blocks, and authorization events.
  • Refund Webhooks: partial and full refunds.

This page covers the shared signature verification and delivery-handling rules. Read these before processing any event.

Payload structure

Webhook fields are at the top level of the JSON body. Route events using webhook_type, then check event and status using their documented lowercase values.

FieldTypeMeaning
webhook_typestringResource category: payment, payout, or refund
eventstringEvent name, such as payment.success or payout.failed
statusstringResource state, such as success, failed, or partially_refunded
modestringlive or test, when included
currencystringCurrency code, such as ETB
amountstringAmount in cents
merchant_referencestringMerchant-generated reference
chapa_referencestringChapa-generated reference
created_at, updated_atstringISO8601 timestamps
metaobjectMerchant-defined metadata

Fields vary by resource and event. See the resource pages for complete examples.

Webhook payloads and verification responses have different shapes. A payment webhook uses webhook_type: "payment", event: "payment.success", and top-level status: "success". The payment verification API uses data.status: "SUCCESS". Do not apply the API response check directly to a webhook body.

Verify Webhook Origin

For v2 payment, payout, and refund webhooks that use Signature authentication, Chapa sends the signature in the x-chapa-signature header. Set and keep the corresponding webhook secret private when configuring the webhook.

The header is a lowercase hexadecimal HMAC-SHA256 digest calculated as:

HMAC_SHA256(key = webhook_secret, message = raw HTTP request body)

The signature covers the exact JSON bytes sent in the request body. Verify it before parsing or reserializing the payload, because JSON.stringify(req.body) can produce a different byte sequence. Use a constant-time comparison.

import crypto from "node:crypto";
import express from "express";

const app = express();

function isValidChapaWebhook(rawBody, receivedSignature) {
  const secret = process.env.CHAPA_WEBHOOK_SECRET;

  const expectedSignature = crypto
    .createHmac("sha256", secret)
    .update(rawBody)
    .digest("hex");

  return (
    typeof receivedSignature === "string" &&
    /^[a-f0-9]{64}$/i.test(receivedSignature) &&
    crypto.timingSafeEqual(
      Buffer.from(receivedSignature, "hex"),
      Buffer.from(expectedSignature, "hex")
    )
  );
}

app.post("/webhooks/chapa", express.raw({ type: "application/json" }), (req, res) => {
  if (!isValidChapaWebhook(req.body, req.get("x-chapa-signature"))) {
    return res.sendStatus(401);
  }

  const event = JSON.parse(req.body.toString("utf8"));
  // Process event idempotently.
  return res.sendStatus(200);
});
<?php

$secret = getenv('CHAPA_WEBHOOK_SECRET');
$rawBody = file_get_contents('php://input');
$receivedSignature = $_SERVER['HTTP_X_CHAPA_SIGNATURE'] ?? '';
$expectedSignature = hash_hmac('sha256', $rawBody, $secret);

if (!hash_equals($expectedSignature, $receivedSignature)) {
    http_response_code(401);
    exit;
}

$event = json_decode($rawBody, true, flags: JSON_THROW_ON_ERROR);
// Process $event idempotently.
http_response_code(200);
import hashlib
import hmac
import os

from flask import Flask, abort, request

app = Flask(__name__)


@app.post("/webhooks/chapa")
def chapa_webhook():
    secret = os.environ["CHAPA_WEBHOOK_SECRET"].encode()
    raw_body = request.get_data(cache=True)
    received_signature = request.headers.get("X-Chapa-Signature", "")
    expected_signature = hmac.new(secret, raw_body, hashlib.sha256).hexdigest()

    if not hmac.compare_digest(expected_signature, received_signature):
        abort(401)

    event = request.get_json()
    # Process event idempotently.
    return "", 200
package main

import (
    "crypto/hmac"
    "crypto/sha256"
    "encoding/hex"
    "io"
    "net/http"
    "os"
)

func chapaWebhook(w http.ResponseWriter, r *http.Request) {
    rawBody, err := io.ReadAll(r.Body)
    if err != nil {
        http.Error(w, "invalid request body", http.StatusBadRequest)
        return
    }

    mac := hmac.New(sha256.New, []byte(os.Getenv("CHAPA_WEBHOOK_SECRET")))
    mac.Write(rawBody)
    expectedSignature := mac.Sum(nil)
    receivedSignature, err := hex.DecodeString(r.Header.Get("X-Chapa-Signature"))

    if err != nil || !hmac.Equal(expectedSignature, receivedSignature) {
        http.Error(w, "invalid signature", http.StatusUnauthorized)
        return
    }

    // Decode rawBody and process the event idempotently.
    w.WriteHeader(http.StatusOK)
}

Do not reconstruct the JSON body before verification or compare the signature with normal string equality. Use the unmodified raw request body, a constant-time comparison, and reject requests with a missing or invalid signature.

Process deliveries safely

Authenticate before processing

Verify the signature before using any event fields. For payloads that include mode, confirm it matches the environment you are processing. Match the references, amount, and currency to the corresponding resource in your system.

Handle duplicate deliveries

Chapa may deliver the same event more than once. Store a hash of the authenticated raw request body, scoped to the webhook configuration and environment, to recognize identical deliveries. Do not use only the event name and payment reference: multiple partial refunds can share those fields.

Delivery deduplication does not replace business-level idempotency. Use a unique payment or order record to prevent repeated fulfillment, and track each refund by its refund reference from refund creation. If a notification does not identify an individual refund, reconcile your stored refund references through Verify Refund rather than creating another refund record from each delivery. Record processing and apply local state changes atomically.

Acknowledge an already processed event with 200 OK.

Acknowledge durable receipt

Return 200 OK after you have durably recorded the event or successfully processed it. Queue heavier work when possible. Chapa may retry a delivery after a non-200 response or timeout, so processing must be safe to repeat.

Handle ordering

Events can arrive out of order. Use updated_at and resource-specific state-transition rules to avoid overwriting a newer state with an older event. Reconcile unexpected states using the verification endpoint for the relevant resource.

Verify before fulfillment

Use payment events to trigger server-side payment verification. Before fulfillment, check the verification response's data.status === "SUCCESS", amount, currency, and merchant reference against the expected order. Keep fulfillment idempotent.

For payouts and refunds, consult their verification endpoints when reconciling the final state. A successful creation response does not establish that an asynchronous operation is complete.

Event references

On this page