> ## Documentation Index
> Fetch the complete documentation index at: https://docs.palpluss.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Webhook signing

> Check that a callback really came from PalPluss. Add your domain in the console, get a signing secret, verify three headers.

# Webhook signing

Anyone who knows your callback URL can send it a fake "payment succeeded" message. Signing lets your server reject those.

Add the domain your callback URLs are on in the console, and PalPluss signs every callback it sends to that domain. Signatures use the [Standard Webhooks](https://www.standardwebhooks.com) format, the same scheme used by Svix and Resend.

> [!NOTE]
>
> Signing changes nothing else. The body, `callbackUrl` and retries work exactly as before. Callbacks to URLs on domains you haven't added are still sent, unsigned.

## How to apply it

**1. Add your domain in the console**

Open **Webhooks → Add domain** and enter the host of your callback URL. Copy the `whsec_…` secret.

**2. Store the secret on your server**

Put it in an environment variable, for example `PALPLUSS_WEBHOOK_SECRET`. Never put it in code or a browser app.

**3. Keep your requests as they are**

Nothing changes in how you call PalPluss. Keep sending the same `callbackUrl`. When it's on your domain, the callback is signed.

**4. Verify every callback**

Check the three `webhook-*` headers against the raw body with the code below. Reject the callback with `400` if the check fails.

**5. Test, then enforce**

Use **Send test webhook**, log failed checks for a while, then start rejecting them.

**Which callbacks are signed:** every callback PalPluss sends to a URL on your domain, for STK Push (including payments made through [payment links](https://docs.palpluss.com/api-reference/payment-links/create.md)), B2C payouts and wallet top-ups, with live and test keys.

## 1. Add your domain

In the [console](https://console.palpluss.com), open **Webhooks → Add domain** and enter the host of your callback URL:

| You enter | Signs callbacks to |
| - | - |
| `api.yourshop.co.ke` | `https://api.yourshop.co.ke/…` only |
| `*.yourshop.co.ke` | Any subdomain, such as `pay.yourshop.co.ke` (not `yourshop.co.ke` itself) |

You can paste a full URL; only its host is kept. IP addresses and `localhost` can't be added.

You can sign up to **10 domains**. To add another once you reach the limit, remove one you no longer use. A `*.` entry covers all of a domain's subdomains and counts as one.

You get a **signing secret** that starts with `whsec_`. Store it on your server, for example as `PALPLUSS_WEBHOOK_SECRET`. You can show it again in the console at any time.

Signing covers callbacks from every API key on your account, in live and test mode.

## 2. What a signed callback looks like

Three headers are added:

| Header | Value |
| - | - |
| `webhook-id` | A message ID such as `msg_3f9a…`. It stays the same on every retry of the same callback, so you can use it to ignore duplicates. |
| `webhook-timestamp` | When this attempt was sent, in Unix seconds |
| `webhook-signature` | `v1,<signature>`. After you rotate the secret it holds two signatures, separated by a space. |

The signature is a base64 HMAC-SHA256 of `{webhook-id}.{webhook-timestamp}.{raw body}`. The key is the base64-decoded part of your secret after `whsec_`.

## 3. Verify it

Verify against the **raw request body**, exactly as received. Parsing the JSON and re-serialising it can change the bytes and break the signature.

```javascript Node.js theme={null}
import crypto from "node:crypto";

export function verifyPalplussWebhook(rawBody, headers, secret) {
  const id = headers["webhook-id"];
  const timestamp = headers["webhook-timestamp"];
  const signatures = headers["webhook-signature"];
  if (!id || !timestamp || !signatures) return false;

  // Reject old or future-dated messages (5 minutes).
  if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return false;

  const key = Buffer.from(secret.replace(/^whsec_/, ""), "base64");
  const expected = crypto
    .createHmac("sha256", key)
    .update(`${id}.${timestamp}.${rawBody}`)
    .digest("base64");

  return signatures.split(" ").some((part) => {
    const [version, signature] = part.split(",");
    return (
      version === "v1" &&
      signature?.length === expected.length &&
      crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected))
    );
  });
}
```

```php PHP theme={null}
<?php
function verify_palpluss_webhook(string $rawBody, array $headers, string $secret): bool {
    $id = $headers['webhook-id'] ?? null;
    $timestamp = $headers['webhook-timestamp'] ?? null;
    $signatures = $headers['webhook-signature'] ?? null;
    if (!$id || !$timestamp || !$signatures) return false;
    if (abs(time() - (int) $timestamp) > 300) return false;

    $key = base64_decode(preg_replace('/^whsec_/', '', $secret));
    $expected = base64_encode(hash_hmac('sha256', "$id.$timestamp.$rawBody", $key, true));

    foreach (explode(' ', $signatures) as $part) {
        [$version, $signature] = array_pad(explode(',', $part, 2), 2, '');
        if ($version === 'v1' && hash_equals($expected, $signature)) return true;
    }
    return false;
}
```

```python Python theme={null}
import base64, hashlib, hmac, time

def verify_palpluss_webhook(raw_body: bytes, headers: dict, secret: str) -> bool:
    msg_id = headers.get("webhook-id")
    timestamp = headers.get("webhook-timestamp")
    signatures = headers.get("webhook-signature")
    if not (msg_id and timestamp and signatures):
        return False
    if abs(time.time() - int(timestamp)) > 300:
        return False

    key = base64.b64decode(secret.removeprefix("whsec_"))
    signed = f"{msg_id}.{timestamp}.".encode() + raw_body
    expected = base64.b64encode(hmac.new(key, signed, hashlib.sha256).digest()).decode()

    for part in signatures.split(" "):
        version, _, signature = part.partition(",")
        if version == "v1" and hmac.compare_digest(expected, signature):
            return True
    return False
```

### Express: keep the raw body

```javascript theme={null}
import express from "express";

app.post("/webhooks/palpluss", express.raw({ type: "application/json" }), async (req, res) => {
  const rawBody = req.body.toString("utf8");
  if (!verifyPalplussWebhook(rawBody, req.headers, process.env.PALPLUSS_WEBHOOK_SECRET)) {
    return res.sendStatus(400);
  }
  res.sendStatus(200);

  const { event_type, transaction } = JSON.parse(rawBody);
  // …fulfil the order, keyed on transaction.id (see Webhooks)
});
```

In Laravel, read the raw body with `$request->getContent()`. In Django, use `request.body`.

> [!TIP]
>
> Signature libraries for the Standard Webhooks format work too, because the scheme is the same. The code above has no dependencies.

## 4. Send a test webhook

Under **Webhooks**, choose **Send test webhook** on a domain and enter an `https` URL on it. PalPluss sends a signed `webhook.test` event:

```json theme={null}
{
  "event": "webhook.test",
  "event_type": "webhook.test",
  "message": "This is a test webhook from PalPluss. If your signature check passes, you are ready.",
  "domain": "api.yourshop.co.ke",
  "sent_at": "2026-11-16T09:00:00.000Z"
}
```

The console shows the status code your server returned. Return a 2xx when the signature checks out and 400 when it doesn't. Test webhooks are only sent to public `https` addresses.

## Rotate the secret

If the secret leaks, choose **Rotate secret**. A new secret is created straight away. For the next **24 hours**, callbacks carry signatures from both the new and the old secret, so you can update your server without missing any. After that, only the new secret is used.

## Turning signing on safely

1. Add the domain and deploy your verification code, but only **log** failures at first.
2. Watch a few real callbacks pass.
3. Then reject unsigned or invalid callbacks with `400`.

If you remove a domain, callbacks to it are sent unsigned again. A server that requires signatures will then reject them.

## Still do this

A valid signature proves the callback came from PalPluss. Keep the other good habits from [Webhooks](https://docs.palpluss.com/guides/webhooks.md): use `transaction.id` (or `webhook-id`) to ignore duplicates, respond with 2xx quickly, and re-fetch `GET /transactions/{id}` before fulfilling high-value orders.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.