TalkamDeskOriginal posterJoined 2026
★ 1.3k reputation
TalkamDesk15 Nov 2026

Every Nigerian app that takes money eventually meets the same bug: a customer pays, the page says "success", but the order stays pending. Or worse, a customer is credited twice. The cause is usually a weak payment webhook integration.

This guide covers patterns that apply to most providers used in Nigeria. Always follow your provider's own documentation for exact fields, headers and signing methods.
What a payment webhook isWhen a customer pays, several things happen:
  1. Your app creates a transaction with the provider and redirects the customer to pay.
  2. The customer pays by card, bank transfer or USSD.
  3. The provider redirects the customer back to your site.
  4. Separately, the provider sends a webhook to your server with the final status.

The redirect is for the customer's experience. The webhook, plus a server-side status check, is how your system should decide what happened.
Rule 1: never trust the redirectA redirect URL can be visited without paying. Users can copy, modify or replay it. Treat it only as a signal to show "we are confirming your payment" and to start a server-side check.
Rule 2: verify the payment webhookAnyone can send a POST request to your webhook URL. Before acting on one:
  • Check the signature. Most providers sign the request body with a secret key, often using HMAC. Recompute the signature from the raw body and compare it in constant time.
  • Use the raw body. Parsing and re-serialising JSON can change the bytes and break the signature.
  • Check the source if offered. Some providers publish IP addresses for webhooks. Use them as an extra check, not the only check.
  • Reject quickly. Return an error for bad signatures and log the attempt.
// Pseudocode: verify, then acknowledge fast
raw = request.rawBody
expected = hmac_sha512(secret, raw)
if not constant_time_equal(expected, request.headers["signature"]):
    return 401
enqueue("payment-event", raw)
return 200
Rule 3: requery before giving valueEven with a valid signature, confirm the transaction with the provider's API before crediting a wallet or shipping goods. Check:
  • The status is final and successful.
  • The amount and currency match what you expected.
  • The reference matches your own transaction record.
  • The transaction has not already been processed.

This protects you against mistakes, replays and partial payments.

Discuss on Programming
Rule 4: idempotency, or "process once"Providers retry webhooks if they do not get a success response. Networks fail. Your own server may time out. So the same event can arrive several times.

Make processing idempotent:
  • Store each provider event or transaction reference with a unique constraint in your database.
  • Process inside a database transaction: check the record, update the order, write the ledger entry and mark the event processed together.
  • If the event is already processed, return success without doing anything else.
BEGIN;
  SELECT status FROM payments WHERE reference = $1 FOR UPDATE;
  -- if status = 'PAID': COMMIT and return
  UPDATE payments SET status = 'PAID', paid_at = now() WHERE reference = $1;
  INSERT INTO ledger (account, amount, ref) VALUES (...);
COMMIT;
Rule 5: respond fast, work laterReturn a success status quickly, then do heavy work in a background job. Slow handlers cause timeouts and extra retries. A queue also lets you retry your own failures safely.
Rule 6: handle every statusPayments are not just "success" or "failed". Plan for:
  • Pending: bank transfers and USSD can take time.
  • Failed or abandoned: release reserved stock and notify the user.
  • Partial or overpaid transfers: decide how to handle amounts that do not match, and flag them for review.
  • Reversals and refunds: update the ledger with a reversing entry, never by deleting the original.
  • Chargebacks or disputes: freeze related value and alert your support team.
Rule 7: reconcile dailyWebhooks can be delayed or lost. A daily reconciliation job compares your records with the provider's settlement reports and API. It finds:
  • Payments marked pending that are actually successful.
  • Payments you recorded that the provider did not settle.
  • Differences in amounts or fees.

Many teams also run a periodic "requery pending payments" job every few minutes for recent transactions.
Security and data protection
  • Store secret keys in environment variables or a secrets manager, never in code or Git.
  • Rotate keys if they may have leaked.
  • Log events without storing full card numbers or sensitive personal data.
  • Restrict who can view payment logs.
  • Nigeria's Data Protection Act applies to personal data you process. Plan for it from the start.
Testing your payment webhook
  • Use the provider's test or sandbox mode and test keys.
  • Use a tunnelling tool to expose your local server for test webhooks, or the provider's webhook test tool.
  • Test duplicates: send the same event twice and confirm only one credit.
  • Test bad signatures, wrong amounts and out-of-order events.
  • Test what happens when your database is down.
Why not just trust the redirect after payment?
Redirects can be visited without paying and can be modified. Always confirm payments on your server with a verified webhook and a status check.
What is idempotency in payments?
It means processing the same event more than once has the same effect as processing it once, so duplicate webhooks never cause double credits.
Should I respond to the webhook before processing?
Verify it, store or queue it, then respond quickly. Do the heavy processing in a background job.
How do I handle bank transfer payments that arrive late?
Treat them as pending, requery periodically, and process them when they become final. Reconcile daily.
Your war storiesWhat payment bugs have you met in production, and how did you fix them? Share patterns, not secret keys or customer data.

More in ProgrammingWebmasters board