PROD Locker Plugin SDK integration


Step 1

Include locker plugin sdk js file into the body tag of your html
<script src="https://cdn.sameday.ro/locker-plugin/lockerpluginsdk.js"></script>

Step 2

Initialize with following parameters and get plugin instance from LockerPlugin object attached on window

Parameter Type Default value Supported values
clientId *required string N\A N\A
countryCode string, ISO-3166 standard "RO" "RO", "HU", "BG"
langCode string, ISO-639 standard "en" "en", "ro", "hu", "bg"
city string country capital city name of supported countries
county string country capital county name of supported countries
favLockerId
(see Optional advanced features - favorite locker)
number, integer format N\A any lockerId
favType
(see Optional advanced features - favorite locker)
number, integer format 0 0 = locker, 1 = pudo
theme string system default theme of the device "light", "dark"
apiUsername*required string N\A any integrator LM username
filters JSON array [
  {"showLockers": true}
  {"showPudos": true}
]
[
  {"showLockers": <boolean value>}
  {"showPudos": <boolean value>}
]
initialMapCenter string N\A "City", "County"

const clientId="11d773d6-5a44-4c48-8e69-72590241bb4b";//each integrator will have an unique clientId const countryCode="RO";//country for which the plugin is used const langCode="ro";//language of the plugin const city="Craiova";//User's default city to be displayed at start const county="Dolj";//User's default county to be displayed at start const favLockerId=143;//User's favorite delivery point which will be pre-selected at start. If favourite delivery point exists, city and county will be negligible. const favType=0;//User's favorite delivery point type, 0 for lockers and 1 for pudos. const theme="light";//theme of the plugin: light, dark const apiUsername="myLmUsername";//integrator LM Username const filters=[{"showLockers": true},{"showPudos": true}];//default filters for lockers const initialMapCenter="City";//Where the map will be initially centered. Leave undefined to center on the user's favorite delivery point, if it exists. window.LockerPlugin.init({   clientId: clientId,
  countryCode: countryCode,
  langCode: langCode,
  city: city,
  county: county,
  favLockerId: favLockerId,
  favType: favType,
  theme: theme
  apiUsername: apiUsername
  filters: filters
  initialMapCenter: initialMapCenter
});
var pluginInstance = window.LockerPlugin.getInstance();
Info: Multiple calls for either init() or getInstance() function won't affect the flow since LockerPlugin is implemented as singleton and will always return the same instance

Step 3

Use subscribe, open and close plugin functions
//myCustomFunction is your callback function to be executed when locker plugin pushes a post message with selected locker pluginInstance.subscribe(myCustomFunction);
//display the modal iframe window pluginInstance.open();

Below is just an example of myCustomFunction implementation, but you can do whatever you want in callback function function myCustomFunction(msg)
{
console.log("I received this msg from locker plugin:", msg); //I received this msg from locker plugin: {"lockerId":1413,"oohType":0,"name":"easybox Grozavesti","address":"str. Slt. Alexandru Borneanu nr. 20C","cityId":6,"city":"Sectorul 6","countyId":1,"county":"Bucuresti","postalCode":"061079"}
//close the modal iframe window pluginInstance.close(); }

Reinitialize Plugin Reinitialize the Locker Plugin with different options
If you need to change any of the options that you first started the plugin with, you can use the reinitializePlugin method to do so. pluginInstance.reinitializePlugin({   clientId: clientId,
  countryCode: countryCode,
  langCode: langCode,
  city: city,
  county: county,
  favLockerId: favLockerId,
  favType: favType,
  theme: theme
  apiUsername: apiUsername
  filters: filters
  initialMapCenter: initialMapCenter
});
//optionally, you can also open the plugin right after reinitialization pluginInstance.open();
Favorite Locker: Get user's favorite delivery point id and type by subscribing to subscribeToFavouriteLocker method
! Precondition: Announce sameday in advance in order to enable this feature for your clientId, otherwise it won't work //myCustomFunction2 is your callback function to be executed when locker plugin pushes a post message with new user's favorite locker action details pluginInstance.subscribeToFavouriteLocker(myCustomFunction2);
//myCustomFunction2 example: function myCustomFunction2(favLockerMsg)
{
console.log("I received this msg about fav locker:", favLockerMsg); //I received this msg about fav locker: {lockerId: 199, type: 0} //If user removed his favorite locker, then received msg is: {} }