# Stripe

Integrating Stripe with Formsort allows you to collect payments seamlessly within your forms. This guide will walk you through setting up Stripe, adding it as an integration, and configuring payment components to accept payments from users.

## Adding Stripe

{% hint style="info" %}
Here is a link to Stripe to help you get a Stripe account set up: [Stripe docs | Overview](https://docs.stripe.com/get-started).&#x20;
{% endhint %}

### Adding Stripe to your Form integrations&#x20;

To allow users to make payments through Stripe, you must first add your Stripe account credentials to your flow's integrations.

1. Navigate to **Integrations** → **Data Integrations** → **Stripe**.&#x20;
2. Click **Add a credential**, then select **Add New**.
3. Enter your Stripe credentials:
   * **Publishable Key** (required): Found in your Stripe account configuration.
   * **Secret Key** (required for direct card charges in Formsort).

<div align="left"><figure><img src="https://1036686854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MJPnL__mOdr_mLZ8nwf%2Fuploads%2Fc6Cm0KyKS9fm9JbNQXv1%2Fimage.png?alt=media&#x26;token=87b9f683-2c12-44f6-81fa-a66caa16c566" alt="" width="563"><figcaption></figcaption></figure></div>

At a minimum, you will need to provide a **Publishable Key**, found in your Stripe account configuration. A **Secret Key** will additionally be required to charge  cards directly in Formsort.&#x20;

{% hint style="info" %}
Refer to [Stripe’s documentation](https://docs.stripe.com/keys) to locate your API keys and understand their usage.
{% endhint %}

Ensure that you use the correct keys based on your [environment](https://docs.formsort.com/publishing-and-deployment/environments):

* **Production Environment**: Live Publishable Key (must start with `pk_live_`)
* **Staging or Testing Environment**: Test Publishable Key (must start with `pk_test_`)

The **Description** field is optional but can help your team distinguish configurations across environments.

### Adding the Payment component to the form&#x20;

To enable Stripe payments in your form:

1. Open **Formsort Studio**.
2. Create a **Payment question**.
3. Set **Provider** to **Stripe**.
4. The Studio will then display which environments have Stripe credentials configured.

<div align="left"><figure><img src="https://1036686854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MJPnL__mOdr_mLZ8nwf%2Fuploads%2FgjiK7tcolebwmXbToTew%2Fimage.png?alt=media&#x26;token=d2740eaa-2e45-4136-8015-1f7698543cd1" alt="payment-provider-setup-in-studio"><figcaption></figcaption></figure></div>

***

## Stripe Payments API

There are several ways to collect payments from your users:

* **Charge immediately**
* &#x20;[**Products**](#products)
* [**Charge later**](#charge-later)

### Charge immediately

<div align="left"><figure><img src="https://1036686854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MJPnL__mOdr_mLZ8nwf%2Fuploads%2FhViFboXT2qBtwUVhpXXj%2Fimage.png?alt=media&#x26;token=2aa9085a-2e55-4075-aacc-ced5afe71393" alt=""><figcaption></figcaption></figure></div>

If you enable **"Allow charging the card immediately"**, you can collect payments using:

* [**A** **fixed** **amount**](#a-fixed-amount): Defined in cents by you.
* [**A** **variable amount**](#a-variable-amount): Defined dynamically based on a form variable (**number**-type).
* and [**Product(s)**](#product-s): Pulled from your Stripe Product Catalog.

You can also attach **Phone** and **Email** variables to the transaction, which will be stored in Stripe’s customer and transaction records. Currently, only these fields are supported; additional fields may be added in the future.

{% hint style="info" %}
If you'd like to see other fields added, let us know in our Intercom chat!&#x20;
{% endhint %}

#### A fixed amount&#x20;

Once a **fixed amount** charge is made:

* A **Transaction** is created in Stripe.
* Transactions can be viewed in **Balances → All Activity** in Stripe.
* A **payment ID** is sent to answer integrations, appearing as: `"stripe":"pi_XXXXXXXXX"`.&#x20;

{% hint style="info" %}
**Note:** The payment ID is sent when [answers](https://docs.formsort.com/getting-data-out#sending-answers) are sent, not immediately.
{% endhint %}

Here is an example stripe transaction that was charged for a fixed amount of $95... &#x20;

<div align="left"><figure><img src="https://1036686854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MJPnL__mOdr_mLZ8nwf%2Fuploads%2FcbthLAAFkws7lEOVdnVe%2Fimage.png?alt=media&#x26;token=4509eca3-704e-4393-bc01-821738ece072" alt=""><figcaption></figcaption></figure></div>

***

<div align="left"><figure><img src="https://1036686854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MJPnL__mOdr_mLZ8nwf%2Fuploads%2FJeVyowu8sVPz2LMHwFYt%2Fimage.png?alt=media&#x26;token=f7ce4c5a-1eab-40c5-9b25-10a655b6aad5" alt=""><figcaption></figcaption></figure></div>

And the associated answers sent in the webhook payload at finalize; notice the Stripe object that holds the `paymentIntentId`:&#x20;

```json
{
  "answers": {
    "phone": "6262626262",
    "email": "test@test.com",
    "stripe": {
      "paymentIntentId": "pi_3RADdoC6ecQgQwdM0pfFGa3d"
     },
  }
```

If you [store responses in Formsort](https://docs.formsort.com/saving-and-retrieving-responses), the Stripe object will also be included in the answer set:

<figure><img src="https://1036686854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MJPnL__mOdr_mLZ8nwf%2Fuploads%2FJzjWWrxM2bGrDWWJmMZu%2Fimage.png?alt=media&#x26;token=93b912b1-0a8d-4934-a29f-ac8155671031" alt=""><figcaption></figcaption></figure>

#### A variable amount

With the **Variable amount** setting, the charge amount is dynamically calculated based on a previous form question. The variable must return a `number` [data type](https://docs.formsort.com/response-data-collection-and-management/variable-schema#data-types).&#x20;

<div align="left"><figure><img src="https://1036686854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MJPnL__mOdr_mLZ8nwf%2Fuploads%2FRNBtrgMXdJquoFfyLh8P%2Fimage.png?alt=media&#x26;token=bdd3eba8-e64b-4093-877a-00bd5a9e071d" alt=""><figcaption></figcaption></figure></div>

{% hint style="info" %}
If you don't have a `number` variable, create a [**calculated variable function**](https://docs.formsort.com/response-data-collection-and-management/variable-schema/calculated-answers) that returns the amount (as a `number`) in cents.
{% endhint %}

The transaction record in Stripe will be similar to that of the fixed-amount charge, and the webhook payload will contain the Stripe object with the `paymentIntentId` and the variable used to determine the amount:

```json
{
  "answers": {
    "charge_amount_in_cents": 6000,
    "stripe": {
      "paymentIntentId": "pi_3RADPfC6ecQgQwdM0VKGOZdV"
    },
    "email_address": "test@test.com",
    "phone_number": "1234567890
  },
```

{% hint style="info" %}
If you store responses in Formsort, the Stripe object will also be included in the answer set.
{% endhint %}

### Products

With the **Product** option, Formsort fetches your Stripe products in real time, allowing users to select purchase options.

#### Creating a Product in Stripe

First, you will need to add a product in the **Product catalog** section in Stripe.

1. In Stripe, go to **Product Catalog**.
2. Click **Create Product**.

<div align="left"><figure><img src="https://1036686854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MJPnL__mOdr_mLZ8nwf%2Fuploads%2FGX6yuqRywYxLgjsKtAzB%2Fimage.png?alt=media&#x26;token=498cd331-6fac-4992-8d4c-8e6960672652" alt="create-product-instruction"><figcaption></figcaption></figure></div>

3. Enter:
   * **Name** - appears as the button/dropdown label in Formsort (pictured below).
   * **Amount -** visible based on pricing setup: recurring or one-time.

<div align="left"><figure><img src="https://1036686854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MJPnL__mOdr_mLZ8nwf%2Fuploads%2F837gcNhqDxaaXITfGs2u%2Fimage.png?alt=media&#x26;token=ede956e1-09e4-4376-8014-77a9d7d42e6e" alt="add-a-product-menu" width="553"><figcaption></figcaption></figure></div>

***

<div align="left"><figure><img src="https://1036686854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MJPnL__mOdr_mLZ8nwf%2Fuploads%2F7dPolLPIZ8AcEwsQ5xAc%2Fimage.png?alt=media&#x26;token=4ab91599-24d4-44bb-820b-a347959bf8d0" alt="product-name-field"><figcaption><p>The name field from the Stripe product, as it appears in Formsort</p></figcaption></figure></div>

4. Click **Add Product**.

{% hint style="info" %}
The **More options** fields are required only for the needs of your business, and are not included as part of the Formsort integration.&#x20;
{% endhint %}

#### Configuring Products  in Formsort

Once Products are added in Stripe, configure the **Payment component** in Formsort:

{% hint style="info" %}
Currently, Stripe [will not load in the **Live Preview** of a form](#stripe-in-live-preview). When testing updates to the component, you will need to deploy the form and view a production or staging instance.&#x20;

It is suggested that you use the staging environment for testing, if available. &#x20;
{% endhint %}

1. Click **Edit Products** under **How much to charge**.
2. Choose a **Product Select Component** style:
   * **Buttons**: Styled as [select buttons](https://docs.formsort.com/adding-questions-and-content/question-reference/select).
   * **Dropdown**: Styled as a [dropdown](https://docs.formsort.com/styling/customizing-appearance/dropdown-menu) (select-based option).
   * **Native Dropdown**: Browser-based dropdown styling.

<div align="left"><figure><img src="https://1036686854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MJPnL__mOdr_mLZ8nwf%2Fuploads%2FpWQtOqcNJ3sL5dzW5qpB%2Fimage.png?alt=media&#x26;token=f02f6d78-8934-40bb-829d-265f8c66eebc" alt="formsort-edit-products-menu"><figcaption></figcaption></figure></div>

The **Product Select Component Label** and **Pricing Cards Label** are optional fields that provide additional information when using a Select component or a pricing card.

<figure><img src="https://1036686854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MJPnL__mOdr_mLZ8nwf%2Fuploads%2FmbcGPbZoS3nmtSymBke8%2Fimage.png?alt=media&#x26;token=c0eba49e-429e-4df3-b7ff-af8a7828b87a" alt=""><figcaption></figcaption></figure>

#### **Multiple prices**&#x20;

If a product has multiple price points:

1. In Stripe, go to the product and click **Edit Product**.

<div align="left"><figure><img src="https://1036686854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MJPnL__mOdr_mLZ8nwf%2Fuploads%2FhyvPPDYZGpVLsBukKJMR%2Fimage.png?alt=media&#x26;token=576065de-4d2c-40da-ac59-45412ca78ce4" alt="" width="563"><figcaption></figcaption></figure></div>

2. Click **Add Another Price**.

<div align="left"><figure><img src="https://1036686854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MJPnL__mOdr_mLZ8nwf%2Fuploads%2F88LCDADg9n4b1B1KnuRP%2Fimage.png?alt=media&#x26;token=56e0b37f-6704-48d9-be63-5b9f4646f755" alt="" width="563"><figcaption></figcaption></figure></div>

3. Enable **Is Multiple Price** in Formsort.

<div align="left"><figure><img src="https://1036686854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MJPnL__mOdr_mLZ8nwf%2Fuploads%2Fl5eRLcLbOg6KYO3tU8Ut%2Fimage.png?alt=media&#x26;token=48f8aa7c-f216-43e5-a608-935af681d79b" alt="" width="522"><figcaption></figcaption></figure></div>

Once everything is configured, you will see that the Product has a card for each price tier.

<div align="left"><figure><img src="https://1036686854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MJPnL__mOdr_mLZ8nwf%2Fuploads%2F3l8XtDuasEgMh0SM2kko%2Fimage.png?alt=media&#x26;token=16b7cfcf-47c2-4019-8a55-68f45cc11341" alt="" width="497"><figcaption></figcaption></figure></div>

#### **Passing data into the price cards**

You can pass metadata into the pricing card, to help explain to your users what they are buying at each price point.&#x20;

There are two sections of the card that can be customized: the **title** of the card, and the **description** in the card.&#x20;

<div align="left"><figure><img src="https://1036686854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MJPnL__mOdr_mLZ8nwf%2Fuploads%2FuA17zUUdvUu0hpAQ5aZC%2Fimage.png?alt=media&#x26;token=b5b8ded5-905e-4921-9af9-3d5177fde62d" alt=""><figcaption></figcaption></figure></div>

To pass data into these fields:&#x20;

1. Open the product in Stripe.
2. Click a specific price and select **Edit Metadata**.

<div align="left"><figure><img src="https://1036686854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MJPnL__mOdr_mLZ8nwf%2Fuploads%2Fmi98DTxGsG9aNyB262e0%2Fimage.png?alt=media&#x26;token=b37232f2-fba9-4acd-acba-3b966f4cf27d" alt="" width="563"><figcaption></figcaption></figure></div>

***

<div align="left"><figure><img src="https://1036686854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MJPnL__mOdr_mLZ8nwf%2Fuploads%2FqhJV7GvtKSFUi6LxEwdC%2Fimage.png?alt=media&#x26;token=79d8b3a5-750c-4f8b-b3eb-c8e7daea6684" alt="" width="563"><figcaption></figcaption></figure></div>

3. Add:

* **formsort\_title** (will be inserted into the card title area, and by default will appear as an H4 element).&#x20;
* **formsort\_description** (markdown-supported).
  * e.g. use asterisks to create a bullet list of descriptions, as in the example below.&#x20;

<div align="left"><figure><img src="https://1036686854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MJPnL__mOdr_mLZ8nwf%2Fuploads%2F5y4P0doANuvCaq32uFIc%2Fimage.png?alt=media&#x26;token=9efc7198-a1ee-4bc2-9139-98856aef1543" alt="" width="563"><figcaption></figcaption></figure></div>

#### Styling price comparison cards&#x20;

General styling for comparison cards can be found in **Theme** -> **Components** -> **Comparison Cards**.&#x20;

If you require custom styling, you can use the class names referenced in [Custom CSS](https://docs.formsort.com/css-and-advanced-styling/custom-css-overrides#comparison-cards).&#x20;

#### Transaction record

Once a transaction is made, you will see the transaction record in Stripe update.&#x20;

If you receive webhooks, the Stripe transaction data will be nested in the `stripe` object, along with the session's other answers:

<pre class="language-json"><code class="lang-json"><strong>// Example
</strong><strong>{
</strong>  "answers": {
    "time_zone": "America/Denver",
    "stripe": {
      "paymentIntentId": "pi_3R9wReC6ecQgQwdM1OMlvF7I",
      "subscriptionId": "sub_1R9wReC6ecQgQwdMp5F1ZLOh",
      "selectedProductId": "prod_ROQ0exf8TguzDz",
      "selectedProductName": "Product 2"
    }
</code></pre>

If you [store responses in Formsort](https://docs.formsort.com/saving-and-retrieving-responses), the Stripe object will also be included in the answer set:

<div align="left"><figure><img src="https://1036686854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MJPnL__mOdr_mLZ8nwf%2Fuploads%2F1IVAVnVyrYOFYaKmhbuG%2Fimage.png?alt=media&#x26;token=9eb4e5a3-739a-46c9-bb92-46e59bc0216f" alt="" width="563"><figcaption></figcaption></figure></div>

### Promo Codes&#x20;

To provide a **promo code** field for your users, enable **Allow inline promo code**.&#x20;

<figure><img src="https://1036686854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MJPnL__mOdr_mLZ8nwf%2Fuploads%2F3I8fo9IrlcEo5db7xsIs%2Fimage.png?alt=media&#x26;token=36e2fe0b-3722-4d39-a81c-192adea1c9f1" alt=""><figcaption></figcaption></figure>

If a promo code is valid, the discount will be applied at checkout.

<div align="left"><figure><img src="https://1036686854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MJPnL__mOdr_mLZ8nwf%2Fuploads%2F10LQFlfE6BafsYNl4I7z%2Fimage.png?alt=media&#x26;token=80681ca2-9c4d-4ecb-b977-073a0808503d" alt="" width="563"><figcaption></figcaption></figure></div>

#### Autofilling promo codes

To autofill promo codes for your users:&#x20;

* enable **Promotion code variable** and choose the variable that is going to provide the promo code.&#x20;

<div align="left"><figure><img src="https://1036686854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MJPnL__mOdr_mLZ8nwf%2Fuploads%2FuY96zbAwoN4Istgz6aKV%2Fimage.png?alt=media&#x26;token=f26c6cbe-829d-486d-86aa-e61e7b8b9e96" alt="" width="563"><figcaption></figcaption></figure></div>

Formsort suggests using the following variable types to provide the promo codes:&#x20;

* [External Variable](https://docs.formsort.com/response-data-collection-and-management/variable-schema/external-answers) (URL parameters)
* [API Variable](https://docs.formsort.com/response-data-collection-and-management/variable-schema/api-answers) (API lookup)
* [Calculated Variable](https://docs.formsort.com/response-data-collection-and-management/variable-schema/calculated-answers) (locally-calculated variable)

{% hint style="warning" %}
The definition of the promo code variable should be available before the user arrives at the Stripe checkout step — trying to calculate the definition at the time of checkout could result in errors. &#x20;
{% endhint %}

### Charge later

By default, **"Allow charging the card immediately"** is disabled. In this case:

* A **Token ID** (`tok_XXXXXXXX`) is sent to [answer integrations](https://docs.formsort.com/getting-data-out#sending-answers) when answers are submitted.
* You must charge the user later using the Token ID via Stripe.
* **Products cannot be used with this setting.**

***

## Stripe in Live Preview

The Stripe integration will not be functional in the [Live Preview](https://docs.formsort.com/publishing-and-deployment/preview-window) window. Instead, a card-capture input area and a "start" button will be mocked up to get a sense of how the integration will sit in your form.&#x20;

<figure><img src="https://1036686854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MJPnL__mOdr_mLZ8nwf%2Fuploads%2FeQFUaaZYRqLD1MCpi4Y9%2Fimage.png?alt=media&#x26;token=375d42fe-c7fd-4589-866d-1b33cd7466d1" alt=""><figcaption><p>The Stripe mock-up in the Live Preview. </p></figcaption></figure>

To experience a live test of the integration, deploy your form to the staging or production environments and test the functionality there.&#x20;

<figure><img src="https://1036686854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MJPnL__mOdr_mLZ8nwf%2Fuploads%2F5cwWcfd7k76feP8UECu3%2Fimage.png?alt=media&#x26;token=a99f9163-1fd1-4ca3-97ef-f620e8f26728" alt=""><figcaption><p>The Stripe component in a live, "production" instance.</p></figcaption></figure>

{% hint style="info" %}
Here is more Stripe documentation to help you set up your Stripe account for testing:&#x20;

<https://docs.stripe.com/testing#cards>.&#x20;

Always make sure to test before going live!&#x20;
{% endhint %}
