Skip to main content

Checkout Widget Methods

Merchants can use the Checkout widget Javascript events to access data and functionality.

API entry point

window.scoApi is the root object for the API and contains all the operations available.

Listening for API readiness

The Checkout raises an event when ready, which can be used to safely access the Javascript Events.

text/javascript
document.addEventListener("checkoutReady", function () {
console.log("Checkout is ready");
});

Available operations

observeEvent

Observes the client data for changes, calling the supplied function when a change is detected. Returns a function that can be called to stop observing the specified property.

Customer events

The following properties are currently supported:

PropertyDescription
identity.isCompany

Value True/False whether the Checkout customer is Private or Company

identity.emailTriggered for change of Email
identity.phoneNumberTriggered for change of PhoneNumber
identity.companyNameTriggered for change of Company Name
identity.firstNameTriggered for change of First Name
identity.lastNameTriggered for change of Last Name
identity.streetAddressTriggered for change of Street Address
identity.coAddressTriggered for change of C/O Address
identity.postalCodeTriggered for change of Postal Code
identity.cityTriggered for change of City
identity.addressLines

Triggered for change of Address. Applicable only for International Checkout

text/javascript
document.addEventListener("checkoutReady", function () {
// Observe the firstName property
var unsubscribe = window.scoApi.observeEvent("identity.firstName", function (data) {
console.log("firstName changed to %s.", data.value);
});
});

Validation events

By subscribing to the event order.validationCallback you will receive a callback function which you can use to tell the checkout us if it should proceed with the purchase or not. The event is triggered when the customer clicks the button to initiate a payment and before the checkout sends a request to the server. The callback expects a response containing a property called valid with the value true or false.

info

If you don't execute the callback within 10 seconds, we will continue with the purchase. If you wish to force the checkout to wait for a response you have to set the RequireClientSideValidationResponse in your MerchantSettings to true while creating your order.

text/javascript
document.addEventListener("checkoutReady", function () {
// Observe the validationCallback property
var unsubscribe = window.scoApi.observeEvent("order.validationCallback", function (data) {
// Execute internal validations
// ***
// Execute callback with a response
data.callback({ valid: true });
});

// Stop observing
unsubscribe();
});

setCheckoutEnabled

Use the setCheckoutEnabled method to enable/disable the Checkout. While disabled, the merchant can safely perform updates to the cart. When finished, call setCheckoutEnabled(true) to re-enable the Checkout and make it reflect the changes made.

text/javascript
document.addEventListener("checkoutReady", function () {
window.scoApi.setCheckoutEnabled(false);
});