---
title: "Accepting Payments with Stripe"
description: "How to accept payments with Stripe in LaunchFast starter kits?"
source: "https://www.launchfa.st/documentation/payments/stripe"
---

> **Site index for agents**
> Fetch https://www.launchfa.st/llms.txt to discover every page on this site.
> Every page is also available as Markdown by appending `.md` to its URL.

> Browse the source code [here](https://github.com/LaunchFast-Boilerplates/launchfa.st-astro/tree/master/src/pages/api/stripe).

import { Steps, Tabs, TabItem } from '@astrojs/starlight/components'

LaunchFast ships with a built-in [Stripe](https://stripe.com) integration: a checkout route that creates a Stripe Checkout session, and a webhook route that gives the customer access once they have paid.

Here's how you would set up Stripe to use it with LaunchFast:

<Steps>
  1. Create a [Stripe](https://dashboard.stripe.com/register) account and add a product.
  2. Copy your secret key from **Developers > API keys** in the Stripe dashboard.
  3. Add a webhook endpoint pointing to `https://<your-domain>/api/stripe/webhook` that listens to `checkout.session.completed` and `payment_intent.succeeded`, then copy its signing secret.
  4. Make sure to update the environment variable(s) of your application per the following instruction:

      <Tabs>
        <TabItem label="Astro">
            [https://github.com/LaunchFast-Boilerplates/launchfa.st-astro#payments](https://github.com/LaunchFast-Boilerplates/launchfa.st-astro#payments)
        </TabItem>
        <TabItem label="SvelteKit">
            [https://github.com/LaunchFast-Boilerplates/launchfa.st-sveltekit#payments](https://github.com/LaunchFast-Boilerplates/launchfa.st-sveltekit#payments)
        </TabItem>
        <TabItem label="Next.js">
            [https://github.com/LaunchFast-Boilerplates/launchfa.st-nextjs#payments](https://github.com/LaunchFast-Boilerplates/launchfa.st-nextjs#payments)
        </TabItem>
      </Tabs>
</Steps>

```bash
## Stripe Environment Variables
STRIPE_SECRET_KEY="sk_live_..."
STRIPE_WEBHOOK_SIG="whsec_..."
```

## Adding a Checkout Button

Import the checkout button anywhere in your app. Clicking it calls the `/api/stripe/checkout` route, which creates a Stripe Checkout session and redirects the user to it.

<Tabs>

<TabItem label="Astro">

```astro
---
import ButtonCheckout from '@/components/Buttons/Checkout.astro'
---

<ButtonCheckout brand_name="ACME" />
```

</TabItem>

<TabItem label="SvelteKit">

```svelte
<script>
  import ButtonCheckout from '@/components/Button-Checkout.svelte'
</script>

<ButtonCheckout />
```

</TabItem>

<TabItem label="Next.js">

```tsx
import ButtonCheckout from '@/components/Button/Checkout/Stripe'

export default function Page() {
  return <ButtonCheckout brandName="ACME" />
}
```

</TabItem>

</Tabs>

To change the product, price, discounts, or custom checkout fields, edit the `stripe.checkout.sessions.create` call in the checkout route.

## Handling the Webhook

Once a payment goes through, Stripe calls your webhook route. The starter kit verifies the signature against the raw request body, reads the customer's email, and gives them access in the database:

```typescript
// File: src/pages/api/stripe/webhook.ts

// Obtain the raw body of the request to be used in Stripe for verification
const rawBody = await request.text()
const event = stripe.webhooks.constructEvent(rawBody, sig, `${getSecret('STRIPE_WEBHOOK_SIG')}`)

// Two events in Stripe point to succesful payment
if (event.type === 'checkout.session.completed' || event.type === 'payment_intent.succeeded') {
  const customerEmail = event.type === 'checkout.session.completed' ? event.data.object.customer_details?.email : event.data.object.receipt_email
  if (customerEmail) {
    // Add the 'email' to the access list in the database
    await setAccess(customerEmail, '1')
    return webResponse('approved user access', 200)
  }
}
```

You can add your own logic in the webhook route, like sending a receipt with the `sendEmail` helper or storing the order in your database.

## Testing

In Stripe test mode, pay with the card number `4242 4242 4242 4242`, any future expiry date, and any CVC. To receive webhooks on your local machine, forward them with the [Stripe CLI](https://docs.stripe.com/webhooks):

```bash
stripe listen --forward-to localhost:3000/api/stripe/webhook
```
