Webhooks
Inshuwa sends webhook notifications to your server when payment and policy events occur.
Overview
Webhooks allow you to receive real-time updates instead of polling the API. When an event occurs (such as a successful payment), Inshuwa sends an HTTP POST request to your configured webhook URL.
Setup
Configure your webhook URL in the Inshuwa dashboard under Settings > Webhooks.
Your webhook endpoint must:
- Accept
POSTrequests - Return a
200 OKstatus code - Be publicly accessible over HTTPS
Payment Webhook
Inshuwa sends a payment notification to your webhook URL when a policy payment is processed.
Example payload:
{
"policyId": "pol_abc123",
"paymentReference": "PAY-20240101-001",
"partnerReference": "your-unique-reference-123",
"status": "Success",
"amount": 1500.00,
"currency": "ZMW",
"policyNumber": "MOT-2024-00001",
"policyStatus": "Active",
"paidAt": "2024-01-01T10:30:00Z"
}Webhook Fields
| Field | Type | Description |
|---|---|---|
policyId | string | Inshuwa internal policy ID |
paymentReference | string | Inshuwa payment reference |
partnerReference | string | Your reference from the payment request |
status | string | Payment status: Success, Failed, Pending |
amount | number | Amount paid |
currency | string | Currency code (e.g., ZMW) |
policyNumber | string | Human-readable policy number |
policyStatus | string | Current policy status after payment |
paidAt | string | ISO 8601 timestamp of payment |
Checking What Was Delivered
Every delivery attempt against a transaction is logged. When a webhook did not arrive, read the log before assuming it was never sent — it records the attempts, the status we got back, and the retries.
Set it once and every Try it out below is authenticated. It stays in this browser's local storage and is never sent anywhere but the API.
/payments/transactions/{reference}/callbacksPlayground
Authorization
Variables
Cancellation Webhooks
When you cancel a policy, or the insurer cancels one whose premium you collected, Inshuwa can tell you when it is decided instead of you polling for it. Cancellation events go to their own URL, separate from the payment webhook, so a payment handler never receives one.
Inshuwa sets your cancellation webhook URL; ask your account manager. It must be HTTPS. Without one, poll the cancellation's status instead.
Example payload:
{
"event": "cancellation.ready_for_disbursement",
"cancellation": {
"reference": "LP-CXL-0001",
"policyId": "Qa7Wd2k",
"policyNumber": "MP-000123",
"status": "ReadyForDisbursement",
"refundAmount": 200.00,
"fundedAmount": 180.00,
"partnerShare": 20.00,
"currency": "ZMW",
"reason": "Customer sold the vehicle",
"initiatedBy": "Partner"
}
}| Event | When | What you do |
|---|---|---|
cancellation.ready_for_disbursement | The policy is cancelled and Inshuwa's part of the refund is in the insurer's cancellation wallet. | Pay the customer refundAmount. |
cancellation.rejected | The insurer or Inshuwa declined the cancellation. The policy stays on cover. | Tell the customer; nothing is refunded. |
cancellation carries the same fields as the cancellation status, with the final amounts. Match it to your request by reference. An event with initiatedBy: "Insurer" is for a cancellation the insurer started, with Inshuwa's reference: match it by policyId and pay the customer the same way.
A failed delivery is retried three times, after 30 seconds, 2 minutes and 5 minutes. If none succeed, the cancellation's status still tells you where it stands.
Verifying Webhooks
Inshuwa signs every webhook, payment and cancellation alike, so you can check that it came from Inshuwa and hasn't been replayed. Ask your Inshuwa account manager for your webhook secret. It starts with whsec_ and is shown only once, so store it like a password. Until a secret is issued for you, webhooks arrive unsigned.
Each signed request carries this header:
X-Inshuwa-Signature: t=1700000000,v1=38877139021993b830af32feea6e18a8da83eb2f6e49ee50bd9e4cf4ca4d3789tis when Inshuwa sent the request, in Unix seconds.v1is the hex HMAC-SHA256 of{t}.{raw body}, keyed with the UTF-8 bytes of your secret.
To verify a request:
- Read the raw request body before any JSON parsing. Re-serialized JSON won't match.
- Split the header on
,and=to gettandv1. - Compute HMAC-SHA256 over
t, a., and the raw body, using your secret. - Compare your result with
v1in constant time. Reject the request if they differ. - Reject the request if
tis more than 5 minutes from your clock.
Each retry is signed afresh, with a new t.
You can test your code with this example: the secret whsec_test, the body {"a":1} and t=1700000000 give the v1 shown above.
If your secret leaks, ask for a new one. The new secret replaces the old one immediately, so deploy it straight away.
Whether or not you verify signatures, base what you do on the cancellation status or the policy itself rather than the webhook alone, for example before you pay a customer.
Example Handler (Node.js)
const crypto = require('crypto');
const express = require('express');
const SECRET = process.env.INSHUWA_WEBHOOK_SECRET; // whsec_...
function verify(req) {
const header = req.get('X-Inshuwa-Signature') || '';
const parts = Object.fromEntries(header.split(',').map(p => p.split('=')));
const t = Number(parts.t);
if (!t || !parts.v1 || Math.abs(Date.now() / 1000 - t) > 300) return false;
const expected = crypto.createHmac('sha256', SECRET)
.update(`${parts.t}.${req.body.toString('utf8')}`)
.digest('hex');
return parts.v1.length === expected.length &&
crypto.timingSafeEqual(Buffer.from(parts.v1), Buffer.from(expected));
}
// express.raw keeps the exact bytes that were signed
app.post('/webhooks/inshuwa/payment', express.raw({ type: 'application/json' }), (req, res) => {
if (!verify(req)) return res.status(401).send('Bad signature');
const { policyId, status, amount } = JSON.parse(req.body);
if (status === 'Success') {
// Update your database, send confirmation email, etc.
console.log(`Policy ${policyId} paid. Amount: ${amount}`);
}
// Always respond with 200
res.status(200).send('OK');
});Retry Policy
If your webhook endpoint is unavailable or returns a non-2xx status, Inshuwa will retry the delivery with exponential backoff. Ensure your endpoint is idempotent — the same webhook may be delivered more than once.
