In this guide
This page covers when to use a webhook, how to turn webhooks on, how to verify the signature, and what happens if delivery times out.
What a webhook is
Flutterwave sends a webhook when something happens on your account, such as a successful payment or a failed transaction. Verify the request before you update an order or mark a payout as complete. That keeps your application from acting on a request that did not come from Flutterwave.
A webhook URL is an endpoint on your server where these notifications are sent. When an event occurs, Flutterwave sends a POST request to that endpoint. The request contains a JSON body with details about the event, including the event type and associated data.
Flutterwave's IP Addresses are Dynamic and May Change Over Time.
To ensure seamless webhook integration, we recommend avoiding strict IP whitelisting. Instead, consider implementing signature verification for security.
When to Use Webhooks
Webhooks are supported for all kinds of payment methods, but they're especially useful for methods and events that happen outside your application's control, such as:
- Getting paid via mobile money or USSD
- A customer is being charged for their subscription (recurring payments).
- A pending payment transitioning to successful.
These are all asynchronous actions, as your application does not control them, so you won't know when they are completed unless we notify you or you check later.
Setting up a webhook allows us to notify you when these payments are completed. Within your webhook endpoint, you can then:
Update a customer's membership records in your database when a subscription payment succeeds.
Email a customer when a subscription payment fails.
Update your order records when the status of a pending payment is updated to successful.
Enabling Webhooks
Here is how to set up a webhook on your Flutterwave account:
- Log in to your dashboard and click on Settings.
- Navigate to Webhooks to add your webhook URL.
- Check all the boxes and save your Settings.

Tip
When testing, you can get an instant webhook URL by visiting webhook.site. This will allow you to inspect the received payload without having to write any code or set up a server.
Structure of a Webhook Payload
All webhook payloads (except virtual card debit) follow the same basic structure:
- An event field describing the type of event.
- A data object. The content of this object will vary depending on the event, but typically, it will contain details of the event, including:
- an id containing the ID of the transaction.
- a status describing the status of the transaction.
- payment or customer details, if applicable.
Here are some sample webhook payloads for transfers and payments:
Successful Payment
Javascript
{
"event": "charge.completed",
"data": {
"id": 285959875,
"tx_ref": "Links-616626414629",
"flw_ref": "PeterEkene/FLW270177170",
"device_fingerprint": "a42937f4a73ce8bb8b8df14e63a2df31",
"amount": 100,
"currency": "NGN",
"charged_amount": 100,
"app_fee": 1.4,
"merchant_fee": 0,
"processor_response": "Approved by Financial Institution",
"auth_model": "PIN",
"ip": "197.210.64.96",
"narration": "CARD Transaction ",
"status": "successful",
"payment_type": "card",
"created_at": "2020-07-06T19:17:04.000Z",
"account_id": 17321,
"customer": {
"id": 215604089,
"name": "Yemi Desola",
"phone_number": null,
"email": "[email protected]",
"created_at": "2020-07-06T19:17:04.000Z"
},
"card": {
"first_6digits": "123456",
"last_4digits": "7889",
"issuer": "VERVE FIRST CITY MONUMENT BANK PLC",
"country": "NG",
"type": "VERVE",
"expiry": "02/23"
}
}
}
Implementing a Webhook
Creating a webhook endpoint on your server is the same as writing any other API endpoint, but there are a few important details to note:
Verifying Webhook Signatures
When enabling webhooks, you have the option to set a secret hash. Since webhook endpoints are publicly accessible, the secret hash allows you to verify that incoming requests are from Flutterwave. You can specify any value as your secret hash, but we recommend something random. You should also store it as an environment variable on your server.
If you specify a secret hash, we'll include it in our request to your webhook endpoint, in a header called verif-hash. In the webhook endpoint, check if the verif-hash header is present and that it matches the secret hash you set. If the header is missing, or the value doesn't match, you can discard the request, as it isn't from Flutterwave.
Responding to Webhook Requests
To acknowledge receipt of a webhook, your endpoint must return a 200 HTTP status code. Any other response codes, including 3xx codes, will be treated as a failure. We don't care about the response body or headers.
Webhook Timeout
Webhook requests time out after 60 seconds. Your webhook endpoint must respond within this window. If it doesn't, the request will be marked as failed. If webhook retries are enabled, we’ll attempt to resend the request.
Handling Webhook Retries
Be sure to enable webhook retries on your dashboard. If we don't get a 200 status code (for example, if your server is unreachable), we'll retry the webhook call 3 times, with a 30-minute interval between each attempt.
Examples
Here are a few examples of implementing a webhook endpoint in some web frameworks:
Rails and Django
Web frameworks like Rails or Django check POST requests for CSRF tokens, a security measure against cross-site request forgery. Exclude webhook endpoints from CSRF protection.
Javascript
const crypto = require("crypto");
const express = require("express");
const app = express();
function safeEqual(a, b) {
if (typeof a !== "string" || typeof b !== "string") return false;
const bufA = Buffer.from(a);
const bufB = Buffer.from(b);
return bufA.length === bufB.length && crypto.timingSafeEqual(bufA, bufB);
}
app.post("/flw-webhook", express.json(), (req, res) => {
const secretHash = process.env.FLW_SECRET_HASH;
const signature = req.get("verif-hash");
if (!secretHash || !safeEqual(signature, secretHash)) {
// This request isn't from Flutterwave; discard
return res.status(401).end();
}
const payload = req.body;
// It's a good idea to log all received events.
console.log(payload);
// Acknowledge first, then process in the background
res.status(200).end();
jobQueue.add("flutterwave-event", payload);
});
Best Practices
Follow these best practices to ensure your webhook integration is secure and reliable:
1. Always Verify Critical Transaction Data
Before giving value to a customer based on a webhook notification, always re-query our API to verify the transaction details. This helps confirm that the data returned is consistent with what you’re expecting and has not been compromised.
For example, when you receive a successful payment notification, call the transaction verification endpoint to confirm that the status, amount, currency, and tx_ref match the expected value in your system before confirming the customer's order.
Javascript
const { data } = req.body;
const response = await flw.Transaction.verify({ id: String(data.id) });
const tx = response.data;
const order = await Order.findOne({ reference: tx.tx_ref });
if (
order &&
tx.status === "successful" &&
tx.currency === order.currency &&
Number(tx.amount) >= order.amount
) {
// Success! Confirm the customer's payment
} else {
// Inform the customer their payment was unsuccessful
}