Stripe Webhook
This endpoint uses Stripe signature verification for authentication. You must configure your Stripe webhook secret in your environment variables.
Authentication
Instead of an API key, this endpoint requires a valid Stripe signature in thestripe-signature header. Stripe automatically includes this header when sending webhook events.
Supported Events
OpenSight processes the following Stripe webhook events:checkout.session.completed
Triggered when a user completes a checkout session and subscribes to a plan. Actions:- Updates user’s plan_id based on the subscription
- Stores Stripe subscription ID
- Links Stripe customer ID to user account
customer.subscription.updated
Triggered when a subscription is modified (upgrade, downgrade, renewal). Actions:- Updates user’s plan_id to match new subscription tier
- Updates subscription ID
- Handles plan changes automatically
customer.subscription.deleted
Triggered when a subscription is cancelled or expires. Actions:- Downgrades user to free plan
- Removes subscription ID from user record
- Maintains user data for future resubscription
invoice.payment_failed
Triggered when a subscription payment fails. Actions:- Logs payment failure
- Triggers notification to user (in production)
- Allows Stripe to handle retry logic
Request Headers
Stripe webhook signature for verification
Must be
application/jsonRequest Body
The request body follows Stripe’s webhook event structure:Event type (e.g., checkout.session.completed)
Event data object
Response
Always returns true to acknowledge receipt
Example Event (checkout.session.completed)
Example Response
Error Responses
Error message
- 401 Unauthorized - Invalid Stripe signature
- 200 OK - Even on processing errors (to prevent Stripe retries)
Webhook Configuration
-
Stripe Dashboard Setup:
- Navigate to Developers → Webhooks in your Stripe dashboard
- Add endpoint:
https://api.opensight.ai/api/webhooks/stripe - Select events:
checkout.session.completed,customer.subscription.updated,customer.subscription.deleted,invoice.payment_failed - Copy the webhook signing secret
-
Environment Configuration:
-
Testing Webhooks:
Use Stripe CLI to test webhooks locally:
Security
- All webhook events are verified using Stripe’s signature validation
- Invalid signatures are rejected with 401 Unauthorized
- Webhook secret must be kept secure and never exposed
- Events are logged for audit purposes
Best Practices
- Idempotency: OpenSight handles duplicate events gracefully
- Logging: All events are logged with correlation IDs
- Error Handling: Processing errors return 200 OK to prevent Stripe retries
- User Data: Subscription changes are applied immediately to user accounts
Plan Mapping
Stripe subscription price IDs are mapped to OpenSight plan IDs:| Stripe Price ID Pattern | OpenSight Plan |
|---|---|
| Contains “starter” | starter |
| Contains “growth” | growth |
| No subscription | free |