Checkout 3.0
Customer Token

Customer Token

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

Handling the Customer Token

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 time. However, there are cases where this is not desirable. For example, when 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.

Storing the token when it's issued

Token is stored by default in the browser localStorage under a key __avarda-checkout--customerToken__. If you don't want to handle the token manually, you can leave the handling to Checkout Form and the token will be picked up and used automatically. If you wish to store the token in a different place, e.g. database, you can register an optional callback when embedding Checkout Form.

Register an optional callback setCustomerTokenCallback when calling window.avardaCheckoutInit():

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

When the customer confirms the purchase and checks "remember me" checkbox the customer token will be stored in localStorage and also passed in as a first argument to the setCustomerTokenCallback() function.

Pass the token manually to window.avardaCheckoutInit()

Customer Token that is stored in browser localStorage will be passed to Checkout automatically, you may pass the previously stored Customer token during checkout initialization like this:

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

Clearing the Checkout Token

To clear the browser-stored token on the page that contains Checkout Form you can call clearCustomerToken(), which is available on Checkout Instance:

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

In case you want to cleanup and remove Customer token (e.g. when user signed out) on a page where Checkout Instance is not available, you may clear the token directly from the localStorage by using the following command:

localStorage.removeItem('__avarda-checkout--customerToken__');

Removing the customer token using window.avardaCheckout.clearCustomerToken(); or directly from localStorage only clears the Customer Token stored in the browser, if you want to completely forget the customer, make sure you also remove the Customer Token that you've previously stored in any other place (e.g. database).