Mantissa Hooksnode is a Mantissa product A Mantissa product mantissatech.xyz

Paystack callback URL vs webhook: which one should give value?

Author:
hooksnode
Published:
Updated:
  • paystack
  • webhooks

The customer paid, the browser never came back, and the order is still unpaid. The callback URL, the verify call, and the webhook are three different things. Only one of them should be the path that gives value.

The Paystack facts below come from the callback support article, Verify payments, and Webhooks, as published on 2026-11-19.

The three things and what each is for

Callback URL. This is the page the customer is redirected to after paying. Paystack's support article says not to use the callback as the only way of returning value, because the customer might not get redirected after a network error. Paystack's webhooks page says callbacks can also fail if the connection is weak or the device goes off.

Verify Transaction API. This is GET https://api.paystack.co/transaction/verify/:reference, called from your server with the secret key. It is how you ask Paystack what the transaction actually is.

Webhook. Paystack POSTs the event to your server when the state changes. Paystack recommends webhooks over callbacks or polling for giving value.

Recommended pattern

Paystack's own guidance is to use the webhook as the primary path, and verify as the fallback for reconciliation, debugging, and recovery.

Webhook. Verify the signature on the raw body. The check is in Verify Paystack webhook signatures (Paystack-Signature and x-paystack-signature). Store the event, answer 200, then call fulfil(reference) in a background job.

Callback page. Call verify so you can show the customer the right status. Do not fulfil here unless the same idempotent fulfil function guards it.

One fulfil function. Key it on the Paystack reference, with a unique constraint, and call it from both the webhook job and the callback. Paystack's tip: for digital value (airtime, wallet top-up), always check you have not already delivered value for that transaction. The same guard is in Why your payment webhook arrived twice.

Confirm the transaction from your server. The secret stays in PAYSTACK_SECRET_KEY:

curl "https://api.paystack.co/transaction/verify/T123456" \
  -H "Authorization: Bearer $PAYSTACK_SECRET_KEY"

Node.js (Express)

EXPECTED_AMOUNT is the subunit you charged (kobo for NGN). EXPECTED_CURRENCY is the currency you charged. fulfil inserts the reference and does the work only when that insert wins.

import express from "express";

const app = express();
const EXPECTED_AMOUNT = 500000;
const EXPECTED_CURRENCY = "NGN";

async function verifyTransaction(reference) {
  const response = await fetch(
    `https://api.paystack.co/transaction/verify/${encodeURIComponent(reference)}`,
    {
      headers: { Authorization: `Bearer ${process.env.PAYSTACK_SECRET_KEY}` }
    }
  );
  const body = await response.json();
  const data = body.data ?? {};
  const ok =
    body.status === true &&
    data.status === "success" &&
    data.amount === EXPECTED_AMOUNT &&
    data.currency === EXPECTED_CURRENCY;
  return { ok, data };
}

async function fulfil(db, reference, work) {
  return db.tx(async (t) => {
    const row = await t.oneOrNone(
      `INSERT INTO fulfilled_payments (reference) VALUES ($1)
       ON CONFLICT (reference) DO NOTHING
       RETURNING reference`,
      [reference]
    );
    if (!row) return false;
    await work(t);
    return true;
  });
}

async function onChargeSuccess(db, event) {
  const data = event.data ?? {};
  if (data.amount !== EXPECTED_AMOUNT || data.currency !== EXPECTED_CURRENCY) return;
  await fulfil(db, data.reference, (t) =>
    t.none(
      `INSERT INTO ledger_entries (reference, amount, currency)
       VALUES ($1, $2, $3)`,
      [data.reference, data.amount, data.currency]
    )
  );
}

app.get("/paystack/callback", async (req, res) => {
  const reference = String(req.query.reference || "");
  const verified = await verifyTransaction(reference);
  if (verified.ok) {
    await fulfil(req.app.get("db"), reference, (t) =>
      t.none(
        `INSERT INTO ledger_entries (reference, amount, currency)
         VALUES ($1, $2, $3)`,
        [reference, verified.data.amount, verified.data.currency]
      )
    );
  }
  res.status(200).send(verified.ok ? "Payment confirmed" : "Payment not confirmed");
});

app.post("/webhooks/paystack", express.raw({ type: "application/json" }), (req, res) => {
  // Verify the signature on the raw body and store the event before answering.
  // fulfil runs after the 200, in the background.
  const event = JSON.parse(req.body.toString("utf8"));
  res.sendStatus(200);
  if (event.event === "charge.success") {
    onChargeSuccess(req.app.get("db"), event);
  }
});

PHP

Same two paths. fulfil is the only function that writes the ledger row. getenv("PAYSTACK_SECRET_KEY") is the only place the secret is read.

<?php
function paystack_secret() {
    $secret = getenv("PAYSTACK_SECRET_KEY");
    if ($secret === false || $secret === "") {
        throw new RuntimeException("PAYSTACK_SECRET_KEY is not set");
    }
    return $secret;
}

