> ## Documentation Index
> Fetch the complete documentation index at: https://docs.searchcompany.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Overview

> Architecture for the Stripe Webhook endpoint

## Purpose

Handles Stripe webhook events for subscription management. Updates both database and Clerk organization metadata.

## Handled Events

| Event                           | Action                                         |
| ------------------------------- | ---------------------------------------------- |
| `checkout.session.completed`    | Link Stripe customer to org, set status active |
| `customer.subscription.created` | Update subscription status                     |
| `customer.subscription.updated` | Update subscription status                     |
| `customer.subscription.deleted` | Set status to canceled                         |

## Architecture

```mermaid theme={null}
flowchart TD
    Stripe["Stripe Webhook"]
    
    subgraph verify [Verification]
        VerifySig["Verify signature"]
    end
    
    subgraph update [Updates]
        UpdateDB["Update clerk_organization_details"]
        UpdateClerk["Update Clerk metadata"]
    end
    
    Stripe --> VerifySig
    VerifySig --> UpdateDB
    UpdateDB --> UpdateClerk
```

## Signature Verification

Uses `STRIPE_WEBHOOK_SECRET` to verify webhook authenticity.

## Code Location

```
src/app/webhooks/stripe_webhook/routes.py
```
