# Configuring the Webhook Endpoint

## **Step 4 - Configure the Webhook Endpoint**

The Lemon Squeezy webhook endpoint processes events such as new orders, verifies their authenticity, and stores them in the database. This section will guide you through creating and configuring this endpoint in your application.

### **1. Set Up API Route**

Create an API route, for example, `/api/webhook`, to handle incoming webhook events from Lemon Squeezy. Ensure that this route is secure and configured correctly to handle Lemon Squeezy events.

### **2. Webhook Handler Overview**

Your webhook handler should:

* **Process Incoming Requests**: It verifies the Lemon Squeezy signature, ensuring the event’s authenticity and security.
* **Signature Verification**: Use the `LEMONSQUEEZY_WEBHOOK_SECRET` environment variable to generate an HMAC digest. Compare it with the incoming request signature using a timing-safe method for secure validation.
* **Order Data Handling**: When an `order_created` event is received, the handler can securely extract and save order details in your database.

### **Additional Notes**

* **Feature Flag Configuration**: Ensure Lemon Squeezy is enabled in your `.env` file with `FF_LEMON="true"`. This helps toggle the payment provider without modifying the core code, allowing flexibility across environments.
* **Security**: Signature verification is essential to ensure that only authentic requests from Lemon Squeezy are processed.
* **Database Integration**: Configure your handler to store specific details from each order event, including product name, amount, and user information.

For additional information on Lemon Squeezy’s webhook specifications, refer to their [official documentation](https://docs.lemonsqueezy.com/).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.startupstarterkits.com/ssk-pro-features/payments/index-1/chapter-2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
