Actions

Add cart logic, launch checkout, or apply promo codes with simple HTML attributes

Using actions in Store Builder

Use actions to trigger FastSpring cart or checkout events directly in your HTML. By adding a data-fsc-action attribute to buttons, links, or inputs, you can add or remove products, update quantities, launch checkout, or apply promo codes.

Why use actions?

Trigger FastSpring cart and checkout behavior directly in your HTML:

  • No custom JavaScript required: Execute FastSpring actions using data-fsc-action
  • Real-time cart updates: Modify contents instantly without API calls
  • Chained actions: Combine multiple actions in one button for smoother UX

What this guide covers

This guide explains how to:

  • Use cart actions to add, update, remove, and replace products
  • Use checkout actions to trigger checkout flows
  • Use promo and tax actions to apply promo codes and VAT exemptions

Requirements

Before using actions, make sure you:

  • Include the FastSpring Store Builder script

    Click to view script
    <script 
        id="fsc-api"
        src="https://sbl.onfastspring.com/sbl/1.0.3/fastspring-builder.min.js"
        type="text/javascript"
        data-storefront="your-storefront-URL">
    </script>
    

    Replace your-storefront-URL with the full path to a checkout in your store.

    Attribute Description
    id Identifies the script block (must be set to fsc-api)
    src Specifies the version of the Store Builder
    type Declares the script as JavaScript
    data-storefront The storefront URL this script will connect to

Quick start

Follow these steps to enable actions in your FastSpring integration:

  1. Add the Store Builder script

    <!-- Load the FastSpring Store Builder script -->
    <script
      id="fsc-api"
      src="https://sbl.onfastspring.com/sbl/1.0.3/fastspring-builder.min.js"
      type="text/javascript"
      data-storefront="your-storefront-URL">
    </script>
    

    Replace your-storefront-URL with the full path to a checkout in your store.

  2. Add an action element

    Here’s how to add a product to the cart using a data-fsc-action button:

    <button data-fsc-item-path-value="your-product-path" data-fsc-action="Add">
      Add to Cart
    </button>
    

    What it does: Adds a product to the cart by setting its selected state to true.
    What to update: Replace your-product-path with the path of a product from your store.


Actions summary

The table below provides an overview of available actions, what they do, and examples of how they can be used to modify cart contents, apply discounts, and trigger checkout flows.

Action Description Example
data-fsc-action="Add" Adds a product to the cart. The default quantity is one unless changed separately. Requires the product path. View Code
data-fsc-action="Update" Updates the quantity of a product in the cart. Requires a select input with data-fsc-item-quantity-value. View Code
data-fsc-action="Remove" Removes a product from the cart by deselecting it and resetting its quantity to 1. View Code
data-fsc-action="Replace" Replaces one product in the cart with another. Often used to support upsell offers. Requires both product paths. View Code
data-fsc-action="Reset" Clears all products from the cart. No additional attributes required. View Code
data-fsc-action="Checkout" Launches the FastSpring popup checkout for the current session. View Code
data-fsc-action="PaypalCheckout" Opens the checkout window with PayPal selected as the payment method. View Code
data-fsc-action="Promocode" Applies a promo code entered by the buyer. Requires a nearby input with data-fsc-promocode-value. View Code
data-fsc-action="TaxId" Applies a VAT ID for tax exemption. Requires a nearby input with data-fsc-taxid-value. View Code
data-fsc-action="ViewCart" Opens the FastSpring cart popup so buyers can view their selected products. View Code
data-fsc-action="Reset, Add, Checkout" Chains multiple actions into one click. In this example: clears the cart, adds a product, then opens checkout. View Code

Detailed action examples

Below are detailed examples for each action. Click each section to see the code snippet, what it does, and how to use it.

data-fsc-action="Add"

HTML markup + FastSpring script setup:

<!-- Button to add a product to the cart -->
<button data-fsc-action="Add" data-fsc-item-path-value="your-product-path">
  Add to Cart
</button>

<!-- Load the FastSpring Store Builder script -->
<script
  id="fsc-api"
  src="https://sbl.onfastspring.com/sbl/1.0.3/fastspring-builder.min.js"
  type="text/javascript"
  data-storefront="your-storefront-URL">
</script>

What it does:
Adds a product to the cart without modifying its quantity. The default quantity is 1 unless changed using another action.

What to update:

  • Replace your-product-path with the path of a product from your store
  • Replace your-storefront-URL with the full path to a checkout in your store.
data-fsc-action="Checkout"

HTML markup + FastSpring script setup:

<!-- Button to launch the FastSpring popup checkout -->
<button data-fsc-action="Checkout">
  Checkout
</button>

