Skip to content

Commit

Permalink
JsonStringMethod Changed
Browse files Browse the repository at this point in the history
  • Loading branch information
byasarcse committed Nov 15, 2024
1 parent e631910 commit 883ba1f
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 48 deletions.
10 changes: 7 additions & 3 deletions Iyzipay/IyzipayResourceV2.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -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;
Expand Down
132 changes: 87 additions & 45 deletions Iyzipay/RestHttpClientV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -45,12 +45,18 @@ public T Get<T>(String url, Dictionary<string, string> headers) where T : Iyzipa

public T Post<T>(String url, Dictionary<string, string> 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)
{
Expand All @@ -64,14 +70,20 @@ public T Post<T>(String url, Dictionary<string, string> headers, BaseRequestV2 r
}
public async Task<T> PostAsync<T>(String url, Dictionary<string, string> 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);
}
Expand All @@ -85,14 +97,20 @@ public async Task<T> PostAsync<T>(String url, Dictionary<string, string> headers

public T Put<T>(String url, Dictionary<string, string> 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);
}
Expand All @@ -105,14 +123,20 @@ public T Put<T>(String url, Dictionary<string, string> headers, BaseRequestV2 re

public async Task<T> PutAsync<T>(String url, Dictionary<string, string> 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);
}
Expand All @@ -127,11 +151,17 @@ public async Task<T> PutAsync<T>(String url, Dictionary<string, string> headers,

public T Patch<T>(String url, Dictionary<string, string> 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)
Expand All @@ -147,14 +177,20 @@ public T Patch<T>(String url, Dictionary<string, string> headers, BaseRequestV2

public T Delete<T>(String url, Dictionary<string, string> 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);
}
Expand All @@ -167,14 +203,20 @@ public T Delete<T>(String url, Dictionary<string, string> headers, BaseRequestV2

public async Task<T> DeleteAsync<T>(String url, Dictionary<string, string> 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);
}
Expand Down

0 comments on commit 883ba1f

Please sign in to comment.