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

# Flex Checkout Quick Start

> Flex Checkout is our low-code integration to accept HSA/FSA payments.

At this point you should have a Flex account and access to the Flex Dashboard. You should also have completed onboarding by adding your payout information with Stripe.

Below we walk through a full example of how to integrate Flex Checkout into your checkout flow.

## Flex Checkout guide

### 1. Create an API Key in the partner dashboard

> [!WARNING]
>
> If you're getting started, be sure to create an API Key in test mode to
> safely distinguish between testing and production.

In the Flex Dashboard, navigate to the **Developers** section. Here you'll find
an **API Keys** tab where you can create a key to interact with Flex.

Select the `New API Key` button and give your key a name. With this key, you can now
make authenticated requests to the Flex API.

### 2. Define a product to sell

Always keep sensitive information, like price and availability, on your server to
prevent customer-side manipulation. Define product data when creating the Checkout
Session using predefined price IDs or on the fly with `price_data`.

For this example, we've created a product that is eligible with a Letter of Medical Necessity.
To learn more, see the [Product docs](https://docs.withflex.com/developer-guides/products-and-prices/how-products-and-prices-work.md) or
the Product API.

```bash theme={null}
curl --request POST \
  --url https://api.withflex.com/v1/products \
  --header 'authorization: Bearer fsk_test_YzNiYjdhNWItN2FkOS00ZTMyLWE5MmQtZTdhNzMzYzE2NTIy' \
  --header 'content-type: application/json' \
  --data '{"product": {"name": "Test Product","description": "Test Product Description"}}'
```

```json theme={null}
{
  "product": {
    "product_id": "fprod_01HW5MXAPBE79RHMMJJGB4ACAB",
    "name": "Test Product",
    "description": "Test Product Description",
    "created_at": "2024-04-23T14:14:16.029253Z",
    "active": true,
    "upc_code": null,
    "gtin": null
  }
}
```

### 3. Define the price for our product

Using the returned `product_id`, create a one-time price for \$50.99:

```bash theme={null}
curl --request POST \
  --url https://api.withflex.com/v1/prices \
  --header 'authorization: Bearer fsk_test_YzNiYjdhNWItN2FkOS00ZTMyLWE5MmQtZTdhNzMzYzE2NTIy' \
  --header 'content-type: application/json' \
  --data '{"price": {"product": "fprod_01HW5MXAPBE79RHMMJJGB4ACAB","description": "Our awesome new price","unit_amount": 5099}}'
```

```json theme={null}
{
  "price": {
    "price_id": "fprice_01HW5NTAB88NK7HPD0H688EPG9",
    "description": "Our awesome new price",
    "unit_amount": 5099,
    "recurring": null,
    "active": true,
    "product": "fprod_01HW5MXAPBE79RHMMJJGB4ACAB",
    "created_at": "2024-04-23T14:30:05.943282Z",
    "type": "one_time",
    "metadata": null
  }
}
```

### 4. Choose the mode

Checkout supports two modes: `payment` (one-time purchases) or `subscription`.
Learn more about subscription and setup modes in the docs.

### 5. Supply success and cancel URLs

Specify publicly accessible URLs so Flex can redirect after checkout:

* `success_url`: `https://withflex.com/thank-you?success=true`
* `cancel_url`:  `https://withflex.com/thank-you?canceled=true`

### 6. Build your checkout

On your website's order preview page, add a button that calls your server to generate
a checkout session.

### 7. Generate a checkout session

On your server, create a session with your line items and redirect URLs:

```bash theme={null}
curl --request POST \
  --url https://api.withflex.com/v1/checkout/sessions \
  --header 'authorization: Bearer fsk_test_YzNiYjdhNWItN2FkOS00ZTMyLWE5MmQtZTdhNzMzYzE2NTIy' \
  --header 'content-type: application/json' \
  --data '{
    "checkout_session": {
      "line_items": [{"price": "fprice_01HW5NTAB88NK7HPD0H688EPG9","quantity": 1}],
      "success_url": "https://withflex.com/thank-you?success=true",
      "cancel_url": "https://withflex.com/thank-you?canceled=true",
      "mode": "payment"
    }
  }'
```

### 8. Redirect customers to checkout

The response includes a `redirect_url`. Send the customer there to complete payment:

```json theme={null}
{
  "checkout_session": {
    "redirect_url": "https://checkout.withflex.com/pay/c/fcs_01HW5Q2A08N6A0YGZ6T1KARN8S",
    …
  }
}
```

### 9. Try it out

Navigate to the returned `redirect_url` and test with these cards:

* Success: `4242 4242 4242 4242`
* Decline: `4000 0000 0000 9995`

### 10. Congratulations!

You now have a basic checkout integration working 🎉

## Fulfillment

Set up a [webhook](https://docs.withflex.com/developer-guides/integration/checkout/fulfillment.md) to fulfill orders after a payment succeeds.

## Explore checkout session scenarios

Depending on your setup/business you may want to rely on additional parameters that are available as part of the Checkout Session API.
Find some of the common scenarios in our [integration guides](https://docs.withflex.com/developer-guides/integration/checkout/guides.md).


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