Operations

Webhooks and System Sync

Synchronize Clerk users and Stripe payments with verified, idempotent webhook handling.

8 minUpdated 2026-02-15
Summary

Synchronize Clerk users and Stripe payments with verified, idempotent webhook handling.

5 deep-dive sections0 code samples
Quick Start
  1. Enable observability for requests and failures.
  2. Run replay checks before policy changes.
  3. Set alert thresholds for error and fallback rate.
  4. Document rollback steps for incidents.

Endpoints

SourceEndpointPurpose
Clerk/api/webhooks/clerkUser lifecycle sync
Stripe/api/webhooks/stripeCheckout settlement to wallet credits

Clerk events handled

  • user.created — create local user with signup bonus (40 free credits)
  • user.updated — sync email and name changes
  • user.deleted — deactivate user account

Clerk webhooks are verified using Svix signatures. If the auth middleware already auto-created the user before the webhook arrives, the webhook gracefully updates instead of duplicating.

Stripe events handled

  • checkout.session.completed — wallet top-up fulfillment
  • checkout.session.async_payment_succeeded — delayed payment confirmation

Both events trigger the same fulfillment flow: validate metadata, check idempotency, and credit the user wallet. Events are deduplicated by stripe_payment_id to prevent double-crediting.

Sync hardening

Reliability controls
Signature verify
Reject unsigned or invalid webhook payloads
Idempotency
Deduplicate replayed deliveries
Identity checks
Validate user/customer linkage before crediting
Mode checks
Ignore environment mismatch events

Setup checklist

  1. Configure webhook endpoints in Clerk and Stripe dashboards.
  2. Set webhook secrets in environment variables.
  3. Send test events and verify logs.
  4. Validate duplicate event handling.
Production safety

Never run webhook handlers without signature verification. Treat all inbound webhook traffic as untrusted until verified.

Docs Assistant

ChatKit-style guided help

Product-scoped assistant for LLMWise docs and API usage. It does not answer unrelated topics.

Sign in to ask implementation questions and get runnable snippets.

Sign in to use assistant
Previous
Semantic Memory API Reference