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

# Stripe integration

> How to set up payments in your app using our Stripe integration

![Integrate Stripe in Lovable](https://mintcdn.com/generaltranslation-d8a08cd1/CqzNmr5z5kHJD2HH/images/lovable-stripe.webp?fit=max\&auto=format\&n=CqzNmr5z5kHJD2HH\&q=85\&s=194aab822bbf8977ee51ab606c7c73a3)

Lovable now lets you set up Stripe entirely through **chat**.

**Chat‑driven auto‑setup (recommended)**\
After you connect **Supabase** and save your **Stripe Secret Key** via **Add API Key**, just describe what you need:

* “Add three subscription tiers …”
* “Create a one‑time checkout for my e‑book at \$29”\
  Lovable generates the checkout / portal edge functions, database tables with RLS, and UI buttons—no manual coding or webhooks unless you ask for them.

> [!NOTE]
>
> * For **one‑off sales**, be sure your cart or product page already works.
> * For **subscriptions**, confirm Supabase Auth is in place so Lovable can link Stripe customers to each user’s **id**

### Key takeaways

* Use the **chat‑driven flow** for both subscriptions and one‑off payments.
* **Never paste your Stripe Secret Key in chat.** Configure it via the in-chat **Add API Key** form.
* **Webhooks are opt‑in.** Lovable relies on edge‑function polling unless you request webhooks.
* Debug in **Browser Console → Network/Errors**, **Supabase → Edge Functions → Logs**, and **Stripe Dashboard → Logs**.
* Always test in **Stripe Test Mode**, then deploy.

## Requirements

Before integrating Stripe, ensure the following prerequisites are met:

* The project **must** be connected to Supabase. [Learn more about Supabase](https://docs.lovable.dev/integrations/supabase)
* A **Stripe account** with properly configured products.
* A working **frontend and backend**:
  * For individual product sales, ensure a shopping cart and checkout page are functional.
  * For subscriptions, set up login functionalities and different pricing tiers.

> [!NOTE]
>
> **Please note**
> Stripe integration doesn't work in preview. To test the integration, make sure to deploy. You should also make sure to be in test mode in Stripe when trying out the functionality. When testing payment, card number: 4242 4242 4242 4242, any 3 digits as CVC and any future date will work as a card.

## Stripe payment setup (No‑code chat flow)

Lovable now generates all Stripe logic for you. Once your **Stripe Secret Key** is configured via the in-chat **Add API Key** form and your project is **connected to Supabase**, simply tell Lovable what you need in chat—no manual Payment Links required.

**1. Step 1**

**Prep your project**

* Supabase connected
* Stripe Secret Key added via the in-chat **Add API Key** form
* (Optional) Prices or product IDs handy

**2. Step 2**

Examples:

* Create a one-time checkout for my "Digital Course" at \$29
* Set up an annual Premium plan for \$99, tied to each user's id

**3. Step 3**

**Review & apply**
Lovable auto‑scaffolds the Edge Functions, database tables, and UI components (all tied to the user's id in Supabase). Check the preview, then click **Apply** to deploy.

> [!NOTE]
>
> * Subscriptions should always linked to the authenticated user’s `id` in Supabase for secure, role‑based access.

## Advanced integration: Webhooks & Supabase

For complex payment structures such as **subscriptions and role-based access**, Lovable recommends using **Supabase** to securely handle Stripe integration. This allows for proper webhook handling, subscription management, and role-based access control based on payment tiers.

> [!NOTE]
>
> The Edge Function that handles the necessary changes to the user account should be set up automatically by the AI.

**1. Connect Supabase to Your Project**

Getting started is simple. Lovable makes connecting Supabase effortless with a built-in native integration:

1. Click the **Supabase button** in the top right corner of Lovable.
2. Follow the instructions to link your project.
3. Once connected, Supabase enables secure payment processing, subscription management, webhook handling, customer data storage, and error handling.

**2. Secure Payment Processing**

Initiate the process by prompting Lovable:

> [!NOTE]
>
> Let's connect Stripe to my project. We will begin with secure payment processing.

Lovable will generate the necessary SQL schema for handling payments. This includes database tables for users, subscriptions, and payments. You can review and customize these tables to fit your specific product needs before applying changes.

**3. Implement Edge Functions for Webhooks**

**Edge Functions** in Supabase act as small, high-performance serverless functions that run close to the user, ensuring fast responses. They help process webhook events, such as payment confirmations, before updating the database.

**1. Step 1**

**Retrieve the Endpoint URL** from the Edge Function in Supabase.

**2. Step 2**

**Go to Stripe Dashboard** > Developers > Webhooks > Create an Event Destination.

![Stripe API Key](https://lovable.dev/content/news/stripe-api.png)

**3. Step 3**

**Select Webhook Events** that align with your project needs:

* `payment_intent.succeeded`
* `payment_intent.payment_failed`
* `customer.subscription.created`
* `customer.subscription.updated`
* `customer.subscription.deleted`

**4. Step 4**

**Enter the Endpoint URL** from Supabase.

**5. Step 5**

**Copy the Webhook Secret** and store it securely in **Supabase → Edge Functions → Manage Secrets → Add New Secret**.

> [!NOTE]
>
> If unsure about naming the secret, ask Lovable in **chat mode** for guidance.

**4. Securely Add API Keys**

To integrate Stripe securely, avoid sharing your API key directly in chat. Instead:

![](https://mintcdn.com/generaltranslation-d8a08cd1/At48MABj-G93zw7Y/images/ConnectLovabletoStripe\(1\).png?fit=max\&auto=format\&n=At48MABj-G93zw7Y\&q=85\&s=39b1f7c34adcb245921a7f29c9826a35)

**1. Step 1**

**Go to Stripe Dashboard** > Developers > API Keys.

**2. Step 2**

**Copy the Secret Key** (DO NOT paste it directly in Lovable chat).

**3. Step 3**

**Use the Lovable "Add API Key" feature** to securely store it.

> [!WARNING]
>
> **Important Security Warning**
>
> Never paste your **Secret Key** directly in Lovable chat. Treat it like the keys to your house—exposing it could allow unauthorized access to your Stripe account. Instead, store it securely using Lovable's API key feature.

**5. Testing Your Integration**

* **Use Stripe's Test Mode** to safely test payments.
* **Test card details**:
  * Card Number: `4242 4242 4242 4242`
  * Any future expiration date
  * Any 3-digit CVC
* **Deploy your app**—Stripe integration does not work in preview mode.

## Debugging & Troubleshooting

> [accordion] Check Console Logs
>
> **1. Step 1**
>
> Open **Developer Tools** (Right-click > Inspect > Console in Chrome).
>
> **2. Step 2**
>
> Look for errors and review webhook event logs.
>
> **3. Step 3**
>
> Copy error messages and ask Lovable for debugging assistance.

> [accordion] Review Supabase Logs
>
> **1. Step 1**
>
> Go to **Supabase Dashboard**
>
> **2. Step 2**
>
> Edge Functions
>
> **3. Step 3**
>
> Logs to check for webhook errors.

> [accordion] Verify Webhook Events in Stripe
>
> **1. Step 1**
>
> Navigate to **Stripe Dashboard**
>
> **2. Step 2**
>
> Webhook logs
>
> **3. Step 3**
>
> Confirm that Stripe is sending data correctly.

> [accordion] Use Lovable Chat Mode
>
> **1. Step 1**
>
> Switch to **chat mode** and ask Lovable follow-up questions.
>
> **2. Step 2**
>
> Ask Lovable follow-up questions.
>
> **3. Step 3**
>
> Use the **Rubber Duck Method** & explain your issue step by step to clarify the problem.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.