Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ErrorCode and ErrorGroup has been added. #150

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Iyzipay.Samples/Sample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

Expand Down
9 changes: 7 additions & 2 deletions Iyzipay/IyzipayResourceV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -69,8 +71,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
142 changes: 90 additions & 52 deletions Iyzipay/RestHttpClientV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -45,14 +47,19 @@ 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)
foreach (var header in headers)
{
requestMessage.Headers.Add(header.Key, header.Value);
}
Expand All @@ -64,14 +71,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");
string jsonContent = content.ReadAsStringAsync().Result;
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);
}
Expand All @@ -85,39 +98,49 @@ 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");
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);
}
foreach (var header in headers)
{
requestMessage.Headers.Add(header.Key, header.Value);
}

HttpResponseMessage httpResponseMessage = HttpClient.SendAsync(requestMessage).Result;
HttpResponseMessage httpResponseMessage = HttpClient.SendAsync(requestMessage).Result;
var response = JsonConvert.DeserializeObject<T>(httpResponseMessage.Content.ReadAsStringAsync().Result);
response.AppendWithHttpResponseHeaders(httpResponseMessage);
return response;
}

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");
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);
}
foreach (var header in headers)
{
requestMessage.Headers.Add(header.Key, header.Value);
}

HttpResponseMessage httpResponseMessage = HttpClient.SendAsync(requestMessage).Result;
HttpResponseMessage httpResponseMessage = HttpClient.SendAsync(requestMessage).Result;
var readAsString = await httpResponseMessage.Content.ReadAsStringAsync();
var response = JsonConvert.DeserializeObject<T>(readAsString);
response.AppendWithHttpResponseHeaders(httpResponseMessage);
Expand All @@ -127,11 +150,16 @@ 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 +175,19 @@ 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");
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);
}
Expand All @@ -167,14 +200,19 @@ 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");
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);
}
Expand Down
Loading