<!-- Load the FastSpring Store Builder script -->
<script
  id="fsc-api"
  src="https://sbl.onfastspring.com/sbl/1.0.3/fastspring-builder.min.js"
  type="text/javascript"
  data-storefront="your-storefront-URL">
</script>

What it does:
Launches the FastSpring popup checkout window using the current session data. The cart must contain at least one product.

What to update:

  • Replace your-storefront-URL with the full path to a checkout in your store.
data-fsc-action="PaypalCheckout"

HTML markup + FastSpring script setup:

<!-- Button to launch checkout with PayPal preselected -->
<button data-fsc-action="PaypalCheckout">
  Pay with PayPal
</button>

<!-- Load the FastSpring Store Builder script -->
<script
  id="fsc-api"
  src="https://sbl.onfastspring.com/sbl/1.0.3/fastspring-builder.min.js"
  type="text/javascript"
  data-storefront="your-storefront-URL"
  data-continuous="true">
</script>

What it does:
Opens the FastSpring popup checkout and preselects PayPal as the buyer’s payment method. The cart must contain at least one product.

What to update:

  • Replace your-storefront-URL with the full path to a checkout in your store.
data-fsc-action="Promocode"

HTML markup + FastSpring script setup:

<!-- Input field to enter a promo code -->
<label for="promo-code">Coupon Code:</label>
<input type="text" id="promo-code" data-fsc-promocode-value placeholder="Enter coupon code" />

<!-- Button to apply the entered promo code -->
<button data-fsc-action="Promocode">
  Apply Coupon
</button>

<!-- Load the FastSpring Store Builder script -->
<script
  id="fsc-api"
  src="https://sbl.onfastspring.com/sbl/1.0.3/fastspring-builder.min.js"
  type="text/javascript"
  data-storefront="your-storefront-URL">
</script>

What it does:
Applies a promotional code entered by the buyer. If the code is valid, FastSpring will automatically update the cart totals.

What to update:

  • Replace promo-code with your preferred input field ID if needed
  • Customize the placeholder text to match your site tone (e.g., "Enter coupon code")
  • Replace your-storefront-URL with the full path to a checkout in your store.
data-fsc-action="Remove"

HTML markup + FastSpring script setup:

<!-- Button to remove a product from the cart -->
<button data-fsc-item-path-value="your-product-path" data-fsc-action="Remove">
  Remove
</button>

<!-- Load the FastSpring Store Builder script -->
<script
  id="fsc-api"
  src="https://sbl.onfastspring.com/sbl/1.0.3/fastspring-builder.min.js"
  type="text/javascript"
  data-storefront="your-storefront-URL">
</script>

What it does:
Removes a product from the cart by changing its selected state to false and resetting its quantity to 1. This does not affect other items in the cart.

What to update:

  • Replace your-product-path with the path of a product from your store
  • Replace your-storefront-URL with the full path to a checkout in your store.
data-fsc-action="Replace"

HTML markup + FastSpring script setup:

<!-- Optional: Display products currently in the cart -->
<div data-fsc-selections-smartdisplay data-fsc-items-container="shopping-cart" data-fsc-filter="selected=true">
</div>

<!-- Button to add an upsell product to the cart -->
<button data-fsc-item-path-value="upsell" data-fsc-action="Add">
  Add to Cart
</button>

<!-- Button to replace an existing product with the upsell -->
<button
  data-fsc-item-path-value="upsell"
  data-fsc-driver-item-path-value="your-original-product-path"
  data-fsc-action="Replace">
  Replace
</button>

<!-- Load the FastSpring Store Builder script -->
<script
  id="fsc-api"
  src="https://sbl.onfastspring.com/sbl/1.0.3/fastspring-builder.min.js"
  type="text/javascript"
  data-storefront="your-storefront-URL">
</script>

<!-- Preload a product into the cart -->
<script>
  fastspring.builder.add("your-original-product-path");
</script>

