> For the complete documentation index, see [llms.txt](https://accelerator.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://accelerator.gitbook.io/docs/setup/payments.md).

# Payments

{% hint style="info" %}
Supported providers:

* [Stripe](#stripe)
* [LemonSqueezy](#lemonsqueezy)
  {% endhint %}

### Stripe 💰

1. Create Stripe account: <https://dashboard.stripe.com/register>
2. Important to note. You can switch between "live" and "test" environment with the following toggle. API keys you generate, products you create etc., **are bound to the environment** you create them in. So if you create API key in test, it won't exist in "live". Same goes for products, coupons, etc.

   <figure><img src="/files/BxbOdCS4xkXztuUYeu0K" alt="" width="375"><figcaption></figcaption></figure>
3. Create `public` and `secret` key **test**: <https://dashboard.stripe.com/test/apikeys>
4. Create `webhook` key in **test**: <https://dashboard.stripe.com/test/webhooks>
5. Set `.env` variables:\
   `STRIPE_PUBLIC_KEY=pk_...`\
   `STRIPE_SECRET_KEY=sk_...`\
   `STRIPE_WEBHOOK_SECRET=whsec_...`\
   Note: Public key is prefixed with "pk", secret key with "sk" and webhook secret with "whsec".
6. When creating a webhook select a route which handles these, in our case it's: `/api/webhook/payment` and select events you want to recieve, example:

   <figure><img src="/files/oavZcubDnp9xjOKcCl3i" alt="" width="370"><figcaption></figcaption></figure>
7. If you want to know how to test webhooks locally, without having website online, checkout this section.
8. Now your Stripe setup is ready and you can add products :)\
   Further documentation: <https://docs.stripe.com/keys>

### LemonSqueezy 🍋

1. Create account: <https://app.lemonsqueezy.com/dashboard>
2. Create `api` keys. API keys are bound to enviroment. API key created in "test" won't work in "production": <https://app.lemonsqueezy.com/settings/api>
3. Create `webhook` key and signing secret: <https://app.lemonsqueezy.com/settings/webhooks>

   <figure><img src="/files/MZxKM9iydSFUYj9K0CNG" alt="" width="272"><figcaption></figcaption></figure>
4. When creating a webhook select a route which handles the incoming events, in our case it's: `/api/webhook/payment` and select events you want to recieve (see picture above).\
   If you want to know how to test webhooks locally, without having website online, checkout this section.
5. Set `.env` variables:\
   `LEMON_SQUEEZY_API_KEY=`\
   `LEMON_SQUEEZY_WEBHOOK_SECRET`=
6. Now your LemonSqueezy setup is ready and you can add products :)\
   Further documentation: <https://docs.lemonsqueezy.com/guides/developer-guide/getting-started>

### Webhooks (payment)

Webhook allow external services, in this case payment provider, to notify your application when specific events occur, such as successful payments.

Your application listens for incoming webhook events at this route:

```
/api/webhook/payment
```

**Testing webhooks locally**

Since webhooks are usually sent to public URLs, testing them locally requires a workaround. You can use [webhook.site](https://webhook.site/) to inspect and debug incoming webhooks and test them before going live.

1. Visit [webhook.site](https://webhook.site/) and copy the generated URL.
2. Configure your webhook sender (e.g., Stripe) to send events to this URL.
3. Install CLI globally: `npm install -g @webhooksite/cli`
4. Run the listener with the command:\
   `whcli forward --token=xxxxxxxxxxx --target=http://localhost:3000/api/webhook.payment`\
   (Note: make sure you use correct token. Also use http, rather then https)
5. Make a "test" purchase to trigger the webhook
6. Check the logs in webhook.site to see the payload being sent.
