docs
  1. SCAYLE Resource Center
  2. Checkout Guide
  3. Integration
  4. Webcomponent

Webcomponent

SCAYLE's Webcomponent acts as our window in your website or app to provide a bulletproof yet fully customizable checkout-experience.

Follow these steps to start the integration:

  1. Access to the SCAYLE Panel
  2. Shop Data & Configuration
  3. Shop backend middleware layer
  4. Authentication Service integration
  5. Baskets
  6. Endpoint URLs
  7. CORS Settings

Refer to Native Mobile App for details on how to set up Checkout on mobile devices.

Access to the SCAYLE Panel

To start integrating the Checkout, ensure you have access to your SCAYLE Panel in the desired environment, to get a valid shop ID (same as appId).

Note: A SCAYLE Account Manager must activate your Checkout. You can access Checkout on a test environment and on public/internal domains where the shop is hosted (see Endpoint URLs).

Your SCAYLE Account Manager must add the IP addresses of users involved in the migration or your company VPN to SCAYLE’s allow-list. Contact your SCAYLE Account Manager with the required IPs

For most Checkout interactions, you'll need appId parameter (same as shopId)

Get shop ID in the SCAYLE Panel

  1. Go to Shops and select your shop.

Shop ID in the SCAYLE Panel

Shop Data & Configuration

Before the checkout systems can be used, you need to have shops and products in your environment. For further information, see the getting started guide.

For most Checkout interactions, you'll need:

  • appId parameter (same as shopId)

To sign tokens, you'll need:

  • shopToken and shopSecret

Note: Never expose shop tokens/secrets via frontend code, Git repositories, or other public places. This may pose a major security risk.

You can customize Checkout for your shops via the SCAYLE Panel. For details, see the Checkout Configuration section of the User Guide or follow the Configuration & Customization section of this guide.

Checkout settings in the SCAYLE Panel

Shop backend middleware layer

Before integrating the Checkout in your shop frontend, you'll need to add a backend middleware layer within the same origin as your shop. This middleware should then handle all interactions with the Checkout APIs, validate signatures with the shopSecret, etc.

  • To avoid CORS issues it's recommended that the middleware (e.g. /api/checkout/ ) is served from the same domain as the main shop.
  • When using multiple shops, e.g. for different locales, keep in mind that you have to either pass the information (shopId) via API or deploy a shop-specfic middleware instance which is aware of the config.
  • Never expose secrets or access tokens to your frontend

Authentication Service integration

Make sure to have your integration with the Checkout Authentication API ready, because you will need to authenticate Customers and pass the accessToken later to the Webcomponent.

Baskets

To proceed with the Checkout integration, you need to have a basket integrated.

Endpoint URLs

Below, we provide the URL to load our frontend JavaScript bundle for the Checkout. For backend-to-backend server requests, you will use a dedicated API hostname.

Frontend Bundle URL

https://{{tenant-space}}.checkout.api.scayle.cloud/frontend/checkout-wc/js?appId={{shop}}

API URL: https://{{tenant-space}}.checkout.api.scayle.cloud

Your SCAYLE Account Manager will provide you with the exact hostnames for your environments. How to use these is described in the corresponding sections of this manual.

CORS Settings

In order to allow requests from the embedded Webcomponent to the Checkout API, your shop hostnames will need to be added to the list of allowed CORS hosts.

See hosts configuration for more detailed information.

Frontend / Webcomponent

How to integrate the Checkout Webcomponent into your shop frontend

Loading the JavaScript bundle

Begin by either creating a static page or modifying the existing start page of your shop application. Then, insert the following JavaScript snippet into the head element to load the Checkout bundle.

<script
  src="https://${tenant-space}.checkout.api.scayle.cloud/frontend/checkout-wc/js?appId=${shopId}"
  defer
></script>

This script registers the Webcomponent with the browser and loads necessary assets (CSS, images).

Initialize the Webcomponent

To initialize and display the Webcomponent, add the <scayle-checkout> tag at a desired place where the content needs to appear. Any additional element like a header or footer must be defined in the root document.

Example code how to set up the Webcomponent:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width,initial-scale=1" />
  <title>Your shop title</title>
  <script
    src="https://${tenant-space}.checkout.api.scayle.cloud/frontend/checkout-wc/js?appId=${shopId}"
    defer>
  </script>
</head>
<body>
<div id="header">...</div>
...
<scayle-checkout jwt="${jwt}" access-token="${accessToken}" origin="web" header-element="#header"></scayle-checkout>
...
</body>
</html>

Attributes

