static async Task PairTerminal()
        {
            using HttpClient client = new HttpClient();

            client.BaseAddress = new Uri("https://takepayments-integrated-sandbox-apim.azure-api.net/");

            client.DefaultRequestHeaders.Add("Authorization", $"bearer {_token}");

            var request = await client.PostAsync($"Terminal/", 
                new StringContent(JsonConvert.SerializeObject(new { terminalType = 2, tid = _tid }), Encoding.UTF8, "application/json"));

            var terminal = JsonConvert.DeserializeObject(await request.Content.ReadAsStringAsync());

            async Task WaitForTerminalToBeReadyToPair()
            {
                while (terminal is not {state: "AwaitingPairing"})
                {
                    Thread.Sleep(500);

                    WriteMessage($"Pairing, awaiting ready to pair state, current state {terminal.state} last checked at {DateTime.Now}");

                    terminal = await GetTerminal();
                }
            }

            await WaitForTerminalToBeReadyToPair();
            
            WriteMessage( "=============================================================");
            WriteMessage($"Terminal is ready to pair, please inout the following details");
            WriteMessage($"IP Address  : {terminal.ipAddress}");
            WriteMessage($"Port        : {terminal.portNumber}");
            WriteMessage("=============================================================");

            async Task WaitForTerminalReadyState()
            {
                while (terminal is {state: "AwaitingPairing"})
                {
                    Thread.Sleep(500);

                    terminal = await GetTerminal();

                    WriteMessage($"Pairing, awaiting paired state, current state {terminal.state} last checked at {DateTime.Now}");
                }
            }

            await WaitForTerminalReadyState();

            if (terminal.state != "Connected")
            {
                WriteMessage($"There has been a problem, the terminal is not ready to pair, state : {terminal.state}");
                return null;
            }

            WriteMessage("Terminal Connected");

            return terminal;
        }