/// <summary> /// Makes a PATCH request to API /// </summary> /// <param name="endPoint">The api endPoint</param> /// <param name="stringBody">The request payload</param> /// <returns>The response</returns> public string patch(string endPoint, IPaymentRailsMappable body) { body.IsMappable(); HttpContent jsonBody = convertBody(body.ToJson()); string result = ""; try { httpClient = createRequest(endPoint, "PATCH", body); var request = new HttpRequestMessage(new HttpMethod("PATCH"), endPoint) { Content = jsonBody }; System.Threading.Tasks.Task <HttpResponseMessage> responseTask = httpClient.SendAsync(request); HttpResponseMessage response = responseTask.Result; result = response.Content.ReadAsStringAsync().Result; if ((int)response.StatusCode != 200) { throwStatusCodeException((int)response.StatusCode, response.Content.ReadAsStringAsync().Result); } } catch (System.Net.Http.HttpRequestException) { throw new InvalidStatusCodeException(result); } return(result); }
/// <summary> /// Makes a POST request to API /// </summary> /// <param name="endPoint">The api endPoint</param> /// <param name="stringBody">The request payload</param> /// <returns>The Response</returns> public string post(string endPoint, IPaymentRailsMappable body) { body.IsMappable(); HttpContent jsonBody = convertBody(body.ToJson()); string result = ""; try { httpClient = createRequest(endPoint, "POST", body); HttpResponseMessage response = httpClient.PostAsync(endPoint, jsonBody).Result; result = response.Content.ReadAsStringAsync().Result; if ((int)response.StatusCode != 200) { throwStatusCodeException((int)response.StatusCode, response.Content.ReadAsStringAsync().Result); } } catch (System.Net.Http.HttpRequestException) { throw new InvalidStatusCodeException(result); } return(result); }
private string generateAuthorization(string timeStamp, string endPoint, string method, IPaymentRailsMappable body) { string newBody = ""; if (body != null) { newBody = body.ToJson(); } string message = timeStamp + "\n" + method + "\n" + endPoint + "\n" + newBody + "\n"; if (this.config.ApiSecret == null || this.config.ApiSecret == "") { throw new InvalidCredentialsException("API Secret must be provided."); } if (this.config.ApiKey == null || this.config.ApiKey == "") { throw new InvalidCredentialsException("API Key must be provided."); } var signature = GetHash(message, this.config.ApiSecret); return("prsign " + this.config.ApiKey + ":" + signature); }