Checkout 3.0
Customer Token

Customer Token

What is customer token?

When a customer selects “remember me” checkbox during the checkout, a token is issued, later used to identify the user and prefill their data automatically in a subsequent checkout.

Why would I care?

For convenience, the flow is handled for you, but in some cases, you may want to handle the token yourself to override the default behavior.

By default, the token is stored within the browser between checkouts, which works well most of the times. However, there are cases where this is not desirable: for example, a user signs out from your platform to let a different person make a purchase on the same computer, but the token issued for the first user is still in the browser, which results in mismatched data being prefilled for the second one.

So what can I do?

You may simply clear the browser-stored token when the user signs out:

<script>
  window.avardaCheckout.clearCustomerToken();
</script>

Additionally, you may pass the right token during checkout initialization like this:

<script>
  window.avardaCheckoutInit({
    ...
    customerToken: "6cb4af7a-eec2-410f-bda4-58ee248b2f2a",
    ...
  });
</script>

This of course assumes you have stored the token during a previous checkout, using a callback:

<script>
  window.avardaCheckoutInit({
    ...
    setCustomerTokenCallback: function(customerToken) {
      // This function is called once the customerToken is ready,
      // so you can store it in your database.
    },
    ...
  });
</script>