Esempio n. 1
0
        public static Chilkat.Rest ConnectToLithic(bool fTestnet)
        {
            Chilkat.Rest rest = new Chilkat.Rest();
            bool         success;
            bool         bTls           = true;
            int          port           = 443;
            bool         bAutoReconnect = true;
            string       sURL           = fTestnet ? "sandbox.lithic.com" : "api.lithic.com";

            success = rest.Connect(sURL, port, bTls, bAutoReconnect);
            if (success != true)
            {
                Log("ConnectFailReason: " + Convert.ToString(rest.ConnectFailReason));
                Log(rest.LastErrorText);
                return(null);
            }
            string lithic_testnet = GetBMSConfigurationKeyValue("lithic_testnet");
            string lithic_prod    = GetBMSConfigurationKeyValue("lithic_prod");

            string auth = "Authorization: api-key " + lithic_testnet;
            string sKey = fTestnet ? "api-key " + lithic_testnet : "api-key " + lithic_prod;

            rest.AddHeader("Authorization", sKey);
            rest.AddHeader("Content-Type", "application/json");
            return(rest);
        }
Esempio n. 2
0
        public static void ListAllCardholders()
        {
            Chilkat.Rest rest = new Chilkat.Rest();
            bool         success;
            //  URL: https://api.stripe.com/v1/balance
            bool bTls           = true;
            int  port           = 443;
            bool bAutoReconnect = true;

            success = rest.Connect("api.stripe.com", port, bTls, bAutoReconnect);
            if (success != true)
            {
                Log("ConnectFailReason: " + Convert.ToString(rest.ConnectFailReason));
                Log(rest.LastErrorText);
                return;
            }
            Chilkat.StringBuilder sbResponseBody = new Chilkat.StringBuilder();
            success = rest.FullRequestNoBodySb("GET", "/v1/issuing/cardholders", sbResponseBody);
            if (success != true)
            {
                Log(rest.LastErrorText);
                return;
            }
            Chilkat.JsonObject jsonResponse = new Chilkat.JsonObject();
            jsonResponse.LoadSb(sbResponseBody);
            var o        = jsonResponse.StringOf("object");
            var livemode = jsonResponse.BoolOf("livemode");
        }
Esempio n. 3
0
        public static void CreateCardholder()
        {
            Chilkat.Rest rest = new Chilkat.Rest();
            bool         success;
            //  URL: https://api.stripe.com/v1/balance
            bool bTls           = true;
            int  port           = 443;
            bool bAutoReconnect = true;

            success = rest.Connect("api.stripe.com", port, bTls, bAutoReconnect);
            if (success != true)
            {
                Log("ConnectFailReason: " + Convert.ToString(rest.ConnectFailReason));
                Log(rest.LastErrorText);
                return;
            }
            //rest.SetAuthBasic(stripe_testnet, "");
            rest.AddQueryParam("type", "individual");
            rest.AddQueryParam("name", "John Doe");
            rest.AddQueryParam("billing[address][line1]", "1008 Their Address St.");
            rest.AddQueryParam("billing[address][city]", "City");
            rest.AddQueryParam("billing[address][state]", "St");
            rest.AddQueryParam("billing[address][country]", "US");
            rest.AddQueryParam("billing[address][postal_code]", "Zip");
            string strResponseBody = rest.FullRequestFormUrlEncoded("POST", "/v1/issuing/cardholders");

            if (rest.LastMethodSuccess != true)
            {
                Log(rest.LastErrorText);
                return;
            }

            Chilkat.JsonObject jsonResponse = new Chilkat.JsonObject();
            jsonResponse.Load(strResponseBody);
        }
Esempio n. 4
0
        public static Chilkat.Rest ConnectToZinc()
        {
            Chilkat.Rest rest = new Chilkat.Rest();
            bool         success;
            bool         bTls           = true;
            int          port           = 443;
            bool         bAutoReconnect = true;
            string       sURL           = "api.zinc.io";

            success = rest.Connect(sURL, port, bTls, bAutoReconnect);
            if (success != true)
            {
                Log("ConnectFailReason: " + Convert.ToString(rest.ConnectFailReason));
                Log(rest.LastErrorText);
                return(null);
            }

            string sKey = GetBMSConfigurationKeyValue("zincprod");

            rest.SetAuthBasic(sKey, "");
            return(rest);
        }
