Polar webhooks
Fetch current subscription state when Polar webhooks arrive out of order
When a Polar subscription.updated arrives after subscription.revoked, fetch the subscription from Polar before writing access. Process the fetch and write in a single sequence for each subscription ID so a slow worker cannot put an older result back.
- Event order or state
- 3 of 388
Apply the fix
Queue the verified delivery
Verify the signature with the Polar SDK. For a Standard Webhooks endpoint, store
webhook-idunder a unique key scoped to the destination and acknowledge after queueing durably. Usedata.idas the subscription key for the worker. It stays the same across different events for that subscription.Reconcile the current subscription
For
subscription.updated,subscription.canceledandsubscription.revoked, fetchGET /v1/subscriptions/{id}in the owning organization and environment. Serialize the fetch through the commit by subscription ID. Retry temporary API or database failures.Keep cancellation and revocation distinct
Read
cancel_at_period_endandends_attogether with the current subscription status. A scheduled cancellation can leave access intact through the paid term. When Polar revokes the subscription, end access for that subscription ID.
Verify the change
Run npx viberaven check from your repo root. The webhook check starts in VibeRaven 1.15. To run the current release explicitly, run npx viberaven@1.20.1 check. Review payment_webhook_order warnings in the handler. In a test environment, deliver a revocation followed by an older update for the same subscription. Check that stored access still reflects the current Polar subscription.
Research and sources
We labeled 3 of 388 payment and webhook repair commits as event order or state. The sample counts repairs in Git history across payment providers, so the denominator is repair commits across providers.