Appendix A - Data types

In the code sample below you will find all the data types along with a description that are necessary for your POS Buddy implementation

/// Status of the websocket connection
public enum PbStatus
{
    /// The status when the websocket connection is connected.
    Connected = 1,
    /// The status when the websocket connection gets disconnected.
    Disconnected = 2,
    /// The status when errors happen with the websocket connection.
    Error = 3
}

/// Provides a definition for the different types of log messages the client can forward via the log callback.
public enum PbLogType
{
    /// The log type for info messages.
    Info = 1,
    /// The log type for warning messages.
    Warning = 2,
    /// The log type message for when we transmit data.
    TransmitData = 3,
    /// The log type message for when we receive data.
    ReceiveData = 4,
    /// The log type for any errors which occur.
    Error = 5   
}

/// Return values for POS Buddy functions
public enum PbResult
{
    /// Result went everything is OK
    RESULT_OK = 0,
    /// Result for any unsupported actions or parameters
    NOT_SUPPORTED = -1000,
    /// Result for any missing required parameters
    MISSING_PARAMETERS = -1001,
    /// Result for any errors parsing the JSON
    PARSE_JSON_ERROR = -1002,
    /// Result when no response was received
    NO_RESPONSE = -1003,
    /// Result when there is a comms error
    COMMS_ERROR = -1004,
    /// Result when an invalid response is received
    INVALID_RESPONSE = -1005,
    /// Result when authentication has not been performed or authentication key is not populated
    AUTH_ERROR = -1006,
    /// Result When calling do sale but an existing sale is still in progress
    SALE_IN_PROGRESS = -1007,
    /// Result when there is a comms issue on the server
    SERVER_COMMS_ERROR = -1008,
    /// Result when comms has not been initialised
    COMMS_NOT_INITIALISED = -2000,
    /// Result when there is an error opening the websocket
    ERROR_OPENING_WEBSOCKET = -2002
}

/// Status of the POS Buddy device
public enum PbDeviceStatus
{
    /// The device is available for use
    Available = 1,
    /// The device is currently connected to a POS and needs to be disconnected before it becomes available
    Connected = 2,
}

Appendix B: Example Implementation


using Ecentric.PosBuddyClient;
using Ecentric.PosBuddyClient.Enums;
using Ecentric.PosBuddyClient.DTOs;

namespace PosBuddyExampleClient
{
    internal class Program
    {
        static PosBuddy PosBuddyClient;
        static bool IsPosBuddyConnected = false;
        static bool IsPosBuddyAuthenticated = false;

        static void Main()
        {
            PosBuddyClient = new PosBuddy((logType, message) =>
            {
                Console.WriteLine($"LogCallback {logType}, Message: {message}");
            });

            PosBuddyClient.SetMerchantId("000000123456");
            PosBuddyClient.SetPosId("0001");

            // Connect to PosBuddy device before interacting with it
            PosBuddyClient.Connect("111222", (status) =>
            {
                // Callback to process Connect result

                switch (status)
                {
                    case PbStatus.Connected:
                        Console.WriteLine($"Status Callback: Connection success.");
                        IsPosBuddyConnected = true;
                        break;
                    case PbStatus.Disconnected:
                        Console.WriteLine($"Status Callback: Connection Disconnected.");
                        IsPosBuddyConnected = false;
                        break;
                    case PbStatus.Error:
                        Console.WriteLine($"Status Callback: Connection Error.");
                        IsPosBuddyConnected = false;
                        break;
                }
            });

            if (IsPosBuddyConnected)
            {
                string? authResult = null;

                // Use provided secret and access keys for DoPosAuth
                PosBuddyClient.DoPosAuth("secretKey", "accessKey", (result) =>
                {
                    // Callback to process DoPosAuth result

                    // Set received authKey before transacting
                    authResult = result["resultDescription"] as string;
                    if (authResult == "COMPLETED" || authResult == "SUCCESS")
                    {
                        var authKey = result["authenticationKey"] as string;
                        PosBuddyClient.SetAuthenticationKey(authKey!);
                        IsPosBuddyAuthenticated = true;
                    }
                });

                // Wait for DoPosAuth to complete before proceeding
                while (authResult == null) ;                

                // PosBuddy device needs to be authenticated before DoSale call
                if (IsPosBuddyAuthenticated)
                {
                    // Do a sale for R10.00
                    PosBuddyClient.DoSale(1000, new Dictionary<string, string>(), (result) =>
                    {
                        Console.WriteLine($"DoSale callback called. Result: {result}");
                    });
                }
            }
        }
    }    
}