Take a look around.
Node.js / Payments

When a Stripe webhook arrives twice

By Lan T.6 min read

Verify the request, retain the event identity and make its business effect safe to repeat. Receiving a webhook and completing an access update are separate steps. Keep enough state to tell what was received, what was processed and what still needs attention.

Diagram: verify the signature, then record the receipt, then apply the change once, then retry the follow-up.
Record the event once and keep a retryable follow-up separate from the purchase.Open the full diagram ↗

Why can the same payment update arrive again?

A webhook tells your app that something happened in Stripe. Stripe documents automatic retries, manual resends and event ordering that your integration should account for. A repeated delivery needs to be an expected case in the design.

The practical question is what your app does with it. Recording a second purchase, sending another invitation or extending access again can create a support problem even when the webhook endpoint returns a successful response.

Check the signature before accepting the event

Verify the Stripe signature against the unmodified request body using the endpoint’s signing secret. Parsing and rebuilding the JSON can change the bytes that the signature covers. Stripe explains this requirement in its webhook documentation.

Keep signing secrets on the server. The handler should reject a request that fails verification, rather than treating its claimed event ID as proof that it came from Stripe.

Store receipt separately from the work that follows

Give each received event a durable identity and a processing state. A repeated delivery of an event already recorded should not create another copy of the same work.

RoleHarbor stores received Stripe events in a SQL inbox before processing their effects. The hosted system uses PostgreSQL through Hyperdrive. Cloudflare Queues wakes the billing and access workers; the stored records explain what arrived, what completed and what needs recovery.

Keep the receipt path focused. Persist the work safely before acknowledging it, then let the processing step handle slower tasks. Avoid making a successful webhook response depend on completing an unrelated email or access-provider request.

Cloudflare Queues delivers at least once, so a wake-up can repeat too. RoleHarbor treats the SQL record as the authority and makes the business effect safe to repeat. Scheduled recovery can find work whose queue notification was missed; queue acceptance alone is not a completed payment or role update.

Protect the payment action as well as the event ID

Two different event IDs can relate to the same underlying payment. A check for “have I seen this event?” does not, by itself, answer “have I already recorded this purchase?” Keeping the intended result unchanged when a request repeats is called idempotency.

Choose the identity for each business action deliberately. In RoleHarbor, payment recording uses the payment reference so a repeat does not add a second payment and entitlement for that reference. A separate paid object should still create its own purchase.

A database constraint and a transaction help preserve these rules when workers overlap. The review needs to cover both repeated event delivery and repeated business effects, including simultaneous requests.

Recurring billing also needs the paid invoice period and the active subscription item. RoleHarbor handles renewal and plan-change records without treating a credit line as another purchase. A change to the subscription does not by itself establish that an upgrade was paid.

IdentityQuestion it answers
Event IDHas this notification already been recorded?
Payment or other business referenceHas this particular business effect already been applied?
Work item and processing stateWhat is pending, completed or waiting for recovery?

Make a failed follow-up visible and retryable

A payment record and delivery of an access change are different facts. If another service is unavailable, keep the payment and the pending work visible so staff can understand what needs attention.

A retry should return to the recorded work and reevaluate the relevant current state. Membership may have expired, been refunded or been restricted since the first attempt. Sending the old action again without checking that state can produce the wrong result.

Define who can retry, what the retry is allowed to change and where the result will appear. Keep retries controlled and retain a history of failures and recovery.

In the RoleHarbor demo, an Owner can restore the default Stripe test and Discord connection settings. This does not clear event receipts, create another payment or replay a completed event. Recovering a failed delivery still means reviewing the existing work and its current eligibility.

Ask for checks that inspect the resulting records

The checks should go beyond an HTTP success response. Inspect the stored events, purchases, access records and processing state after the request and worker have finished. Include a separate-payment case so an over-broad duplicate guard does not discard valid work.

ScenarioExpected result
Wrong signature or altered request bodyRequest rejected before an event is stored.
Same event delivered repeatedlyOne inbox record and no repeated business effect.
Duplicate arrives after processingCompleted work stays completed without another purchase.
Another event ID refers to the same paymentPayment recording remains safe to repeat.
A separate valid payment arrivesThe separate purchase is retained.
Provider lookup failsRetry state is retained without a partly applied purchase.
Provider recoversRecorded work can complete through the controlled retry path.

Where AI agents and people fit in this change

A coding agent can map the receipt and worker paths, draft the test matrix and run the agreed checks. The person responsible for the product confirms what counts as one purchase, how long access lasts and which changes a retry may make.

The developer reviews the implementation and the assertions behind the results. Check that the tests use the real handler and database rules where required, and record which external responses were simulated. An agent’s test summary is evidence to inspect, not a human approval.

For QA, agree on the rules, scenarios and review responsibilities before the change. For QC, run the checks and inspect their outcomes. Then have the nominated person review the member-facing result and the release owner confirm readiness.

  • Spec: product owner confirms duplicate, refund and access rules.
  • Development: developer reviews the agent’s focused code changes.
  • Tests: agent runs the matrix; developer checks coverage and resulting state.
  • Human review: product owner tries the relevant journey; the release owner decides whether required findings are resolved.

Start with the failing flow and the expected result

Bring the event type, the behavior you expected and an anonymized description of what happened. Useful context includes whether the event was received, whether processing completed and which downstream action failed.

Remove signing secrets, private keys and customer details from anything you share. We can agree on a safe example and a first check before changing the integration.

Explore the working system

Try RoleHarbor for yourself.

RoleHarbor serves one business and one Discord server. Try the member journey or sign in as Owner, Administrator or Viewer. The demo uses Stripe test mode; no real charges are collected. Discord uses the configured demo server.

How to sign in and restore the connections
  1. Open the staff demo. The sign-in page lists the three available accounts.
  2. Choose Owner, Administrator or Viewer to fill in the email and password. Start with Viewer if you want to look around.
  3. Select Sign in. Use the workspace navigation to explore members, plans, billing and operations.
Owner
demo.owner@beemvp.comBusiness and provider settings, package-to-role mapping, room access and membership operations.
Administrator
demo.admin@beemvp.comDay-to-day membership operations, packages, billing and eligible failed-work retries.
Viewer
demo.viewer@beemvp.comRead-only access to the workspace. Changes are refused by the server.

Shared password: RoleHarbor@Demo

These public accounts keep fixed sign-in details. They cannot change staff accounts, passwords or MFA. Private staff accounts retain the full team and security controls.

Restore the default connections

Sign in as Owner, open Connections and choose Reset demo. Enter the shared password, then select Restore default connections.

This restores the saved Stripe test keys and Discord connection settings. It keeps members, payments, plans and activity. It does not undo Discord room changes, reverse payments or reset the whole workspace.

This is a shared workspace, so other visitors may change its records. Use test information when trying an editable role.

Further reading & related work

Product examples and references for the decisions in this note.

Have a similar piece of work?

Walk me through the payment flow that needs attention.

Tell me what you’re working on ↗

Keep reading