Skip to main content
Next Defence - Next-Gen AI Cyber Security Firm
Australia & New Zealand[email protected](02) 9064 2614
INSIGHT

Reconciliation Test for Subscription Billing Webhooks

Valid webhook signatures do not prevent duplicate credits. Test idempotency, event ordering and ledger reconciliation for subscription billing.

Why a valid webhook can still change the ledger twice

A subscription business receives billing events from a payment provider. The provider may deliver an event more than once, retry after a timeout, or send related events in an order different from their business sequence. A system that treats every authenticated callback as a new financial instruction can grant duplicate credits, reopen cancelled subscriptions or mark an invoice paid before its final settlement state is known.

A reconciliation test should answer a specific question: does the subscription ledger reflect the provider’s authoritative business state exactly once, despite delays, duplicates and conflicting events? It needs more than a valid signature and an HTTP 200 response. Signature checks establish message authenticity under the provider’s protocol; they do not establish that the event has already been processed, that the event is the latest business state, or that a downstream ledger write succeeded.

Define the ledger invariant first

Start with an example subscription account and write the expected state transitions: invoice issued; payment pending; payment captured; credit applied; subscription entitlement activated; refund or chargeback processed if applicable. Specify the accounting or entitlement invariant for each transition. For example, one captured payment with a unique provider transaction reference should not create two customer credits, even if the same delivery arrives five times.

Decide which system is authoritative for each field. The payment provider may control charge status, while the application controls local entitlement activation. Distinguish a provider’s event ID, which identifies a notification, from its transaction or invoice ID, which identifies the underlying commercial object. Multiple legitimate event IDs can refer to the same invoice. A deduplication table keyed only on the first event ID may prevent exact retries but still permit double posting if different events trigger the same financial side effect.

Document edge conditions: partial payment, currency mismatch, proration, cancelled account, refund, tax adjustment, subscription migration and a payment that settles after a timeout. Ask finance to approve the expected ledger outcome. Engineering should not invent billing semantics to satisfy a test case.

Separate webhook acceptance from business processing

The public endpoint should authenticate the request according to the provider’s documented signing method, validate payload structure and enforce appropriate size and rate limits. Where the provider signs a timestamp, verify freshness within the supported tolerance; do not assume an unsigned event identifier protects against replay. Keep signing secrets out of logs, and record secret rotations through a controlled process.

After validation, persist an event receipt and enqueue business processing. Acknowledge the delivery according to the provider’s retry contract once the event is durably accepted, not merely because a request handler started. If the worker crashes between receiving and processing, the queue must preserve the work; if the provider retries, the system must recognise that it already has the event. Avoid making the external provider wait for slow downstream finance reconciliation.

Use a transaction boundary around the durable processing record and its financial side effect where architecture permits. If they reside in different systems, adopt an explicit outbox, idempotent command or compensating reconciliation pattern. A process that records ‘processed’ before writing the ledger can silently lose credit; one that writes the ledger before recording ‘processed’ can double-credit after a crash.

Create the test data and instrumentation

Use a sandbox provider account and a synthetic subscriber. Capture a baseline snapshot of invoice identifiers, provider transaction references, local credit entries and entitlement state. Enable correlation across inbound delivery, queue record, worker execution and database transaction. Every test should preserve the input payload or a safely redacted hash, expected outcome, observed outcome and final reconciliation decision.

Prepare test cases with distinct subscription IDs so one case cannot contaminate another. Include a legitimate new payment, a duplicate notification, an event delivered after its successor, a transient worker failure, a queue outage, a successful refund and a cancelled plan with a late payment. Use the provider’s signed test-event mechanism where possible rather than manufacturing a payload that bypasses signature verification.

Do not run fault injection in a live payment account without controls and approval. The objective is to validate business rules with test funds or provider sandbox transactions, not to create real refunds, capture real cardholder data or interfere with paying customers. Sanitise logs and avoid copying payment instrument details into the QA evidence pack.

Exercise duplicate, replay and out-of-order delivery

First deliver the same signed event twice. The endpoint may acknowledge both according to the provider protocol, but the ledger must show one financial effect. Verify the worker’s deduplication decision and check the queue after restart. Next simulate a captured delivery outside the supported timestamp window. If the protocol provides authenticated timestamps, the stale request should fail freshness validation; if it does not, rely on supported authentication and durable business idempotency rather than claiming protection the protocol cannot provide.

Then deliver a refund notification before a delayed payment-success notification for the same invoice. The application should not reactivate the subscription merely because a stale success event arrived last. Re-fetch the provider’s authoritative object or apply a documented state machine with versioning where needed. Check that reconciliation records the discrepancy rather than burying it behind automatic retry.

Test two different event IDs referencing one transaction. Only the permitted transition should create a ledger credit. Test a worker crash after the ledger commit but before the acknowledgement record. On restart, the processing path must discover the existing effect and avoid creating another one. Record the exact fault-injection point; otherwise the test may never exercise the dangerous interval.

Reconcile external and internal state

