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); }
// (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); }