To set up Customer Authentication, please follow the steps given below:


1. Login to Merchant Center.
2. Click Loyalty tab.
3. In Loyalty tab, click Dashboard Config tab. Refer to Figure: Dashboard Config.

Figure: Dashboard Config


There are three types of customer authentications:
  • ShopSocially Authentication: The ShopSocially Authentication gives users options of logging in via Facebook, Google, or Yahoo. This login will be separate from your website login and users who have already been authenticated to their website accounts will still have to log in again here. To set up ShopSocially Authentication, please follow steps given below:
1. In Authentication Options, in Authentication Type, from drop down, select ShopSocially Authentication. Refer to Figure: ShopSocially Authentication.
2. Contact your Customer Success Manager. ShopSocially will configure these values.
3. When values are configured, click Save.


Refer to Figure: ShopSocially Authentication



This option requires some programming at your end. But once implemented, your customers can avoid the hassles of logging in separately to your website and ShopSocially’s loyalty dashboard. Base64 Authentication is based on front end JavaScript. With this the merchant needs to pass the user details to ShopSocially, for to log in the user into ShopSocially Loyalty Program. 

You will need to call our JavaScript public API method:

ss_mi.authenticate_loyalty_user(user_info), where user_info must be a JavaScript object like,

{
    "first_name": "Akshay",
    "last_name": "Deshmukh",
    "email": "akshayd@shopsocially.com",
    "uid": "12jlkd1k2lksdsdls"
}
This API call has to be made on window load to avoid calling our API before the loyalty js has loaded.
For e.g. in jQuery -
$(window).load(function() {
ss_mi.authenticate_loyalty_user(user_info);
});

This JavaScript has success and failure handlers as mentioned below:

  • window.ssmi_authenticate_loyalty_user_success_handler() 
  • window.ssmi_authenticate_loyalty_user_failure_handler(resp)

The default success handler will redirect the user to the Loyalty Dashboard (User Dashboard URL set in the merchant center configuration), whereas the failure handler will return a json object like:

{
"success" : "false"
}
To set up Base64 Authentication, please follow steps given below:

1. In Authentication Options, in Authentication Type, from drop down, select Base64 Authentication. Refer to Figure: Base64 Authentication.

2. In Loyalty Authentication URL, enter URL of the intermediate page where the API call is made, and the user info is passed to ShopSocially to authenticate and sign the customer in to the Loyalty program. You may insert a URL parameter in the loyalty authentication URL field for tracking purpose. Advantage of doing this is explained in the use cases section of this document.

3. Click Save.

Figure: Base64 Authentication



In the token based authentication, the customer data for authentication is exchanged through a server side call and hence this method is more secure. This requires additional programming at your end to generate a token for every user that logs in, and associate that token with the user in your back end. The token number will be passed to ShopSocially through the JavaScript API call. ShopSocially will hit your server with a request for customer data and pass the token number in the request. After the customer data is retrieved, the user will be logged in to the Loyalty program.

For authenticating a customer, use the following JavaScript API:

ss_mi.authenticate_loyalty_user(user_info), where user_info will be a JavaScript object as follows:

{
   "access_token" : "6788kahfk89ajlf"
}
ShopSocially will use this token and hit your server on the User endpoint URL provided. You will verify the token and pass the user information in the response. The response should be a json object with following structure.
{
    "first_name": "Akshay",
    "last_name": "Deshmukh",
    "email": "akshayd@shopsocially.com",
    "uid": "12jlkd1k2lksdsdls"
}

This JavaScript has success and failure handlers as mentioned below:
  • window.ssmi_authenticate_loyalty_user_success_handler() 
  • window.ssmi_authenticate_loyalty_user_failure_handler(resp)
The default success handler will redirect the user to the Loyalty Dashboard (User Dashboard URL set in the App configuration), whereas the failure handler will return a json object like:
{
"success" : "false"
}
To set up Token Based Authentication, please follow steps given below:
1. In Authentication Options, in Authentication Type, from drop down, select Token Based Authentication. Refer to Figure: Token Based Authentication. 
2. In User Endpoint enter URL of your server which ShopSocially will hit with the token number to retrieve the customer information. You need to validate the token and pass the customer information to ShopSocially in the response.
3. In Loyalty Authentication URL, enter the URL of the page where the API call is made and the user info or token number is passed to ShopSocially to authenticate and sign the customer in to the Loyalty Dashboard. You may insert a URL parameter in the loyalty authentication URL for tracking purpose. Advantage of doing this is explained in the use cases section of this document.
4. Click Save.

Figure: Token Based Authentication


Logout Function:

The default loyalty dashboard seen by customers has a logout button available. However using this button may create scenarios where the customer only logs out of the loyalty program and not out of the website. To avoid this, you can disable the logout button in the dashboard and use the logout API to deal with this instead. In Loyalty in Loyalty Config, in Authentication Options, clear check box 'Show Logout Button'. Refer to Figure: Show Logout Button.

 

Figure: Show Logout Button

Call the following JavaScript API to log a user out of the loyalty program. 
ss_mi.logout_loyalty_user();
This JavaScript API will have success and failure handlers:
window.ssmi_logout_loyalty_user_success_handler = function(); {
//write the logout success handling code here
} 
If a success handler is not implemented, the user will be redirected to the home page of the merchant site.
 window.ssmi_logout_loyalty_user_failure_handler = function(); {
//write the logout failure handling code here
} 
If a failure handler is not implemented, in the event of failure ShopSocially will send an alert with the message 'Error occurred while logging out'


Below is JavaScript function to fetch user data in the front end. This function is to be called only when a user is logged in.

Call the following JavaScript API function to get information about the loyalty user currently logged in.
ss_mi.get_loyalty_user_info()
You will need to implement success handler for this JavaScript API to get the loyalty user information in the following way:
window.ssmi_loyalty_user_info_success_handler = function(resp){
//resp has two fields - data, and success.
//success will be true in the success handler.
//data consists of information about the logged in loyalty user

And the format of the data object is follows:

{
 "data":{
 "user_id":<SS User ID>,
 "user_email":<User Email>,
 "first_name":<User First Name>,
 "last_name":<User Last Name>,
 “gender”:<Gender>,
 "profile_image_url":<Profile Image url>,
 "redeemed_points":<Redeemed Points>,
 "available_points":<Available Points>,
 "loyalty_level_id":"platinum",
 "loyalty_lifetime_level_id":"platinum_lifetime",
 "user_language":<User Language>,
 "user_status":<User Status>
 "expiration_schedule": [{"expiration_date": "07-Jan-2016 23:59:59","points": 34226}],
 "last_award_transaction": {"date": "07-Dec-2015 13:23:35","points": 300,"name": "Became a Twitter Follower"}
}

Expiration schedule will be an array of objects. In case of inactivity based expiration this array will contain only one object with keys – ‘expiration date’ and ‘points’ expiring on that date.