At the end of the suite, compare provider settlement objects and local ledger entries by stable identifiers, amount, currency and status. Do not rely only on total dollars: one missing credit can cancel out one duplicate and produce a misleadingly correct aggregate. Compare each transaction individually and then reconcile totals by account and period.

Establish an exception workflow for events that cannot be matched automatically. An unmatched captured payment should be investigated promptly without granting arbitrary access; an unknown refund should be isolated from automatic entitlement changes until verified. Define who can approve manual correction, how dual control works for material amounts and how evidence of each adjustment is retained.

Review eventual consistency explicitly. A delayed event does not necessarily mean a permanent failure, but it must have a monitored age and an escalation threshold. The finance team needs visibility of unsettled reconciliation items, while customer support needs a safe way to explain pending state without manually applying unsupported credits.

Make recovery and operational ownership part of the test

Verify that a worker restart, queue replay and database restore do not cause duplicate side effects. Restore a staging snapshot taken before the event, replay the provider’s available events and reconcile to the current authoritative state. This exercise reveals whether the application depends on ephemeral deduplication data that disappears during recovery. Retain processing keys long enough to cover legitimate retry and recovery windows, based on the actual provider and business requirements.

Document a runbook for signing-key compromise, changed provider event formats and prolonged webhook delivery failure. Include an emergency decision about temporarily withholding entitlements or using verified provider queries rather than blindly accepting events. A provider’s dashboard showing healthy delivery is not proof that local accounting has converged.

Challenge the reconciliation with a controlled race condition

Two valid notifications may arrive at the same moment for the same account. Create a sandbox test in which parallel workers process a payment-success message and a subscription-plan change that both touch the entitlement record. Without database-level constraints or an appropriate concurrency design, both can read an old state, calculate changes and overwrite one another. A single-worker test can pass while production remains exposed to concurrent processing.

Record the initial state and the final state expected under each legitimate ordering. Use a test harness to coordinate worker starts and inspect whether locking, optimistic version checks or the event-state machine resolved the conflict. If only one order is permitted, enforce that rule explicitly; do not rely on whichever worker happens to finish first. The ledger should retain enough correlation to explain why one transition won.

Also exercise a long provider outage followed by a burst of delayed notifications. The system should throttle work safely, preserve the provider’s transaction identities and avoid letting older events undo an already reconciled refund or cancellation. Measure the duration of the backlog, the point at which finance receives an alert, and the time required to reconcile every item. A queue clearing to zero is not sufficient: finance must verify the actual balances and customer entitlements.

Check provider reconciliation when an invoice changes after settlement

Introduce a test invoice that is legitimately corrected after payment, such as a tax adjustment or partial credit. Determine whether the provider emits a revised invoice event, an adjustment event or a separate credit-note object. The application should not infer the accounting entry from an old event name; it must use the provider’s documented object model and the finance-approved treatment. Preserve the link between original payment, adjustment and customer-facing balance.

Test a customer who cancels while the adjustment is pending. The service should not grant a fresh subscription period merely because it receives a delayed success notification. Review the reconciliation report with finance and customer support: can they explain the final balance and entitlement without manually guessing which callback was last? The result demonstrates that the subscription system has an authoritative ledger rather than a sequence of loosely connected notifications.

Check entitlements across a billing-platform migration

When a subscription service moves between billing providers, the same commercial transaction can appear under different external identifiers. A migration plan should define a durable mapping from old invoice and payment references to the new provider’s objects. Replay test data through the migration boundary and verify that historical paid periods do not generate new entitlement grants.

Add an explicit check for subscriptions that are paused, pending cancellation or waiting for dispute resolution. A simplistic migration routine may turn their last positive payment status into an active subscription. Finance and customer operations should approve the mapping and be able to trace the resulting entitlements to the originating evidence.

Acceptance evidence for release

The release owner should require a signed test matrix with expected and observed ledger transitions, a reconciliation report proving zero unexplained duplicates, samples of authentication rejections, queue-restart results, and named finance approval for billing outcomes. Any known limitation must have an owner and a deployment decision. Repeat the suite after material changes to billing logic, event schema, processing architecture or provider integration.

This is an illustrative subscription-billing workflow, not an allegation of a real customer’s payment error. The core lesson is that delivery authentication, idempotent processing and financial reconciliation solve different problems; a reliable subscription service needs all three.

Sources and further reading

How Next Defence can help

A scoped review should cover reconciling subscription-billing webhook delivery after a replay or timeout. Record event IDs, deduplication outcomes, ledger reconciliation and customer-impact handling; an owner should accept both the permitted and blocked outcomes. Next Defence can help design the exercise through Application Security & DevSecOps, subject to the relevant operational approvals.

LET'S TALK

Let’s talk about your security.

Tell us what you are protecting, where you need greater visibility or what you want to achieve. We will help identify the right next step.

Talk to a Security Specialist

Describe your security requirements. Please do not submit passwords, credentials or confidential incident evidence. This form is not an emergency incident-response channel.

Form powered by HubSpot. Review our Privacy Policy. If the form doesn’t load, email [email protected].