Esempio n. 5
0
        private void googleDriveListFiles()
        {
            bool success = true;

            Chilkat.AuthGoogle gAuth = new Chilkat.AuthGoogle();
            //  This is our previously obtained access token...
            gAuth.AccessToken = getSavedAccessToken();
            if (gAuth.AccessToken.Length == 0)
            {
                popupError("No previously obtained access token is available.");
                return;
            }

            Chilkat.Rest rest = new Chilkat.Rest();

            //  Connect using TLS.
            bool bAutoReconnect = true;

            success = rest.Connect("www.googleapis.com", 443, true, bAutoReconnect);

            //  Provide the authentication credentials (i.e. the access key)
            rest.SetAuthGoogle(gAuth);

            //  Add a search query parameter to only return files having names matching our criteria
            //  See https://developers.google.com/drive/v3/web/search-parameters
            // ignore = rest.AddQueryParam("q","name contains 'starfish'");
            // ignore = rest.AddQueryParam("maxResults","2");

            //  We are using the Google Drive V3 API... (not V2)
            string jsonResponse = rest.FullRequestNoBody("GET", "/drive/v3/files");

            if (rest.LastMethodSuccess != true)
            {
                fgAppendToErrorLog(rest.LastErrorText);
                popupError("REST request failed.");
                return;
            }

            // A successful JSON response looks like this:
            //{
            //  "kind": "drive#fileList",
            //  "files": [
            //    {
            //      "kind": "drive#file",
            //      "id": "0B53Q6OSTWYolenpjTEU4ekJlQUU",
            //      "name": "test",
            //      "mimeType": "application/vnd.google-apps.folder"
            //    },
            //    {
            //      "kind": "drive#file",
            //      "id": "0B53Q6OSTWYolRm4ycjZtdXhRaEE",
            //      "name": "starfish4.jpg",
            //      "mimeType": "image/jpeg"
            //    },
            //    {
            //      "kind": "drive#file",
            //      "id": "0B53Q6OSTWYolMWt2VzN0Qlo1UjA",
            //      "name": "hamlet2.xml",
            //      "mimeType": "text/xml"
            //    },
            // ...
            //    {
            //      "kind": "drive#file",
            //      "id": "0B53Q6OSTWYolc3RhcnRlcl9maWxlX2Rhc2hlclYw",
            //      "name": "Getting started",
            //      "mimeType": "application/pdf"
            //    }
            //  ]
            //}

            // Iterate over the files and show the name and mimeType of each.
            Chilkat.JsonObject json = new Chilkat.JsonObject();
            json.Load(jsonResponse);
            int numFiles = json.SizeOfArray("files");
            int i        = 0;

            while (i < numFiles)
            {
                json.I = i;
                fgAppendToErrorLog("name: " + json.StringOf("files[i].name") + "\r\n");
                fgAppendToErrorLog("mimeType: " + json.StringOf("files[i].mimeType") + "\r\n");
                i++;
            }
        }
Esempio n. 6
0
        // (for Google authorization)
        // Exchange the code for an access token and refresh token.

        // REMEMBER -- this code is running in a background thread because it is called
        // from listenSocket_OnTaskCompleted.
        private bool googleExchangeCodeForToken(string code, string taskUserData)
        {
            // The taskUserData contains JSON information.
            Chilkat.JsonObject taskData = new Chilkat.JsonObject();
            taskData.Load(taskUserData);
            string redirect_uri  = taskData.StringOf("redirect_uri");
            string code_verifier = taskData.StringOf("code_verifier");

            Chilkat.Rest rest = new Chilkat.Rest();

            bool bTls           = true;
            int  port           = 443;
            bool bAutoReconnect = true;
            bool success        = rest.Connect("www.googleapis.com", port, bTls, bAutoReconnect);

            if (success != true)
            {
                fgAppendToErrorLog(rest.LastErrorText);
                return(false);
            }

            success = rest.AddQueryParam("code", code);
            success = rest.AddQueryParam("client_id", googleAppClientId);
            success = rest.AddQueryParam("client_secret", googleAppClientSecret);
            success = rest.AddQueryParam("redirect_uri", redirect_uri);
            success = rest.AddQueryParam("code_verifier", code_verifier);
            success = rest.AddQueryParam("scope", "");
            success = rest.AddQueryParam("grant_type", "authorization_code");

            rest.VerboseLogging = true;
            string responseJson = rest.FullRequestFormUrlEncoded("POST", "/oauth2/v4/token");

            if (rest.LastMethodSuccess != true)
            {
                fgAppendToErrorLog(rest.LastErrorText);
                return(false);
            }

            //  When successful, the response status code will equal 200.
            if (rest.ResponseStatusCode != 200)
            {
                //  Examine the request/response to see what happened.
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("LastErrorText: " + rest.LastErrorText);
                sb.AppendLine("response status code = " + Convert.ToString(rest.ResponseStatusCode));
                sb.AppendLine("response status text = " + rest.ResponseStatusText);
                sb.AppendLine("response header: " + rest.ResponseHeader);
                sb.AppendLine("response body (if any): " + responseJson);
                sb.AppendLine("---");
                sb.AppendLine("LastRequestStartLine: " + rest.LastRequestStartLine);
                sb.AppendLine("LastRequestHeader: " + rest.LastRequestHeader);
                fgAppendToErrorLog(sb.ToString());
                return(false);
            }

            // A successful response JSON will look like this:
            //{
            // "access_token": "ya29.Ci9ZA-Z0Q7vtnch8xxxxxxxxxxxxxxgDVOOV97-IBvTt958xxxxxx1sasw",
            // "token_type": "Bearer",
            // "expires_in": 3600,
            // "refresh_token": "1/fYjEVR-3Oq9xxxxxxxxxxxxxxLzPtlNOeQ"
            //}
            m_googleAccessJson = responseJson;

            fgAppendToErrorLog(responseJson);

            return(true);
        }