jwtContains basketId, etc. as encoded and signed parameter. Find out how to generate the token here. More details about the JWT .required
access-tokenThe access token you receive after successful user authentication. Find out how to generate the token here.required
originDefines where the user is coming from, can be app or web. Passing the correct value is mandatory, otherwise users might encounter problems with e.g. payment processing.required
header-elementCSS selector pointing to the header element of the site (e.g. #header), used to display Checkout notifications with the correct top offset (under the header)required
has-cookie-consentContains the value of the user's cookie consent. Only enabled when the value resolves to 'true'. It unlocks in-depth error tracking, A/B testing, etc. We strongly recommend adding it to the Webcomponent and passing in the correct cookie consent value.required

Note: All these attributes need to be set on the Webcomponent from the very start. If you mount the component first and then set e.g. the basket-id attribute afterward, it will not be considered and not work correctly.

JWT attribute

To ensure integrity, you need to provide the jwt attribute containing an encoded JSON payload. The value of the jwt attribute has to be a common JWT (JSON web token) string. The payload of the JWT contains the properties likes basketId to initialize the checkout. The JWT is then signed with the shopSecret. Find the example here.

NameDescriptionType
issIdentifies the principal that issued the token. It is typically a unique identifier or URL of the service responsible for generating the token. The recipient of the token can use this field to verify the authenticity of the issuer. See example.optional
audIntended recipients of the token. It is used to ensure that the token is only accepted by the services or users that are authorized. The value is typically a unique identifier or URI representing the audience. See example.optional
iatissued at / current unix timestamprequired
nbfnot-valid-before unix timestampoptional
expexpiry unix timestamprequired
basketIdsets the current basket id of the active sessionrequired
rBasketIdsalted hash of basketId for rate-limiting purposesoptional
customDatasets order-level custom data, must be a JSON stringoptional
carriersets preferred Carrier Groupoptional
campaignKeyset an active campaign, so that corresponding price-reductions are displayed in the checkout cartoptional
preferredCollectionPointsets preferred collection point data as objectoptional
preferredCollectionPoint.idcollection point idoptional
preferredCollectionPoint.typecollection point type. e.g. dhl_packstationoptional
vouchersets an pre-applied voucher codeoptional

If you require a more advanced configuration of your JWT parameters, please view the documentation.

Tracking

Tracking events will be sent to the same Google Tag Manager (GTM) instance as the frontend application and the events will be attached to the same data layer object (window.dataLayer).

This section is important for the customers hosting their own storefront. For all other clients, this step is done by SCAYLE.

Your shop frontend is responsible for implementing the connection with the GTM (Google Tag Manager) and the corresponding data layer. It's crucial to ensure the correct data layer setup. To achieve this, insert the given code segment at the top of the page, just before initializing the checkout.

<script>
  window.dataLayer = window.dataLayer || [];
</script>

Add the following into your code to forward the events:

import { find } from 'lodash-es';

window.addEventListener('message', function receiveMessage(message) {
  const event = message.data.event;
  // avoid duplicate tracking of events
  if (message.data.type === 'tracking' && !find(window.dataLayer, event)) {
    // forward CHECKOUT tracking events to GTM
    window.dataLayer.push(event);
  }
}, false);

For more details and available events see the tracking overview.

Loading Indicator

You can optionally improve the UX for customers with slow internet connection by implementing a custom loading indication on the page that renders the checkout application, within the <body> tag.

SCAYLE does not provide a custom loading animation, so it's up to you to design and implement the loading-indicator. Below, we only show how a sample implementation could look like.

Example HTML Code:

<!DOCTYPE html>
<html>
 <head>
  <!--  all the resources your checkout rendering page needs -->
 </head>
 <body>
  <header id="sampleHeader"> <!-- A header id we pass to the 'header' attribute of scayle-checkout with # sign, in order to properly position notifications and modals -->
   <a href="#">Sample link</a>
  </header>
  <div class="sample-checkout-wrapper"> <!--Just an example container -->
   <!-- Your custom loading animation goes here -->
   <div class="loading-indicator" id="loading-indicator">...</div> <!-- Your custom loading indicator, you may want to add some css to showcase some animations -->
    <!-- Your custom loading animation ends here -->
   <scayle-checkout jwt="${jwt}" origin="web" header="#sampleHeader" style="display: none;"></scayle-checkout>
 </div>
 </body>
</html>

Example JS Code

The code below does two things:

  1. It listens for the load event emitted by the checkout application upon successful initialization, while also monitoring for the error event in case anything goes wrong during app bootstrap.
  2. It sets the display CSS property of both <scayle-checkout> and #loading-indicator elements to show the checkout and hide custom loading indicator.

The script below can be added at the bottom of your body tag:

<!DOCTYPE html>
<html>
 <head>
 
 </head>
 <body>
   <!--- All the HTHL described above, <scayle-checkout>, loading-indicator etc -->
   
   <!--- Start of the script -->
   <script>
    const loadingIndicator = document.getElementById('loading-indicator');
    const checkoutWebComponent = document.getElementsByTagName('scayle-checkout')[0];
    const onLoad = () => {
      loadingIndicator.style.display = 'none';
      checkoutWebComponent.style.display = 'block';
    };
    checkoutWebComponent.addEventListener('load', onLoad);
    checkoutWebComponent.addEventListener('error', () => {
      console.error('Checkout web  component is experiencing difficulties...');
      onLoad();
    });
   </script>
   <!--- End of the script -->
 </body>
</html>

Webcomponent methods

The Checkout Webcomponent provides a method to update the used basket ID (string) via setBasketId:

const checkoutWebComponent = document.getElementsByTagName('scayle-checkout')[0];
// Update the basket ID of the current Webcomponent instance
checkoutWebComponent.setBasketId('${newBasketId}');

Webcomponent events

The Checkout Webcomponent can notify the parent shop frontend about specific events or user actions. Your application can subscribe to these events by adding a listener, as shown in the below example:

const checkoutWebComponent = document.getElementsByTagName('scayle-checkout')[0];

checkoutWebComponent.addEventListener('authenticate', e => {
  // evt.detail property contains payload data
  // Use it to provide feedback to users, update app state
...
});

The event listener needs to be added within the page where you load your Checkout bundle.

You can find the event details in the table below. The list of event types may be extended in the future.

Event NameDescriptionTrigger
loadUse this if you want to show your own loading indicator until the component is readyCheckout has loaded all data for initial render
errorAn error state will be rendered by the Webcomponent. The load event will not be triggered in this caseCheckout has loaded all data for initial render, but there was an unrecoverable error
intentConfirmationCustomer has made the decision to buy / intents to confirm the orderCustomer clicks the "Pay Now" button
authenticateDeprecated This event is fired to inform the shop frontend that a user has logged in or registered during checkoutUser logs in or signs up via Checkout
Example/default
Checkout/checkout
Order Success Page (OSP)/order/success
Example URLhttps://<shopName.domain>/order/success?cbd=<base64EncodedToken>