Callbacks

Configure a JavaScript function to follow completed actions or methods.

Callbacks are JavaScript functions that follow a completed action or method. You can configure a callback to occur within certain conditions. Then, FastSpring will add each callback to a script and individually define them.

Data Callback

The data-data-callback allows you to create a function that occurs each time the SBL loads. This is useful when performing actions based on the data within FastSpring. The data-data-callback returns the entire object associated with the session. You can use this for the following:

  • Bypass directives to display information
  • Apply gathered data to a native react app to display it

Parameters:

  • 1 object
  • 1 parameter

Popup Closed Callback

Use the data-popup-closed callback to create a function that occurs each time your Popup Storefront closes. This only takes place after a successful purchase; abandoned carts result in null.

Parameters:

  • 1 object, which will contain the internal FastSpring Order ID (key: id)
  • 1 customer-facing order reference (key: reference)

🚧

The callback will not fire if a customer closes the browser window instead of the popup.

Popup Webhook Received Callback

Create a function that occurs when FastSpring receives a webhook from your Popup Storefront. You can use the data-popup-webhook-received callback with API calls to post information on your server. For example, you can pass information to create a customer account following a purchase.

Parameters:

The data-popup-webhook-received callback must accept 1 parameter. Browser Scripts are not required to send this callback.

đź‘Ť

The data-popup-webhook-received callback excludes personal information. To gather this information, set up Webhooks events.

Markup Callbacks

After the SBL makes a call to Builder, it updates the webpage with the markup to display relevant directives.

  • data-before-markup-callback: Create a JavasScript function that will occur before the markup is performed. No parameters are passed to this function.
  • data-after-markup-callback: Create a JavaScript function that will occur after the directives are performed. No parameters are passed to this function.
  • markup-helpers-callback: Create a JavaScript "if" statement to return a boolean value. This applies to templates on your store page where a handlebar script is written. If there is no handlebar script, this callback is not included.

Before / After Requests

When you make a request against the SBL, you can make a callback request to occur before or after the original request.

  • data-before-requests-callback: Create a JavasScript function that will occur before the request is performed. No parameters are passed to this function.
  • data-after-requests-callback: Create a JavasScript function that will occur immediately after the request is performed. No parameters are passed to this function.

Error Messages

  • data-error-callback: Create a JavaScript function that occurs when an error is received from the backend. This enables you and the customer to view the error that occurred in the shopping cart. The data-error-callback must accept 2 parameters: an error code and an error string.

  • data-validation-callback: Create a JavaScript function that must accept a JSON object. The JSON object should consist of an array with field validation results. This enables you and the customer to view the error that occurred in the shopping cart. This makes it easier to display user-friendly field validation error messages.