From 750907512be15fa6b5382cf60c174c6bdadfe989 Mon Sep 17 00:00:00 2001 From: byasarcse Date: Wed, 6 Nov 2024 13:28:37 +0300 Subject: [PATCH 1/5] ErrorCode and ErrorGroup has been added. --- Iyzipay/IyzipayResourceV2.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Iyzipay/IyzipayResourceV2.cs b/Iyzipay/IyzipayResourceV2.cs index e2d0e73..194e35a 100644 --- a/Iyzipay/IyzipayResourceV2.cs +++ b/Iyzipay/IyzipayResourceV2.cs @@ -19,7 +19,9 @@ public class IyzipayResourceV2 public String Status { get; set; } public int StatusCode { get; set; } + public String ErrorCode { get; set; } public String ErrorMessage { get; set; } + public String ErrorGroup { get; set; } public String ConversationId { get; set; } public long SystemTime { get; set; } public String Locale { get; set; } From 228a3e35549352379b78b9538cebd4eeddb129c8 Mon Sep 17 00:00:00 2001 From: byasarcse Date: Wed, 6 Nov 2024 13:37:13 +0300 Subject: [PATCH 2/5] fix/jsonSerialize --- Iyzipay/IyzipayResourceV2.cs | 9 ++- Iyzipay/RestHttpClientV2.cs | 140 ++++++++++++++++++++--------------- 2 files changed, 88 insertions(+), 61 deletions(-) diff --git a/Iyzipay/IyzipayResourceV2.cs b/Iyzipay/IyzipayResourceV2.cs index 194e35a..1e5db93 100644 --- a/Iyzipay/IyzipayResourceV2.cs +++ b/Iyzipay/IyzipayResourceV2.cs @@ -4,6 +4,8 @@ using System.Linq; using System.Net.Http; using System.Net.Http.Headers; +using Newtonsoft.Json.Serialization; +using Newtonsoft.Json; namespace Iyzipay { @@ -71,8 +73,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..318d66b 100644 --- a/Iyzipay/RestHttpClientV2.cs +++ b/Iyzipay/RestHttpClientV2.cs @@ -6,6 +6,8 @@ using System.Net.Http.Headers; using System.Linq; using System.Threading.Tasks; +using Newtonsoft.Json.Serialization; +using System.Text; namespace Iyzipay { @@ -45,14 +47,19 @@ 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) + foreach (var header in headers) { requestMessage.Headers.Add(header.Key, header.Value); } @@ -64,14 +71,19 @@ 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"); + HttpRequestMessage requestMessage = new HttpRequestMessage + { + Method = HttpMethod.Post, + RequestUri = new Uri(url), + Content = content + }; - foreach (var header in headers) + foreach (var header in headers) { requestMessage.Headers.Add(header.Key, header.Value); } @@ -85,19 +97,19 @@ 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) - }; - - foreach (var header in headers) - { - requestMessage.Headers.Add(header.Key, header.Value); - } + 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, + RequestUri = new Uri(url), + Content = content + }; - HttpResponseMessage httpResponseMessage = HttpClient.SendAsync(requestMessage).Result; + HttpResponseMessage httpResponseMessage = HttpClient.SendAsync(requestMessage).Result; var response = JsonConvert.DeserializeObject(httpResponseMessage.Content.ReadAsStringAsync().Result); response.AppendWithHttpResponseHeaders(httpResponseMessage); return response; @@ -105,19 +117,19 @@ 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) - }; - - foreach (var header in headers) - { - requestMessage.Headers.Add(header.Key, header.Value); - } + 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, + RequestUri = new Uri(url), + Content = content + }; - HttpResponseMessage httpResponseMessage = HttpClient.SendAsync(requestMessage).Result; + HttpResponseMessage httpResponseMessage = HttpClient.SendAsync(requestMessage).Result; var readAsString = await httpResponseMessage.Content.ReadAsStringAsync(); var response = JsonConvert.DeserializeObject(readAsString); response.AppendWithHttpResponseHeaders(httpResponseMessage); @@ -127,18 +139,18 @@ 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) - { - requestMessage.Headers.Add(header.Key, header.Value); - } - HttpResponseMessage httpResponseMessage = HttpClient.SendAsync(requestMessage).Result; var response = JsonConvert.DeserializeObject(httpResponseMessage.Content.ReadAsStringAsync().Result); response.AppendWithHttpResponseHeaders(httpResponseMessage); @@ -147,14 +159,19 @@ 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"); + HttpRequestMessage requestMessage = new HttpRequestMessage + { + Method = HttpMethod.Delete, + RequestUri = new Uri(url), + Content = content + }; - foreach (var header in headers) + foreach (var header in headers) { requestMessage.Headers.Add(header.Key, header.Value); } @@ -167,14 +184,19 @@ 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"); + HttpRequestMessage requestMessage = new HttpRequestMessage + { + Method = HttpMethod.Delete, + RequestUri = new Uri(url), + Content = content + }; - foreach (var header in headers) + foreach (var header in headers) { requestMessage.Headers.Add(header.Key, header.Value); } From 6e437fb169e853121663149d577ca31d3730a205 Mon Sep 17 00:00:00 2001 From: byasarcse Date: Wed, 6 Nov 2024 13:44:37 +0300 Subject: [PATCH 3/5] Typo/Added missing foreach --- Iyzipay/RestHttpClientV2.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Iyzipay/RestHttpClientV2.cs b/Iyzipay/RestHttpClientV2.cs index 318d66b..3620c77 100644 --- a/Iyzipay/RestHttpClientV2.cs +++ b/Iyzipay/RestHttpClientV2.cs @@ -109,6 +109,11 @@ public T Put(String url, Dictionary headers, BaseRequestV2 re Content = content }; + foreach (var header in headers) + { + requestMessage.Headers.Add(header.Key, header.Value); + } + HttpResponseMessage httpResponseMessage = HttpClient.SendAsync(requestMessage).Result; var response = JsonConvert.DeserializeObject(httpResponseMessage.Content.ReadAsStringAsync().Result); response.AppendWithHttpResponseHeaders(httpResponseMessage); @@ -129,6 +134,11 @@ public async Task PutAsync(String url, Dictionary headers, Content = content }; + foreach (var header in headers) + { + requestMessage.Headers.Add(header.Key, header.Value); + } + HttpResponseMessage httpResponseMessage = HttpClient.SendAsync(requestMessage).Result; var readAsString = await httpResponseMessage.Content.ReadAsStringAsync(); var response = JsonConvert.DeserializeObject(readAsString); @@ -151,6 +161,11 @@ public T Patch(String url, Dictionary headers, BaseRequestV2 Content = content }; + foreach (var header in headers) + { + requestMessage.Headers.Add(header.Key, header.Value); + } + HttpResponseMessage httpResponseMessage = HttpClient.SendAsync(requestMessage).Result; var response = JsonConvert.DeserializeObject(httpResponseMessage.Content.ReadAsStringAsync().Result); response.AppendWithHttpResponseHeaders(httpResponseMessage); From d7ed292c5f4ab106ff0140d76292610a0847fc7d Mon Sep 17 00:00:00 2001 From: byasarcse Date: Fri, 8 Nov 2024 14:15:44 +0300 Subject: [PATCH 4/5] Revert "ErrorCode and ErrorGroup has been added." This reverts commit 750907512be15fa6b5382cf60c174c6bdadfe989. --- Iyzipay/IyzipayResourceV2.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Iyzipay/IyzipayResourceV2.cs b/Iyzipay/IyzipayResourceV2.cs index 1e5db93..065b4a3 100644 --- a/Iyzipay/IyzipayResourceV2.cs +++ b/Iyzipay/IyzipayResourceV2.cs @@ -21,9 +21,7 @@ public class IyzipayResourceV2 public String Status { get; set; } public int StatusCode { get; set; } - public String ErrorCode { get; set; } public String ErrorMessage { get; set; } - public String ErrorGroup { get; set; } public String ConversationId { get; set; } public long SystemTime { get; set; } public String Locale { get; set; } From 845c2a7ccbf9303ee37d092607700c6cbfbb73f1 Mon Sep 17 00:00:00 2001 From: byasarcse Date: Fri, 8 Nov 2024 14:16:46 +0300 Subject: [PATCH 5/5] Revert - ErrorCode and ErrorGroup has been added --- Iyzipay.Samples/Sample.cs | 4 ++-- Iyzipay/RestHttpClientV2.cs | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Iyzipay.Samples/Sample.cs b/Iyzipay.Samples/Sample.cs index 56168f4..38d6053 100644 --- a/Iyzipay.Samples/Sample.cs +++ b/Iyzipay.Samples/Sample.cs @@ -15,8 +15,8 @@ public class Sample public void Initialize() { options = new Options(); - options.ApiKey = "your api key"; - options.SecretKey = "your secret key"; + options.ApiKey = "sandbox-X8Qfwvvb16pe2prgfeX857cwiD4bkfAf"; + options.SecretKey = "sandbox-qaIiLIxhjMgx3LSKIVvp6j17NunHOFtD"; options.BaseUrl = "https://sandbox-api.iyzipay.com"; } diff --git a/Iyzipay/RestHttpClientV2.cs b/Iyzipay/RestHttpClientV2.cs index 3620c77..921b624 100644 --- a/Iyzipay/RestHttpClientV2.cs +++ b/Iyzipay/RestHttpClientV2.cs @@ -76,6 +76,7 @@ public async Task PostAsync(String url, Dictionary headers ContractResolver = new CamelCasePropertyNamesContractResolver(), }; var content = new StringContent(JsonConvert.SerializeObject(request, settings), Encoding.UTF8, "application/json"); + string jsonContent = content.ReadAsStringAsync().Result; HttpRequestMessage requestMessage = new HttpRequestMessage { Method = HttpMethod.Post,