Synchronisation

Version: v2.0

Whenever a customer changes their information in their ShopLogin account, synchronisation should take place between WebshopLogin and the webshop the user is logging into. There are 2 ways to check if a customer has updated their data which are:

  1. webshoplogin.user.isSync in Javascript when the user clicks the webshoplogin-loginbutton.
  2. By comparing the versions of user, customer and all address versions. after the webshop has recieved the users data.

1. If webshoplogin.user.isSync == false you should perform a synchronisation. Since it is not known which data is unsynchronised the versions should still be compared and updated accordingly.

2. Whenever you retrieve the userdata you should compare the saved versions with the retrieved versions. This process works the same as option 1. with the difference being that webshoplogin.user.isSync is not checked.


The userdata, which is retrieved by calling Get user, will consist of a User object. This user object contains a user version, customer version and a version for every address. When you create a new account for a user, you should store these versions at the shop. Whenever you retrieve the user object, you should compare their versions with the stored versions.


In order to synchronise you need to retrieve an accesstoken by setting an eventlistener to the event "getAccesstokenResponse" and calling webshoplogin.accesstoken(). From there you can send the accesstoken to the synchronisation endpoint of the shop. Where you can retrieve the userdata and compare the versions. If a version of the retrieved userdata is higher than the stored data the customer should be updated.

Note: when synchronising on the checkout page make sure you show the loader. This way the customer knows their data is being synchronised.
<script>
document.addEventListener("getAccesstokenResponse", function(event) {
     synchronise(event.detail.accesstoken);
}, false);
</script>