SDK Functions Code Sample

This guide will provide you with guidance on various code samples that you can use to enable various functions that we have in our Windows SDK.

Prerequisites

Please make sure that you provide set the following code before enabling the feature:

var rms = new SmartBridge.Api(txtClientID.Text, txtSecret.Text, txtReturnUrl.Text, txtBaseUrl.Text, txtoAuthUrl.Text);

Some features may require you to set the Callback URL, token, or RefreshToken. For the details, please refer to the sample code within various features below.

📘

Note:

If you don't have the callback URL, please use the callback URL that is within your server or use https://oauth.pstmn.io/v1/browser-callback as the callback URL.

1. Authentication

You should start with the authentication first when you use our Windows SDK. There are log in and log out functions within authentication. The IEbrowserFix() function is an optional function in case you find an issue with the authentication.

1.1 Log in

Code sample:

private void IEbrowserFix()
        {
            try
            {
                Microsoft.Win32.RegistryKey regDM;
                bool is64 = Environment.Is64BitOperatingSystem;
                string KeyPath = "";
                if (is64)
                {
                    KeyPath = @"SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION";
                }
                else
                {
                    KeyPath = @"SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION";
                }

                regDM = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(KeyPath, false);
                if (regDM is null)
                {
                    regDM = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(KeyPath);
                }

                Microsoft.Win32.RegistryKey Sleutel;
                if (regDM is object)
                {
                    string location = Environment.GetCommandLineArgs()[0];
                    string appName = Path.GetFileName(location);
                    Sleutel = (Microsoft.Win32.RegistryKey)regDM.GetValue(appName);
                    if (Sleutel is null)
                    {
                        // Sleutel onbekend
                        regDM = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(KeyPath, true);
                        Sleutel = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(KeyPath, Microsoft.Win32.RegistryKeyPermissionCheck.ReadWriteSubTree);

                        // What OS are we using
                        var OsVersion = Environment.OSVersion.Version;
                        if (OsVersion.Major == 6 & OsVersion.Minor == 1)
                        {
                            // WIN 7
                             Sleutel.SetValue(appName, 9000, Microsoft.Win32.RegistryValueKind.DWord);
                        }
                        else if (OsVersion.Major == 6 & OsVersion.Minor == 2)
                        {
                            // WIN 8 and above
                            Sleutel.SetValue(appName, 10000, Microsoft.Win32.RegistryValueKind.DWord);
                        }
                        else if (OsVersion.Major == 5 & OsVersion.Minor == 1)
                        {
                            // WIN xp
                            Sleutel.SetValue(appName, 8000, Microsoft.Win32.RegistryValueKind.DWord);
                        }

                        Sleutel.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\nYou need to run as Administrator to alter the registry");
            }
        }

private void cmdGetAccessToken_Click(object sender, EventArgs e)
        {
            //If you receive script errors on login then call this 
           // IEbrowserFix();
            var rms = new SmartBridge.Api(txtClientID.Text, txtSecret.Text,  txtReturnUrl.Text,txtBaseUrl.Text,       txtoAuthUrl.Text);
          
            Properties.Settings.Default.Save();
            string url = rms.getoAuthUrl();
            var frm = new frmlogin();
            frm.webBrowser1.Navigate(url);
            frm.ShowDialog();
            string code = (string)frm.Tag;
            frm.Close();
            frm = default;
            if (string.IsNullOrEmpty(code))
                return;
            try
            {
                JObject resp = (JObject)rms.GetToken(code);
                txtaccess.Text = (string)resp["access_token"];
                txtRefresh.Text = (string)resp["refresh_token"];
                MessageBox.Show("Login Successfull");
                Properties.Settings.Default.Save();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

1.2 Log out

🚧

Important:

If you use the logout function, the RefreshToken is no longer valid, you need to login back in to get a new RefreshToken.

Code sample:

private void cmdLogout_Click(object sender, EventArgs e)
        {
            //If you receive script errors on login then call this 
            // IEbrowserFix();
            var rms = new SmartBridge.Api(txtClientID.Text, txtSecret.Text, txtReturnUrl.Text, txtBaseUrl.Text, txtoAuthUrl.Text);

            Properties.Settings.Default.Save();
            string url = rms.getLogoutUrl();
            var frm = new frmlogin();
            frm.webBrowser1.Navigate(url);
            frm.ShowDialog();
            string code = (string)frm.Tag;
            frm.Close();
            frm = default;
            if (string.IsNullOrEmpty(code))
                return;
            try
            {
                JObject resp = (JObject)rms.GetToken(code);
                txtaccess.Text = (string)resp["access_token"];
                txtRefresh.Text = (string)resp["refresh_token"];
                MessageBox.Show("Login Successfull");
                Properties.Settings.Default.Save();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

2. Select the terminal

To enable terminal selection feature, please refer to the code sample below.

Code sample:

private void cmdSelectTerminal_Click(object sender, EventArgs e)
       {
            var rms = new SmartBridge.Api(txtClientID.Text, txtSecret.Text, txtReturnUrl.Text, txtBaseUrl.Text, txtoAuthUrl.Text);

            rms.setToken(txtaccess.Text);
            rms.setRefreshToken(txtRefresh.Text);
            object terminals;
            lvTerminals.Items.Clear();
            try
            {
                terminals = rms.GetTerminalList();
                lblOutput.Text = terminals.ToString();
                foreach (JObject terminal in (IEnumerable)terminals)
                {
                    var li = new ListViewItem();
                    li.Text = terminal["terminalId"].ToString();
                    li.SubItems.Add((terminal["terminalName"] is null) ? terminal["terminalId"].ToString() : terminal["terminalName"].ToString());
                    li.SubItems.Add(terminal["terminalStatus"].ToString());
                    lvTerminals.Items.Add(li);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

3. Initiate a sale

To enable sale initiation feature, please refer to the code sample below.

Code sample:

private void cmdSaleInitiation_Click(object sender, EventArgs e)
        {
            var rms = new SmartBridge.Api(txtClientID.Text, txtSecret.Text, txtReturnUrl.Text, txtBaseUrl.Text, txtoAuthUrl.Text);

            rms.setToken(txtaccess.Text);
            rms.setRefreshToken(txtRefresh.Text);
            rms.SetActiveTerminal(txtTerminalId.Text);
            JObject resp;
            try
            {
                resp = (JObject)rms.CreateTransaction(2400, "GBP", "SALE");
                lblOutput.Text = resp.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            string transactionid = resp["transactionid"].ToString();
            cmdCheckStatus.Tag = transactionid;
            MessageBox.Show("Transaction " + transactionid + " successfull \r\nCheck Status for approval");
        }

4. Initiate a refund

To enable refund initiation feature, please refer to the code sample below.

Code sample:

private void cmdRefundInitiation_Click(object sender, EventArgs e)
       {
            var rms = new SmartBridge.Api(txtClientID.Text, txtSecret.Text, txtReturnUrl.Text, txtBaseUrl.Text, txtoAuthUrl.Text);

            rms.setToken(txtaccess.Text);
            rms.setRefreshToken(txtRefresh.Text);
            rms.SetActiveTerminal(txtTerminalId.Text);
            JObject resp;
            try
            {
                resp = (JObject)rms.CreateTransaction(2400, "GBP", "REFUND");
                lblOutput.Text = resp.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            string transactionid = resp["transactionid"].ToString();
            cmdCheckStatus.Tag = transactionid;
            MessageBox.Show("REFUND Transaction " + transactionid + " successfull \r\nCheck Status for approval");
        }

5. Cancel a transaction via terminal

To enable transaction cancellation feature via terminal, please refer to the code sample below.

Code sample:

private void cmdTerminalCancellation_Click(object sender, EventArgs e)
        {
            var rms = new SmartBridge.Api(txtClientID.Text, txtSecret.Text, txtReturnUrl.Text, txtBaseUrl.Text, txtoAuthUrl.Text);

            rms.setToken(txtaccess.Text);
            rms.setRefreshToken(txtRefresh.Text);
            rms.SetActiveTerminal(txtTerminalId.Text);
            JObject resp;
            try
            {
                resp = (JObject)rms.CreateTransaction(2400, "GBP", "SALE");
                lblOutput.Text = resp.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            string transactionid = resp["transactionid"].ToString();
            cmdCheckStatus.Tag = transactionid;
            MessageBox.Show("Transaction " + transactionid + " successfull \r\nPlease press cancel on the terminal");
        }

6. Cancel a transaction via EPOS

To enable transaction cancellation feature via EPOS, please refer to the code sample below.

Code sample:

private void cmdTransactionCancellationEPOS(object sender, EventArgs e)
        {
            var rms = new SmartBridge.Api(txtClientID.Text, txtSecret.Text, txtReturnUrl.Text, txtBaseUrl.Text, txtoAuthUrl.Text);

            rms.setToken(txtaccess.Text);
            rms.setRefreshToken(txtRefresh.Text);
            rms.SetActiveTerminal(txtTerminalId.Text);
            JObject resp;
            try
            {
                resp = (JObject)rms.CreateTransaction(2400, "GBP", "SALE");
                lblOutput.Text = resp.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            string transactionid = resp["transactionid"].ToString();
            MessageBox.Show("Transaction " + transactionid + " created ");
            try
            {
                resp= (JObject)rms.CancelTransaction(transactionid);
                lblOutput.Text += resp.ToString();

            }
            catch (Exception ex) { }
          
            cmdCheckStatus.Tag = transactionid;
            MessageBox.Show("Transaction " + transactionid + "  canceled");
        }

7. Execute cashback via EPOS till

To enable the cashback feature, please refer the code sample below.

private void cmdCashback_Click(object sender, EventArgs e)
        {
            var rms = new SmartBridge.Api(txtClientID.Text, txtSecret.Text, txtReturnUrl.Text, txtBaseUrl.Text, txtoAuthUrl.Text);

            rms.setToken(txtaccess.Text);
            rms.setRefreshToken(txtRefresh.Text);
            rms.SetActiveTerminal(txtTerminalId.Text);
            JObject resp;
            try
            {
                resp = (JObject)rms.CreateTransaction(2400, "GBP", "SALE",2000);
                lblOutput.Text = resp.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            string transactionid = resp["transactionid"].ToString();
            cmdCheckStatus.Tag = transactionid;
            MessageBox.Show("Transaction  for 24 GBP and 20 GBP cashback :" + transactionid + " successfull \r\nCheck Status for approval");
        }

8. List/filter the transactions

You can list/filter the transactions by status, type, and transaction ID via EPOS.

8.1 List/filter the transactions by status

To enable transaction filter feature by status, please refer to the code sample below.

Code sample:

private void cmdFilterByStatus_Click(object sender, EventArgs e)
        {
            var rms = new SmartBridge.Api(txtClientID.Text, txtSecret.Text, txtReturnUrl.Text, txtBaseUrl.Text, txtoAuthUrl.Text);

            rms.setToken(txtaccess.Text);
            rms.setRefreshToken(txtRefresh.Text);
            rms.SetActiveTerminal(txtTerminalId.Text);
            JObject resp;
            try
            {
                resp = (JObject)rms.GetTransactionsByStatus("SUCCESSFUL");
                lblOutput.Text = resp.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }

8.2 List/filter the transactions by type

To enable transaction filter feature by type, please refer to the code sample below.

Code sample:

private void cmdFilterByType_Click(object sender, EventArgs e)
        {
            var rms = new SmartBridge.Api(txtClientID.Text, txtSecret.Text, txtReturnUrl.Text, txtBaseUrl.Text, txtoAuthUrl.Text);

            rms.setToken(txtaccess.Text);
            rms.setRefreshToken(txtRefresh.Text);
            rms.SetActiveTerminal(txtTerminalId.Text);
            JObject resp;
            try
            {
                resp = (JObject)rms.GetTransactionsByType("SALE");
                lblOutput.Text = resp.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }

8.3 List/filter the transactions by transaction ID

To enable transaction filter feature by transaction ID, please refer to the code sample below.

Code sample:

private void cmdFilterByTransactionID_Click(object sender, EventArgs e)
        {
            var rms = new SmartBridge.Api(txtClientID.Text, txtSecret.Text, txtReturnUrl.Text, txtBaseUrl.Text, txtoAuthUrl.Text);

            rms.setToken(txtaccess.Text);
            rms.setRefreshToken(txtRefresh.Text);
            rms.SetActiveTerminal(txtTerminalId.Text);
            JObject resp;
            try
            {
                resp = (JObject)rms.CreateTransaction(2400, "GBP", "SALE");
                lblOutput.Text = resp.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            string transactionid = resp["transactionid"].ToString();
            MessageBox.Show("Transaction " + transactionid + " created ");
            try
            {
                resp = (JObject)rms.GetTransactionById(transactionid);
                lblOutput.Text += resp.ToString();

            }
            catch (Exception ex) { }

            cmdCheckStatus.Tag = transactionid;
          
        }

9. Retrieve transaction details

If you want to retrieve transaction details, please refer to the code sample below.

Code sample:

private void cmdRetrieveTransactionDetail_Click(object sender, EventArgs e)
        {
            var rms = new SmartBridge.Api(txtClientID.Text, txtSecret.Text, txtReturnUrl.Text, txtBaseUrl.Text, txtoAuthUrl.Text);

            rms.setToken(txtaccess.Text);
            rms.setRefreshToken(txtRefresh.Text);
            rms.SetActiveTerminal(txtTerminalId.Text);
            JObject resp;
            try
            {
                resp = (JObject)rms.CreateTransaction(2400, "GBP", "SALE");
                lblOutput.Text = resp.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            string transactionid = resp["transactionid"].ToString();
            MessageBox.Show("Transaction " + transactionid + " created , Retrieving Details...");
            try
            {
                resp = (JObject)rms.GetTransactionById(transactionid);
                lblOutput.Text += resp.ToString();

            }
            catch (Exception ex) { }

            cmdCheckStatus.Tag = transactionid;

        }

10. Retrieve status of the sale transaction

If you want to retrieve status of the sale transaction, please refer to the code sample below.

Code sample:

private void cmdStatusofTheSale_Click(object sender, EventArgs e)
        {
            var rms = new SmartBridge.Api(txtClientID.Text, txtSecret.Text, txtReturnUrl.Text, txtBaseUrl.Text, txtoAuthUrl.Text);

            rms.setToken(txtaccess.Text);
            rms.setRefreshToken(txtRefresh.Text);
            rms.SetActiveTerminal(txtTerminalId.Text);
            JObject resp;
            try
            {
                resp = (JObject)rms.CreateTransaction(2400, "GBP", "SALE");
                lblOutput.Text = resp.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            string transactionid = resp["transactionid"].ToString();
            MessageBox.Show("Transaction " + transactionid + " created.\n Complete the transaction on the terminal. \nThen press ok on this Dialog");
            try
            {
                resp = (JObject)rms.GetTransactionById(transactionid);
                lblOutput.Text += resp.ToString();

            }
            catch (Exception ex) { }

            cmdCheckStatus.Tag = transactionid;
        }

11. Retrieve cancellation status

If you want to retrieve the cancellation status, please refer to the code sample below.

Code sample:

private void cmdCancellationStatus_Click(object sender, EventArgs e)
        {
            var rms = new SmartBridge.Api(txtClientID.Text, txtSecret.Text, txtReturnUrl.Text, txtBaseUrl.Text, txtoAuthUrl.Text);

            rms.setToken(txtaccess.Text);
            rms.setRefreshToken(txtRefresh.Text);
            rms.SetActiveTerminal(txtTerminalId.Text);
            JObject resp;
            try
            {
                resp = (JObject)rms.CreateTransaction(2400, "GBP", "SALE");
                lblOutput.Text = resp.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            string transactionid = resp["transactionid"].ToString();
            MessageBox.Show("Transaction " + transactionid + " created.\n Cancel the transaction on the terminal. \nThen press ok on this Dialog");
            try
            {
                resp = (JObject)rms.GetTransactionById(transactionid);
                lblOutput.Text += resp.ToString();

            }
            catch (Exception ex) { }

            cmdCheckStatus.Tag = transactionid;
        }

12. Retrieve the transaction stage

If you want to retrieve the transaction stage, please refer to the code sample below.

Code sample:

private void cmdRetrieveTransactionStage_Click(object sender, EventArgs e)
        {
   
            var rms = new SmartBridge.Api(txtClientID.Text, txtSecret.Text, txtReturnUrl.Text, txtBaseUrl.Text, txtoAuthUrl.Text);
            rms.setToken(txtaccess.Text);
            rms.setRefreshToken(txtRefresh.Text); 
            rms.SetActiveTerminal(txtTerminalId.Text);
            JObject resp;
            try
            {
                resp = (JObject)rms.CreateTransaction(2400, "GBP", "SALE");
                lblOutput.Text = resp.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            string transactionid = resp["transactionid"].ToString();
            MessageBox.Show("Transaction " + transactionid + " created.\nPress ok on this Dialog when you want the Transaction Stage");
            try
            {
                resp = (JObject)rms.GetTransactionById(transactionid);
                lblOutput.Text += "\nTransaction Stage:"+ resp["transactionStage"].ToString()+"\n";

            }
            catch (Exception ex) { }

            cmdCheckStatus.Tag = transactionid;
        }

13. Process chip and pin transactions

To process chip and pin transactions, please refer to the code sample below.

Code sample:

private void cmdProcessChipandPinTransactions_Click(object sender, EventArgs e)
       {
            var rms = new SmartBridge.Api(txtClientID.Text, txtSecret.Text, txtReturnUrl.Text, txtBaseUrl.Text, txtoAuthUrl.Text);

            rms.setToken(txtaccess.Text);
            rms.setRefreshToken(txtRefresh.Text);
           
            rms.SetActiveTerminal(txtTerminalId.Text);
            JObject resp;
            try
            {
                resp = (JObject)rms.CreateTransaction(2400, "GBP", "SALE");
                lblOutput.Text = resp.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }

14. Process swiped transactions

To process swiped transactions, please refer to the code sample below.

Code sample:

private void cmdSwipedTransactions_Click(object sender, EventArgs e)
       {
            var rms = new SmartBridge.Api(txtClientID.Text, txtSecret.Text, txtReturnUrl.Text, txtBaseUrl.Text, txtoAuthUrl.Text);

            rms.setToken(txtaccess.Text);
            rms.setRefreshToken(txtRefresh.Text);
             
            rms.SetActiveTerminal(txtTerminalId.Text);
            JObject resp;
            try
            {
                resp = (JObject)rms.CreateTransaction(2400, "GBP", "SALE");
                lblOutput.Text = resp.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }

15. Process contactless transactions

To process contactless transactions, please refer to the code sample below.

Code sample:

private void cmdContactless_Click(object sender, EventArgs e)
        {
            var rms = new SmartBridge.Api(txtClientID.Text, txtSecret.Text, txtReturnUrl.Text, txtBaseUrl.Text, txtoAuthUrl.Text);

            rms.setToken(txtaccess.Text);
            rms.setRefreshToken(txtRefresh.Text);
           
            rms.SetActiveTerminal(txtTerminalId.Text);
            JObject resp;
            try
            {
                resp = (JObject)rms.CreateTransaction(2400, "GBP", "SALE");
                lblOutput.Text = resp.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }

16. View all transactions

To view all transactions processed by a terminal, please refer to the code sample below.

Code sample:

private void cmdViewAllTransactions_Click(object sender, EventArgs e)
        {
            var rms = new SmartBridge.Api(txtClientID.Text, txtSecret.Text, txtReturnUrl.Text, txtBaseUrl.Text, txtoAuthUrl.Text);

            rms.setToken(txtaccess.Text);
            rms.setRefreshToken(txtRefresh.Text);
            
            rms.SetActiveTerminal(txtTerminalId.Text);
            JObject resp;
            try
            {
                resp = (JObject)rms.GetTransactions();
                lblOutput.Text = resp.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }

17. Start an XBAL report

To start an XBAL report, please refer to the code sample below.

Code sample:

private void cmdXBALReport_Click(object sender, EventArgs e)
       {
            var rms = new SmartBridge.Api(txtClientID.Text, txtSecret.Text, txtReturnUrl.Text, txtBaseUrl.Text, txtoAuthUrl.Text);

            rms.setToken(txtaccess.Text);
            rms.setRefreshToken(txtRefresh.Text);
            
            rms.SetActiveTerminal(txtTerminalId.Text);
            rms.RequestReportByType("XBAL");
        }

18. Start a ZBAL report

To start a ZBAL report, please refer to the code sample below.

Code sample:

private void cmdZBALReport_Click(object sender, EventArgs e)
         {
            var rms = new SmartBridge.Api(txtClientID.Text, txtSecret.Text, txtReturnUrl.Text, txtBaseUrl.Text, txtoAuthUrl.Text);

            rms.setToken(txtaccess.Text);
            rms.setRefreshToken(txtRefresh.Text); 
            rms.SetActiveTerminal(txtTerminalId.Text);
            rms.RequestReportByType("ZBAL");
        }

💬 We're here to help!

If you're looking for help, shoot us an email. Please include a description of the issues that you are running into.