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

# Payments

> Choose between Stripe, or Lemon Squeezy (not implemented)

## Implementation

The main logic can be found in the `service-go-user/domain/payment/provider.go` file.

The payments implementation can generate the client **Checkout Session** to process payments, the **Customer Portal** to check invoices, and includes a **Webhook** implementation to listen for changes.
The flow is as follows:

1. The user clicks the subscribe button, sending a request to the backend.
2. The backend generates a Checkout URL.
3. The user completes the order.
4. A webhook on the backend listens for changes and updates the client's status accordingly.
5. After the client is created in the payment provider, they can visit their customer portal to check all invoices.

The local provider is a mock implementation that doesn't require any configuration. It generates a random customer ID and subscription end date.

### Webhook

Since the webhook needs to listen for changes, the gRPC configuration still includes an HTTP server.
The payments webhook has a separate file for HTTP routes: `service-go-user/http/route_webhook.go`.
Regardless of the provider, remember to set up the webhook URL in the provider's dashboard, pointing to the `/payments/webhook` route.

To test Stripe webhook locally, you can use the Stripe CLI, authenticate, and forward the events to the local server:

```bash theme={null}
sh scripts/stripe.sh
```

Lemon Squeezy doesn't have a CLI, so you need to set up a tunnel to forward the events to the local server. One option is [Cloudflare Tunnel](https://one.dash.cloudflare.com).

## Configuration

This choice can be made using the **GoFast CLI** or by modifying the `docker-compose.yml` file.

### via CLI

Possible options are `Stripe`, `Lemon Squeezy` and `Local (mock)`.

### via Docker Compose

Possible options are `stripe`, `lemon` and `local`.

### Payments Configuration

Depending on the provider, you need to set the following environment variables in the `docker-compose.yml` file:

* for `stripe`, set `STRIPE_API_KEY` and `STRIPE_PRICE_ID`.
* for `lemon`, set `LEMON_API_KEY`, `LEMON_VARIANT_ID` and `LEMON_STORE_ID`.
* for `local`, no configuration is needed.

```yaml theme={null}
services:
  server:
    environment:
      PAYMENT_PROVIDER: stripe
      STRIPE_API_KEY: ${STRIPE_API_KEY}
      STRIPE_PRICE_ID: ${STRIPE_PRICE_ID}
      STRIPE_WEBHOOK_SECRET: ${STRIPE_WEBHOOK_SECRET}
      # PAYMENT_PROVIDER: lemon
      # LEMON_API_KEY: ${LEMON_API_KEY}
      # LEMON_VARIANT_ID: ${LEMON_VARIANT_ID}
      # LEMON_STORE_ID: ${LEMON_STORE_ID}
      # PAYMENT_PROVIDER: local
```

## Getting Secrets

### Stripe

To get the `STRIPE_API_KEY`, `STRIPE_PRICE_ID` and `STRIPE_WEBHOOK_SECRET`, you need to create an account on the [Stripe](https://dashboard.stripe.com) website and get the keys from the dashboard.

1. Go to the [Stripe Api Section](https://dashboard.stripe.com/apikeys).
2. Copy the `Secret Key` and set it as the `STRIPE_API_KEY`.
3. Create a new product and price in the [Products](https://dashboard.stripe.com/products) section.
4. Go to the `Prices` tab and create a new price.
5. Go to the price details.
6. Copy the `Price ID` and set it as the `STRIPE_PRICE_ID`.
7. Go to the [Webhooks](https://dashboard.stripe.com/webhooks) section.
8. Create a new webhook with a `Signing Secret`.
9. Copy the `Signing Secret` and set it as the `STRIPE_WEBHOOK_SECRET`.

### Lemon Squeezy

To get the `LEMON_API_KEY`, `LEMON_VARIANT_ID` and `LEMON_STORE_ID`, you need to create an account on the [Lemon Squeezy](https://app.lemonsqueezy.com) website and get the keys from the dashboard.

1. Go to the [Lemon Squeezy Api Section](https://app.lemonsqueezy.com/settings/api).
2. Create a new API key and set it as the `LEMON_API_KEY`.
3. Create a new product on the [Products](https://app.lemonsqueezy.com/products) section.
4. On the list, open the dropdown and click on `Copy variant ID`. Set it as the `LEMON_VARIANT_ID`.
5. Go to the [Stores](https://app.lemonsqueezy.com/settings/stores) section, where you can find the `Store ID`. Set it as the `LEMON_STORE_ID`.

## Need help?

Visit our discord server to ask any questions, make suggestions and give feedback :).

[https://discord.gg/EdSZbQbRyJ](https://discord.gg/EdSZbQbRyJ)
