Consolidated Checkout - Callbacks

Callback functions for the consolidated checkout

The Porterbuddy Consolidated Checkout provides callback function references to trigger actions in the widget from external sources. To access the callback function references, a function is defined for the configuration option "onSetCallbacks". This function gets called by the widget after initialization, the argument passed is an object containing references to the callback functions. These references can be stored and used to trigger actions in the widget from external sources.

Available callback functions

Function Description
forceRefresh() Refreshes the consolidated checkout with the currently specified values from the window.porterbuddy variable.
setRecipientInfo(recipientInfo: RecipientInfo) Sets the recipient info in the consolidated checkout to the specified value.
refreshShippingOptions() Refreshes the shipping options with the values currently specified in window.porterbuddy. Only the 3 arrays specifying the shipping options are read from the configuration object, all other properties will remain unchanged.

Example

Entered PostCode

Callback Triggers

Configuration

In this example, the refresh function is exposed as window.refresh, in consequence, calling window.refresh within the page will refresh the whole checkout.

<script>
  window.porterbuddy = {
    homeDeliveryOptions: [],
    pickupPointOptions: [],
    storeOptions: [],
    now: '2019-03-14T12:30:00+01:00',
    onPostCodeEntered: function (postCode) {
      document.getElementById('postCodeData').value = postCode;
      window.porterbuddy.homeDeliveryOptions = homeOptions;
      window.porterbuddy.storeOptions = storeOptions;
      window.porterbuddy.pickupPointOptions = pickupOptions;
      window.setRecipientInfo({
        postCode: postCode,
        email: 'test.d.testensen@porterbuddy.com',
      });
      window.refreshShippingOptions();
    },
    onSetCallbacks: function(callbacks) {
      window.refresh = callbacks.forceRefresh;
      window.setRecipientInfo = callbacks.setRecipientInfo;
      window.refreshShippingOptions = callbacks.refreshShippingOptions;
    }
  }
</script>