Express API lifecycle

API documentation for version 2 and version 3 of the Spreedly Express Javascript API.

Express overview

Review the Express payment form guide for general-purpose information on using Express.

Spreedly Express is available from the following URL: https://core.spreedly.com/iframe/express-3.min.js

By default, an instance of Spreedly Express will be available on the host page as SpreedlyExpress. Invoke the functions described in these docs using the SpreedlyExpress object.

// Invoke methods on the "SpreedlyExpress" global object,
// for instance...
SpreedlyExpress.openView();

Lifecycle

Including the Express Javascript file on a checkout page does not automatically load the library. Express’s lifecycle must be explicitly managed using these functions.

init

Initialize the Express library. This must be the first call made to Express.

SpreedlyExpress.init("C7cRfNJGODKh4Iu5Ox3PToKjniY", {
  "amount": "$9.83",
  "company_name": "Acme Widgets",
  "sidebar_top_description": "Providing quality widgets since 2015",
  "sidebar_bottom_description": "Your order total today",
  "full_name": "First Last"
}, {
  "email": "[email protected]"
});

Signature

init(environmentKey, displayOptions, paymentMethodParams)

Arguments

NameDescription
environmentKeyThe key of the Spreedly environment where the payment method should be tokenized
displayOptionsMap of display options
paymentMethodParams(optional) Map of values to add to tokenized payment method

displayOptions supports the following values:

NameDescription
amountThe amount to display to the user, including currency. E.g., $9.83.
company_nameThe name of the merchant
sidebar_top_descriptionText to display under the company name
sidebar_bottom_descriptionText to display under the amount
close_labelLabel to use to dismiss the Express view. Defaults to “Cancel”.
name_labelThe input label to use for the user’s name field
number_labelThe input label to use for the credit card number field
cvv_labelThe input label to use for the credit card verification field
expiration_labelThe input label to use for the credit card expiration field
submit_labelThe label for the submit button. Default is “Pay Now”.
full_nameAutofill the user’s name field by specifying a value here

paymentMethodParams supports the following values, which will be stored on the payment method record at Spreedly:

Name
email
address1
address2
city
state
zip
country
phone_number
company
shipping_address1
shipping_address2
shipping_city
shipping_state
shipping_zip
shipping_country
shipping_phone_number

Callbacks

onInitDescription
onInitTriggered when init has completed and other page elements can be safely enabled (such as the payment button)

openView

Open the Express payment window to collect the user’s payment information.

SpreedlyExpress.openView();

Signature

openView()

unload

Completely unloads Express. Removes all DOM elements. Resets all callback functions.

SpreedlyExpress.unload();

Signature

unload()