---
agentTools:
  projectIndex: https://swahilies.readme.io/llms.txt
---

# Webhooks

Webhooks are an important part of your payment integration. They allow Swahilies Pay notify you about events that happen on your account, such as a successful payment or a failed transaction.

A webhook URL is an endpoint on your server where you can receive notifications about such events. When an event occurs, we'll make a POST request to that endpoint, with a JSON body containing the details about the event.

## The response body on the callback contains the following.

[block:parameters]
{
  "data": {
    "h-0": "Code",
    "h-1": "200 for success and 300 for error",
    "0-0": "order_id",
    "0-1": "your order_id submitted when initiating check out process",
    "1-0": "reference_id",
    "1-1": "the reference of the transaction to swahilies",
    "2-0": "amount",
    "2-1": "the order amount"
  },
  "cols": 2,
  "rows": 3
}
[/block]

\##Sample of response body

[block:code]
{
  "codes": [
    {
      "code": " {\n     \"code\":200,\n     \"transaction_details\":\n     {\n       \"order_id\":order.client_order_id,\n       \"reference_id\":order.order_id,\n    }\n}",
      "language": "python"
    }
  ]
}
[/block]

## Verifying webhook

For security purpose is very important user verify the webhook callback

The header of the response :

[block:parameters]
{
  "data": {
    "h-0": "header-key",
    "h-1": "value",
    "0-0": "Digest",
    "0-1": "the signed based64 encoded hmac signature using the api_secret"
  },
  "cols": 2,
  "rows": 1
}
[/block]

The signed signature consist of the combination of the timestamp, server IPand the api\_key

This will be enable user to verify the request , after decrypting compare the timestamp, the server IP address and the api\_key

[block:html]
{
  "html": "<div class=\"nuxt-content\" style=\"margin-bottom: 50px; margin-top: 50px;\">\n\n  <h6>Example</h6>\n\n  <ol>\n\n    <li>Get the timestamp from the main response object.</li>\n\n    <li>Fetch the IP the callback is coming from</li>\n\n    <li>Together with your api key combine to make a string of key = value, as below</li>\n\n    <li>Then using your secret key sign the the created string using hmac256.</li>\n\n    <li>Encode the signature with base64 and compare it to the Digest coming in the request heade</li>\n\n  </ol>\n\n</div>\n\n<style>\n\n  .nuxt-content li {\n\n    position: relative;\n\n    counter-increment: item 1;\n\n    padding-left: 24px;\n\n    margin-bottom: 10px;\n\n}\n\n  ol, ul {\n\n    list-style: none;\n\n}\n\n.nuxt-content li:before {\n\n    content: counter(item);\n\n    width: 14px;\n\n    height: 14px;\n\n    border-radius: 50%;\n\n    border: 1px solid rgba(114,143,158,.08);\n\n    display: flex;\n    justify-content: center;\n\n    align-items: center;\n\n    font-size: 11px;\n\n    line-height: 11px;\n\n    font-weight: 500;\n\n    color: #333;\n\n    background: #bdbdbd;\n\n    position: absolute;\n\n    top: 5px;\n\n    left: 0;\n\n}\n\n</style>"
}
[/block]

[block:code]
{
  "codes": [
    {
      "code": "fordigest = {\n    \"timestamp\": current_date,\n    \"server_ip\": \"oo.00.00.189\",\n    \"api_key\": \"your_api_key\"\n}\ntoDigest = \"\"\n    for key in fordigest.keys():\n        toDigest += \"&\" + key + \"=\" + array[key]\n    # return toDigest\n base64.b64encode(\n        hmac.digest(api_secret.encode(), toDigest.encode(), 'sha256')).decode()",
      "language": "python"
    }
  ]
}
[/block]