A payment acknowledgement is not a shipping instruction
A retailer may fulfil an order after a payment gateway sends a webhook indicating success. The trouble begins when the webhook is delayed, missing, duplicated, forged or delivered out of order. A browser checkout screen can say “payment complete” while the merchant backend has not recorded a settled or authorised payment in the state required by its business rules. Conversely, a genuine payment may be recorded by the gateway while the retailer’s queue remains unavailable. Neither condition justifies blindly issuing a refund or shipping stock. The design needs a way to recover the authoritative payment state, relate it to exactly one order and prevent an old event from changing a newer business decision.
Consider a fictional store with a web frontend, order database, payment gateway, fulfilment queue and courier integration. A customer pays once, but the success webhook never arrives. An impatient customer clicks checkout again, creating a second merchant attempt. Later both delayed events reach the queue, one after the order has already been cancelled. The retailer needs a clear state machine, not a handler that simply treats every “succeeded” event as authority to dispatch. For each order define the permitted transitions and who can override an exception. Keep gateway identifiers, merchant idempotency keys and shipment identifiers distinct; they belong to different systems and can be duplicated independently.
Authenticate the message before interpreting it
Verify the webhook using the gateway’s documented signature method, appropriate key version and raw payload handling. Authentication helps establish that a message came from an authorised sender; it does not by itself prove that the business state is current. Enforce the gateway-specific replay controls and maintain a processed-event record keyed by the provider’s stable event identifier. Do not invent a universal replay timestamp tolerance because provider rules and retry patterns differ. Validate merchant account and environment as well as signature: a signed event from a test account or another connected merchant must not update a production order. Keep secrets out of application logs and rotate them through a controlled overlapping-key procedure where supported.
The receiving endpoint should acknowledge receipt according to provider guidance only after the event has been durably recorded, or otherwise use a safe queueing mechanism with retry handling. A database transaction should atomically record the event and the intended state-change decision where possible. If the queue accepts the event but the order processor crashes, later retries should not cause a second fulfilment. The audit trail should contain a pseudonymous order reference, provider event ID, validated account, signature verification result, payload type, decision and processing timestamp. It should not log cardholder details or payment credentials. Payment-security requirements must be assessed against the merchant’s actual architecture and applicable standards.
Treat the gateway as an evidence source, not an oracle for every action
A missing event calls for a bounded reconciliation query to the gateway’s authoritative payment API, using the merchant’s authenticated server identity. The response must be mapped to the correct customer, amount, currency, merchant account and order attempt. A successful authorisation may differ from capture, settlement or payout, depending on the provider and payment method. The retailer should define which status is sufficient to release goods and which requires a hold. Never infer settlement solely from the latest front-end redirect or email notification. The backend should reject a success event attached to the wrong order or amount even if the signature is valid.
An exception queue should categorise payments as awaiting confirmation, confirmed but unfulfilled, fulfilled but unreconciled, refunded, disputed, reversed or requiring manual review. The categories must reflect the gateway’s actual event model rather than fictitious universal statuses. Build a reconciliation report that compares the merchant order ledger with gateway payments and shipments, including transactions with no matching webhook. Review mismatches at an interval appropriate to the order value and fulfilment speed. A high-value order may require a stronger confirmation step than a low-risk digital entitlement. Commercial risk appetite belongs with finance and operations; security implements enforceable controls and usable evidence.
Ten deliberately awkward test events
Test a valid success event arriving once and confirm that exactly one authorised order transitions to fulfilment. Test the same event identifier twice; the second delivery should be recorded as a duplicate with no additional shipment. Test two different events representing the same payment where the gateway legitimately emits several lifecycle updates; the order should move only through permitted transitions. Test a signed event with the wrong merchant-account identifier; it must not affect any order. Test an event with a tampered payload or invalid signature; it must be rejected and monitored. Test the correct event for an incorrect currency or amount; fulfilment must pause for investigation. These are synthetic sandbox tests, not live card transactions.
Then test a cancellation immediately preceding a delayed payment update. The handler should not reactivate a cancelled order without an explicit approved rule. Test a refund event for a payment that has not been matched to the retailer’s order ledger; it should enter an exception flow rather than trigger an unrelated credit. Test the queue crashing after an event is persisted but before the shipment job is created; the replay should eventually produce one consistent outcome. Finally, simulate temporary gateway API unavailability during reconciliation; orders requiring confirmation should remain in a safe pending state with an operational alert, rather than switch to a success assumption. Record each expected result and the final order, payment and shipment identifiers.
Investigate a mismatch across three ledgers
A robust incident trace joins the provider payment event, internal order-state change and fulfilment job. If an order shipped without a corresponding accepted gateway payment, examine whether the error arose from a signed but wrongly associated event, a stale state transition, a manual override or a forged callback. The classification changes the response. A valid event with bad internal mapping suggests a software defect, while a signature bypass or unauthorised administrator change may justify security escalation. Preserve bounded request bodies, event signatures or verification results, code version, queue delivery history and approvals. Do not erase evidence by replaying transactions before taking a snapshot of the state.
The order manager should have an operational playbook for customer communication. A missing webhook does not necessarily mean the customer’s payment failed; telling them to pay again can create double charges and disputes. Conversely, telling a customer an order has shipped when it is on hold erodes trust. Agents need precise status terms and an escalation channel that does not expose gateway secrets. Keep manual overrides accountable with reason, approval and expiry. A one-off customer-service exception may be justified commercially, but it should not quietly introduce a reusable bypass in the event processor.
Engineer recovery after reconciliation failure
During an integration outage, freeze automatic shipment for payments that cannot meet the agreed confirmation rule. Preserve gateway events in a durable store, monitor backlog age and process them in a deterministic order that respects final business state rather than mere arrival time. Before restoring automatic dispatch, reconcile the outstanding ledger against the provider and verify that no customer was double-charged, refunded twice or shipped twice. Use a bounded canary batch of synthetic or low-risk test orders to verify idempotency after deployment. Roll back the new handler if it changes the same order twice for one legitimate payment. The recovery owner needs a quantitative limit on unreconciled value, not merely a green HTTP health check.
A meaningful management dashboard separates delivery failure rate, signature failures, duplicate-event suppression, reconciliation backlog age, unconfirmed fulfilment exposure and manual overrides. Each metric should show the affected merchant account and a known observation window. Alert thresholds should be tied to order volume; a fixed number of delayed webhooks can mean very different things on a quiet morning and during a sale. Review provider schema changes and signing-key rotations in a staging environment. The operational acceptance statement is simple but demanding: each order has one explainable financial state, and no asynchronous event can create an unauthorised second fulfilment or refund.
Sources and context
- ASD Essential Eight: https://www.cyber.gov.au/resources-business-and-government/essential-cyber-security/essential-eight
- NIST Cybersecurity Framework 2.0: https://www.nist.gov/cyberframework
How Next Defence can assist
For retail, hospitality and ecommerce, Next Defence can scope the specific application and API security problem in this example: A retailer sends goods after receiving a payment success message through a gateway webhook. An engagement could translate the intended safeguard—reconcile authoritative payment state with idempotent fulfilment and exception queues—into an owner-approved work plan and a reproducible check to suppress one synthetic webhook and establish the order remains in review instead of shipping twice. Any assessment would be limited to the agreed systems and would respect the operational constraint: Refunds and chargebacks need separate accounting controls.