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

# Webhooks

> Receive real-time notifications for subscription and payment events.

## Overview

Alana Shopping sends webhook events for billing and subscription changes via Stripe. Your application can listen for these events to automate workflows.

## Supported events

| Event                           | Description                                     |
| ------------------------------- | ----------------------------------------------- |
| `checkout.session.completed`    | Customer completed a checkout session           |
| `customer.subscription.created` | New subscription created                        |
| `customer.subscription.updated` | Subscription plan changed, renewed, or modified |
| `customer.subscription.deleted` | Subscription canceled                           |
| `invoice.paid`                  | Invoice payment succeeded                       |
| `invoice.payment_failed`        | Invoice payment failed                          |

## Webhook security

All webhook payloads are signed by Stripe. Always verify the signature before processing:

```javascript theme={null}
import Stripe from 'stripe';

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);

export async function POST(request) {
  const body = await request.text();
  const signature = request.headers.get('stripe-signature');

  const event = stripe.webhooks.constructEvent(
    body,
    signature,
    process.env.STRIPE_WEBHOOK_SECRET
  );

  // Process the verified event
  switch (event.type) {
    case 'customer.subscription.updated':
      // Update workspace plan
      break;
    case 'invoice.payment_failed':
      // Notify workspace owner
      break;
  }
}
```

<Warning>
  Never process webhook events without verifying the Stripe signature. Unverified webhooks could be spoofed by malicious actors.
</Warning>

## Retry policy

Stripe retries failed webhook deliveries with exponential backoff for up to 3 days. Ensure your endpoint returns a `200` status code promptly to avoid retries.
