public static SinglePaymentResponse doSomething(Environment env, SinglePaymentRequest req) { using (HttpClient client = new HttpClient(getHTTPClientHandler("singlePayment", env))) { String queryParams = "?client_id=" + env.getClientId() + "&client_secret=" + env.getClientSecret(); client.BaseAddress = new Uri( env.getEndpointAddress("singlePayment").Uri.ToString() + queryParams); HttpResponseMessage response = client.PostAsync("", getRequestContent(req)).Result; response.EnsureSuccessStatusCode(); String responseJSON = response.Content.ReadAsStringAsync().Result; using (MemoryStream responseStream = new MemoryStream(Encoding.UTF8.GetBytes(responseJSON))) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(SinglePaymentResponse)); return((SinglePaymentResponse)serializer.ReadObject(responseStream)); } } }
private static HttpContent getRequestContent(SinglePaymentRequest req) { req.request.signature = new Signature(); DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(SinglePaymentRequest)); using (MemoryStream ms = new MemoryStream()) { serializer.WriteObject(ms, req); String requestJSON = Encoding.UTF8.GetString(ms.ToArray()); Console.WriteLine(requestJSON); return(new StringContent( requestJSON, Encoding.UTF8, "application/json")); } }