<!-- Optional: Smart display template for cart items -->
<script data-fsc-template-for="shopping-cart" type="text/x-handlebars-template">
  <ul>
    {{#each items}}
      {{#each items}}
        <li>{{this.display}}</li>
      {{/each}}
    {{/each}}
  </ul>
</script>

What it does:
Replaces one product in the cart with another. Typically used to offer upgrades or swaps between related products or variations.

What to update:

  • Replace upsell with the path of the upsell or replacement product
  • Replace your-original-product-path with the product to be replaced
  • Replace your-storefront-URL with the full path to a checkout in your store.
data-fsc-action="Reset"

HTML markup + FastSpring script setup:

<!-- Button to reset the cart -->
<button data-fsc-action="Reset">
  Empty Cart
</button>

<!-- Load the FastSpring Store Builder script -->
<script
  id="fsc-api"
  src="https://sbl.onfastspring.com/sbl/1.0.3/fastspring-builder.min.js"
  type="text/javascript"
  data-storefront="your-storefront-URL">
</script>

What it does:
Clears the entire cart for the current session. This is useful for giving buyers a fresh start or for testing checkout flows.

What to update:

  • Replace your-storefront-URL with the full path to a checkout in your store.
data-fsc-action="TaxId"

HTML markup + FastSpring script setup:

<!-- Input field to collect the buyer’s tax ID -->
<label for="tax-id">Tax ID:</label>
<input type="text" id="tax-id" data-fsc-taxid-value placeholder="Enter tax ID" />

<!-- Button to apply the tax ID to the order -->
<button data-fsc-action="TaxId">
  Apply Tax ID
</button>

<!-- Optional: Elements used to display order updates -->
<div>Order Total: <span data-fsc-order-total></span></div>
<div>Order Tax: <span data-fsc-order-tax></span></div>

<!-- Load the FastSpring Store Builder script -->
<script
  id="fsc-api"
  src="https://sbl.onfastspring.com/sbl/1.0.3/fastspring-builder.min.js"
  type="text/javascript"
  data-storefront="your-storefront-URL">
</script>

<!-- Set country and preload product for tax logic -->
<script>
  fastspring.builder.country("de");
  fastspring.builder.add("your-product-path");
</script>

What it does:
Applies a VAT ID to the order using the value from the nearest input with data-fsc-taxid-value. This can trigger a tax exemption if the ID is valid for the order’s country.

What to update:

  • Replace 'tax-id' with your own input field ID if needed
  • Replace the placeholder text Enter tax ID to match your site tone
  • Replace your-product-path with the path of a product from your store
  • Replace your-storefront-URL with the full path to a checkout in your store.
data-fsc-action="Update"

HTML markup + FastSpring script setup:

<!-- Dropdown to let the buyer select a new quantity -->
<label for="quantity">Quantity:</label>
<select id="quantity" data-fsc-item-path-value="your-product-path" data-fsc-item-quantity-value>
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
</select>

<!-- Button to apply the updated quantity -->
<button data-fsc-item-path-value="your-product-path" data-fsc-action="Update">
  Update Quantity
</button>

<!-- Optional: Element used to show the current quantity -->
<div>
  Quantity: <span data-fsc-item-path="your-product-path" data-fsc-item-quantity></span>
</div>

<!-- Load the FastSpring Store Builder script -->
<script
  id="fsc-api"
  src="https://sbl.onfastspring.com/sbl/1.0.3/fastspring-builder.min.js"
  type="text/javascript"
  data-storefront="your-storefront-URL">
</script>

<!-- Preload a product into the cart -->
<script>
  fastspring.builder.add("your-product-path");
</script>

What it does:
Updates the quantity of a product in the cart. The Update action looks for the closest data-fsc-item-quantity-value element tied to the selected product path.

What to update:

  • Replace your-product-path with the path of a product from your store
  • Replace 'quantity' with your own select element ID if needed
  • Replace the option values if you want to limit or expand the quantity range
  • Replace your-storefront-URL with the full path to a checkout in your store.
data-fsc-action="ViewCart"

HTML markup + FastSpring script setup:

<!-- Button to open the FastSpring cart popup -->
<button data-fsc-action="ViewCart">
  View Cart
</button>

<!-- Load the FastSpring Store Builder script -->
<script
  id="fsc-api"
  src="https://sbl.onfastspring.com/sbl/1.0.3/fastspring-builder.min.js"
  type="text/javascript"
  data-storefront="your-storefront-URL"
  data-continuous="true">
</script>

What it does:
Opens the FastSpring cart popup so buyers can view their selected products before checking out.

What to update:

  • Replace your-storefront-URL with the full path to a checkout in your store.
Chained actions – data-fsc-action="Reset, Add, Checkout"

HTML markup + FastSpring script setup:

<!-- Button that resets the cart, adds a product, and launches checkout -->
<button
  data-fsc-item-path-value="your-product-path"
  data-fsc-action="Reset, Add, Checkout">
  Add to Cart and Checkout
</button>

<!-- Load the FastSpring Store Builder script -->
<script
  id="fsc-api"
  src="https://sbl.onfastspring.com/sbl/1.0.3/fastspring-builder.min.js"
  type="text/javascript"
  data-storefront="your-storefront-URL">
</script>

What it does:
Executes multiple actions in sequence when the button is clicked. In this example:

  1. Resets the cart

  2. Adds the selected product

  3. Launches the FastSpring popup checkout

    What to update:

  • Replace your-product-path with the path of a product from your store
  • Replace your-storefront-URL with the full path to a checkout in your store.
  • Reorder or edit the actions as needed (Reset, Add, Checkout)