Introduction


Starting with release 2017-05-16, merchants can now use the Checkout JavaScript API to access data and functionality previously internal to the checkout. For the time being, this primarily concerns reloading payment methods and observing changes in the state and data model. Please note that the API is still considered a work in progress and might see significant changes in the coming few releases.

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 API.

Example:

document.addEventListener("checkoutReady", function() {
    window.scoApi... // Your code here
});

Available operations

observeEvent(propertyString, handlerFunction) => function

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.

The following properties are currently supported:

"checkout.state"
"checkout.mode"

"identity.isCompany"
"identity.email"
"identity.postalCode"
"identity.phoneNumber"
"identity.city"
"identity.organisationNumber"
"identity.nationalIdNumber"
"identity.companyName"
"identity.firstName"
"identity.lastName"
"identity.streetAddress"
"identity.coAddress"

"validation.result"

Example:

// Observe the city property
var unsubscribe = window.scoApi.observeEvent("identity.city", function (data) { 
    console.log("City changed to %s.", data.value); 
});

// Stop observing
unsubscribe();

observeModel(propertyString, handlerFunction) => function

Obsolete. Preserved for backwards compatibility but may be removed in a future version. Please, use observeEvent instead.

setCheckoutEnabled(value) => void

Pass a false-ish value to 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.