Plugin Settings

In this article:

  • ISettingsService GetSettingsService()

All plugins need to have settings and they differ from each other. Because they are all specific for their own purpose, LS Pay includes a settings mechanism that can store and manage different settings for each plugin, the ISettingsService GetSettingsService().

To start accessing and updating settings for the selected plugin, call the function GetSettingService in the EAManagement object. This returns the setting service which has the following interface:

Copy
public interface ISettingsService
{
  void AddSetting(Setting setting);
  List<Setting> GetAllSettings();
  bool UpdateValue(SettingType key, object value);
  string GetValueString(SettingType key);
  bool GetValueBool(SettingType key);
  int GetValueInt(SettingType key);
  ConnectionType GetValueConnectionType(SettingType key);
}

The GetAllSettings() function returns a list of all the settings the plugin needs. Use this list to create an interface where a user can update these settings as a part of commissioning the POS solution. The Settings object has some variables in it that you can use to populate the setting interface.

Copy
public readonly SettingType Key;
public readonly string Description;
public readonly object DefaultValue;
public readonly DataType Type;
public readonly bool Required;
public readonly Func<object, bool> VerifyValue;
public readonly bool SensitiveData;
public readonly bool IsReadOnly;

Settings are identified by the Key parameter, an enum type provided in the ExternalAccessoryManagement namespace of LS Pay. An example of how to update a value for a given key:

Copy
ss.UpdateValue(SettingType.IPAdress, "127.0.0.1");

Note: In this example the key and value are hardcoded, the key should be fetched from the setting list and the value from an entry filed in the GUI.

When settings are updated, the plugin verifies the new value and will throw an argument exception if the new value is not acceptable for the field.

If the field is SensitiveData, it is up to the client to store the information.
Note:  Do not store as plain text or have it easily accessible by a normal user in the POS system or through a web browser code.
This refers to fields like API keys or passwords (credentials).
Note: It is up to the user (service/POS) to take care of the information.

An example of handling settings:

Copy
private static void InitSettings()
{
  // Get the Setting service so you can change the values. 
  // This list of settings is usually shown in the UI and filled in by them.
  var ss = eam.GetSettingsService();
  var settings = ss.GetAllSettings();

  System.Console.WriteLine("List of available settings for the plugin: ");
  foreach(var setting in settings)
  {
    System.Console.WriteLine("\t" + setting.Key.ToString() + " : " + setting.Value + " - " + setting.Description);
  }
  System.Console.WriteLine("");


  if(psp == ExternalAccessoryType.Mock)
  {
    // Example of how to update setting (Note! don't hardcode setting key)
    ss.UpdateValue(SettingType.UserFieldOnReceipt, "43");
  }
  else if(psp == ExternalAccessoryType.VerifonePoint)
  {
    // change encription and ip
    // Can't change encryption setting when already paired with device."
    if (!eam.IsPairedAsync().Result)
    {
      ss.UpdateValue(SettingType.IPAdress, "127.0.0.1");
      ss.UpdateValue(SettingType.UseEncryption, false);
      System.Console.WriteLine("-----------------");
      try
      {
        ss.UpdateValue(SettingType.ReceiptLineWidth, 20);
      }
      catch(Exception e)
      {
        System.Console.WriteLine("Exception: " + e.Message);
      }
      System.Console.WriteLine("-----------------");
    }
  }
}

When updating or changing settings, the class may throw a SettingException. The exception includes an error code as an enum, so it can be localized and forwarded to the UI.

Copy
public enum SettingErrorCode
{
InvalidKey,
DataTypeMismatch
}