diff --git a/Iyzipay/IyzipayResourceV2.cs b/Iyzipay/IyzipayResourceV2.cs index 194e35a..979211c 100644 --- a/Iyzipay/IyzipayResourceV2.cs +++ b/Iyzipay/IyzipayResourceV2.cs @@ -1,9 +1,10 @@ using System; using System.Collections.Generic; -using System.Net; using System.Linq; using System.Net.Http; using System.Net.Http.Headers; +using Newtonsoft.Json.Serialization; +using Newtonsoft.Json; namespace Iyzipay { @@ -71,8 +72,11 @@ private static String PrepareAuthorizationStringWithRequestBody(BaseRequestV2 re { String randomKey = GenerateRandomKey(); String uriPath = FindUriPath(url); - - String payload = request != null ? uriPath + JsonBuilder.SerializeObjectToPrettyJson(request) : uriPath; + var settings = new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver(), + }; + String payload = request != null ? uriPath + JsonConvert.SerializeObject(request, settings) : uriPath; String dataToEncrypt = randomKey + payload; String hash = HashGeneratorV2.GenerateHash(options.ApiKey, options.SecretKey, randomKey, dataToEncrypt); return IYZIWS_V2_HEADER_NAME + hash; diff --git a/Iyzipay/RestHttpClientV2.cs b/Iyzipay/RestHttpClientV2.cs index b8c9e82..9d471fd 100644 --- a/Iyzipay/RestHttpClientV2.cs +++ b/Iyzipay/RestHttpClientV2.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.Net; using System.Net.Http; -using System.Net.Http.Headers; -using System.Linq; using System.Threading.Tasks; +using Newtonsoft.Json.Serialization; +using System.Text; namespace Iyzipay { @@ -45,12 +45,18 @@ public T Get(String url, Dictionary headers) where T : Iyzipa public T Post(String url, Dictionary headers, BaseRequestV2 request) where T : IyzipayResourceV2 { - HttpRequestMessage requestMessage = new HttpRequestMessage - { - Method = HttpMethod.Post, - RequestUri = new Uri(url), - Content = JsonBuilder.ToJsonString(request) - }; + var settings = new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver(), + }; + var content = new StringContent(JsonConvert.SerializeObject(request, settings), Encoding.UTF8, "application/json"); + + HttpRequestMessage requestMessage = new HttpRequestMessage + { + Method = HttpMethod.Post, + RequestUri = new Uri(url), + Content = content + }; foreach (var header in headers) { @@ -64,14 +70,20 @@ public T Post(String url, Dictionary headers, BaseRequestV2 r } public async Task PostAsync(String url, Dictionary headers, BaseRequestV2 request) where T : IyzipayResourceV2 { - HttpRequestMessage requestMessage = new HttpRequestMessage - { - Method = HttpMethod.Post, - RequestUri = new Uri(url), - Content = JsonBuilder.ToJsonString(request) - }; + var settings = new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver(), + }; + var content = new StringContent(JsonConvert.SerializeObject(request, settings), Encoding.UTF8, "application/json"); - foreach (var header in headers) + HttpRequestMessage requestMessage = new HttpRequestMessage + { + Method = HttpMethod.Post, + RequestUri = new Uri(url), + Content = content + }; + + foreach (var header in headers) { requestMessage.Headers.Add(header.Key, header.Value); } @@ -85,14 +97,20 @@ public async Task PostAsync(String url, Dictionary headers public T Put(String url, Dictionary headers, BaseRequestV2 request) where T : IyzipayResourceV2 { - HttpRequestMessage requestMessage = new HttpRequestMessage - { - Method = HttpMethod.Put, - RequestUri = new Uri(url), - Content = JsonBuilder.ToJsonString(request) - }; + var settings = new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver(), + }; + var content = new StringContent(JsonConvert.SerializeObject(request, settings), Encoding.UTF8, "application/json"); - foreach (var header in headers) + HttpRequestMessage requestMessage = new HttpRequestMessage + { + Method = HttpMethod.Put, + RequestUri = new Uri(url), + Content = content + }; + + foreach (var header in headers) { requestMessage.Headers.Add(header.Key, header.Value); } @@ -105,14 +123,20 @@ public T Put(String url, Dictionary headers, BaseRequestV2 re public async Task PutAsync(String url, Dictionary headers, BaseRequestV2 request) where T : IyzipayResourceV2 { - HttpRequestMessage requestMessage = new HttpRequestMessage - { - Method = HttpMethod.Put, - RequestUri = new Uri(url), - Content = JsonBuilder.ToJsonString(request) - }; + var settings = new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver(), + }; + var content = new StringContent(JsonConvert.SerializeObject(request, settings), Encoding.UTF8, "application/json"); - foreach (var header in headers) + HttpRequestMessage requestMessage = new HttpRequestMessage + { + Method = HttpMethod.Put, + RequestUri = new Uri(url), + Content = content + }; + + foreach (var header in headers) { requestMessage.Headers.Add(header.Key, header.Value); } @@ -127,11 +151,17 @@ public async Task PutAsync(String url, Dictionary headers, public T Patch(String url, Dictionary headers, BaseRequestV2 request) where T : IyzipayResourceV2 { + var settings = new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver(), + }; + var content = new StringContent(JsonConvert.SerializeObject(request, settings), Encoding.UTF8, "application/json"); + HttpRequestMessage requestMessage = new HttpRequestMessage { - Method = HttpMethod.Put,//todo: [EY] Patch olarak değiştirilmeli fakat kütüphane güncellenmesi gerekiyor. + Method = HttpMethod.Put, RequestUri = new Uri(url), - Content = JsonBuilder.ToJsonString(request) + Content = content }; foreach (var header in headers) @@ -147,14 +177,20 @@ public T Patch(String url, Dictionary headers, BaseRequestV2 public T Delete(String url, Dictionary headers, BaseRequestV2 request) where T : IyzipayResourceV2 { - HttpRequestMessage requestMessage = new HttpRequestMessage - { - Method = HttpMethod.Delete, - RequestUri = new Uri(url), - Content = JsonBuilder.ToJsonString(request) - }; + var settings = new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver(), + }; + var content = new StringContent(JsonConvert.SerializeObject(request, settings), Encoding.UTF8, "application/json"); - foreach (var header in headers) + HttpRequestMessage requestMessage = new HttpRequestMessage + { + Method = HttpMethod.Delete, + RequestUri = new Uri(url), + Content = content + }; + + foreach (var header in headers) { requestMessage.Headers.Add(header.Key, header.Value); } @@ -167,14 +203,20 @@ public T Delete(String url, Dictionary headers, BaseRequestV2 public async Task DeleteAsync(String url, Dictionary headers, BaseRequestV2 request) where T : IyzipayResourceV2 { - HttpRequestMessage requestMessage = new HttpRequestMessage - { - Method = HttpMethod.Delete, - RequestUri = new Uri(url), - Content = JsonBuilder.ToJsonString(request) - }; + var settings = new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver(), + }; + var content = new StringContent(JsonConvert.SerializeObject(request, settings), Encoding.UTF8, "application/json"); - foreach (var header in headers) + HttpRequestMessage requestMessage = new HttpRequestMessage + { + Method = HttpMethod.Delete, + RequestUri = new Uri(url), + Content = content + }; + + foreach (var header in headers) { requestMessage.Headers.Add(header.Key, header.Value); }