function verify_transaction($reference) {
    $url = "https://api.paystack.co/transaction/verify/" . rawurlencode($reference);
    $ch = curl_init($url);
    curl_setopt_array($ch, [
        CURLOPT_HTTPHEADER => ["Authorization: Bearer " . paystack_secret()],
        CURLOPT_RETURNTRANSFER => true,
    ]);
    $raw = curl_exec($ch);
    curl_close($ch);
    $body = json_decode($raw, true);
    $data = is_array($body) ? ($body["data"] ?? []) : [];
    $ok = is_array($body)
        && ($body["status"] ?? false) === true
        && ($data["status"] ?? "") === "success"
        && ($data["amount"] ?? null) === 500000
        && ($data["currency"] ?? "") === "NGN";
    return ["ok" => $ok, "data" => $data];
}

function fulfil(PDO $db, $reference, $amount, $currency) {
    $db->beginTransaction();
    try {
        $insert = $db->prepare(
            "INSERT INTO fulfilled_payments (reference) VALUES (:reference)
             ON CONFLICT (reference) DO NOTHING
             RETURNING reference"
        );
        $insert->execute([":reference" => $reference]);
        if ($insert->fetch(PDO::FETCH_ASSOC) === false) {
            $db->commit();
            return false;
        }
        $ledger = $db->prepare(
            "INSERT INTO ledger_entries (reference, amount, currency)
             VALUES (:reference, :amount, :currency)"
        );
        $ledger->execute([
            ":reference" => $reference,
            ":amount" => $amount,
            ":currency" => $currency,
        ]);
        $db->commit();
        return true;
    } catch (Throwable $e) {
        $db->rollBack();
        throw $e;
    }
}

function on_callback(PDO $db, $reference) {
    $verified = verify_transaction($reference);
    if ($verified["ok"]) {
        fulfil($db, $reference, $verified["data"]["amount"], $verified["data"]["currency"]);
    }
    return $verified["ok"];
}

function on_charge_success(PDO $db, $event) {
    $data = $event["data"] ?? [];
    if (($data["amount"] ?? null) !== 500000 || ($data["currency"] ?? "") !== "NGN") {
        return;
    }
    fulfil($db, $data["reference"], $data["amount"], $data["currency"]);
}

500000 and NGN in these samples are the amount and currency you charged, in the subunit. They are not a Hooksnode limit.

Verify response pitfalls

These come from the verify-payments page.

response.status is the status of the API call, not the transaction. Check response.data.status.

The transaction statuses are abandoned, failed, ongoing, pending, processing, queued, reversed, and success. Only success gives value.

Compare data.amount (in the subunit, for example kobo) and data.currency to what you expected before giving value.

What the webhook will not tell you

Paystack's verify-payments page says it currently sends webhook events for just successful transactions. A failed or abandoned payment shows up only through verify. Pending orders need a scheduled verify sweep, not a wait for a webhook.

A missing webhook is not always a delivery failure. The checks are in Why your Paystack webhook is not working.

Where Hooksnode fits

Point Paystack at one Hooksnode URL with the Paystack preset. The setup is in Send one Paystack webhook to several services. Hooksnode checks the signature at ingress, saves the event, and fans it out to your app, ledger, Slack or Sheets, each destination retrying on its own for up to 25 delivery attempts in total. Dead deliveries can be batch retried from Needs retry.

Delivery is at least once, never exactly once. The idempotent fulfil function above is still required.

Hooksnode does not replace the verify call on the callback page or the pending-order sweep.

When the workspace has no credits left, Hooksnode stores the event as held and answers 202, until the hold limits. For project Free, with no paid project in the workspace, those limits are 1,000 held events, 50 MB stored, and a body larger than 64 KB is not held. A paid project Pro plan raises the event and byte caps. Workspace Pro ($50 a month) does too. Past a limit, the answer is 402. Paystack retries a 402 on its own schedule, so watch your usage.

Plans

The project Free plan is $0 and includes 100,000 credits a month, with a hard cap.

The project Pro plan is $10/month and includes 1,000,000 credits, with a hard cap.

Checked against the public plans API on 2026-11-19. See pricing.

FAQ

Should the callback URL be the only way I give value?

No. Paystack's support article says not to use the callback as the only way of returning value, because the customer might not get redirected after a network error. Paystack's webhooks page says callbacks can also fail if the connection is weak or the device goes off.

Which verify field is the transaction status?

response.status is the status of the API call, not the transaction. Check response.data.status. Only success gives value.

Does Paystack send a webhook for a failed payment?

No. Paystack currently sends webhook events for just successful transactions. A failed or abandoned payment shows up only through verify.

Does Hooksnode replace the verify call?

No. Hooksnode does not replace the verify call on the callback page or the pending-order sweep.

Further reading