Skip to content

Commit

Permalink
feat: sipay card integrations added; sipay, hepsiburada, trendyol log…
Browse files Browse the repository at this point in the history
…ics update
  • Loading branch information
onurkanbakirci committed Dec 29, 2023
1 parent 9876080 commit 3654fe1
Show file tree
Hide file tree
Showing 47 changed files with 942 additions and 86 deletions.
19 changes: 18 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,24 @@
"type": "dotnet",
"request": "launch",
"projectPath": "${workspaceFolder}/samples/PaymentGateways/SipayIntegrationSampleConsoleApp/SipayIntegrationSampleConsoleApp.csproj"
},
{
"name": "C#: Paynet Debug",
"type": "dotnet",
"request": "launch",
"projectPath": "${workspaceFolder}/samples/PaymentGateways/PaynetIntegrationSampleConsoleApp/PaynetIntegrationSampleConsoleApp.csproj"
},
{
"name": "C#: Hepsiburada Debug",
"type": "dotnet",
"request": "launch",
"projectPath": "${workspaceFolder}/samples/Marketplaces/HepsiburadaIntegrationSampleConsoleApp/HepsiburadaIntegrationSampleConsoleApp.csproj"
},
{
"name": "C#: Trendyol Debug",
"type": "dotnet",
"request": "launch",
"projectPath": "${workspaceFolder}/samples/Marketplaces/TrendyolIntegrationSampleConsoleApp/TrendyolIntegrationSampleConsoleApp.csproj"
}

]
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
isInProduction: false
);

await sipayPaymentIntegration.SetTokenAsync();

// Get installments
var installments = await sipayPaymentIntegration.CheckInstallmentsAsync(new CheckInstallmentRequestModel(
creaditCard: "123456",
creditCard: "450803",
amount: 100,
currenyCode: "TRY"
currencyCode: "TRY"
));

// Non secure payment
Expand Down
6 changes: 6 additions & 0 deletions src/Integration.Hub/ICardIntegration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Integration.Hub;

public interface ICardIntegration
{

}
20 changes: 14 additions & 6 deletions src/Integration.Hub/IntegrationBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,22 @@ static IntegrationBase()

protected void InitializeDefaultHeaders(Dictionary<string, string> headers)
{
// Add default headers to the request
foreach (var header in headers)
_httpClient.DefaultRequestHeaders.Add(header.Key, header.Value);
}

protected void SetHeader(KeyValuePair<string, string> header)
{
_httpClient.DefaultRequestHeaders.Add(header.Key, header.Value);
}

protected void SetSerializerOptions(JsonSerializerOptions options)
{
_options = options;
}

public async Task<TResponse> InvokeRequestAsync<TResponse>(Func<HttpClient, Task<HttpResponseMessage>> httpRequest) where TResponse : IResponseModel
public async Task<TResponse> InvokeRequestAsync<TResponse>(Func<HttpClient, Task<HttpResponseMessage>> httpRequest)
where TResponse : IResponseModel
{
var response = await httpRequest.Invoke(_httpClient);
var responseAsString = await response.Content.ReadAsStringAsync();
Expand All @@ -46,9 +51,11 @@ public async Task<bool> InvokeRequestAsync(Func<HttpClient, Task<HttpResponseMes
return isSuccess;
}

public async Task<TResponse> InvokeRequestAsync<TResponse>(Func<HttpClient, StringContent?, Task<HttpResponseMessage>> httpRequest, IRequestModel requestModel) where TResponse : IResponseModel
public async Task<TResponse> InvokeRequestAsync<TRequest, TResponse>(Func<HttpClient, StringContent?, Task<HttpResponseMessage>> httpRequest, TRequest requestModel)
where TResponse : IResponseModel
where TRequest : IRequestModel
{
var jsonData = JsonSerializer.Serialize(requestModel);
var jsonData = JsonSerializer.Serialize(requestModel, _options);
var requestBody = new StringContent(jsonData, Encoding.UTF8, "application/json");

var response = await httpRequest.Invoke(_httpClient, requestBody);
Expand All @@ -59,9 +66,10 @@ public async Task<TResponse> InvokeRequestAsync<TResponse>(Func<HttpClient, Stri
return JsonSerializer.Deserialize<TResponse>(responseAsString, _options)!;
}

public async Task<bool> InvokeRequestAsync(Func<HttpClient, StringContent?, Task<HttpResponseMessage>> httpRequest, IRequestModel requestModel)
public async Task<bool> InvokeRequestAsync<TRequest>(Func<HttpClient, StringContent?, Task<HttpResponseMessage>> httpRequest, TRequest requestModel)
where TRequest : IRequestModel
{
var jsonData = JsonSerializer.Serialize(requestModel);
var jsonData = JsonSerializer.Serialize(requestModel, _options);
var requestBody = new StringContent(jsonData, Encoding.UTF8, "application/json");

var response = await httpRequest.Invoke(_httpClient, requestBody);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Integration.Marketplaces.Hepsiburada.Infrastructure.ProductIntegration.Constants;
public enum ProductStatus
{
WAITING,
IN_EXTRENAL_PROGESS,
PRE_MATCHED,
MATCHED,
REJECTED,
MATCHED_WITH_STAGED,
MISSING_INFO,
CREATED,
BLOCKED
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Text.Json;
using Integration.Hub;
using Integration.Marketplaces.Hepsiburada.Infrastructure.ProductIntegration.Models.Request;
using Integration.Marketplaces.Hepsiburada.Infrastructure.ProductIntegration.Models.Response;
using Integration.Marketplaces.Trendyol.Infrastructure;

Expand All @@ -9,6 +11,16 @@ public class HepsiburadaProductIntegration : HepsiburadaIntegrationBase, IHepsib
private string GetCategoriesUrl() => $"{GetBaseUrl()}product/api/categories/get-all-categories";
private string GetCategoryAttributesUrl(int categoryId) => $"{GetBaseUrl()}product/api/categories/{categoryId}/attributes";
private string GetCategoryAttributeValueUrl(int categoryId, string attributeId) => $"{GetBaseUrl()}product/api/categories/{categoryId}/attribute/{attributeId}/v";
private string GetRejectPrematchUrl() => $"{GetBaseUrl()}product/api/products/reject-prematch";
private string GetCreateProductUrl() => $"{GetBaseUrl()}product/api/products/import";
private string GetFastListingUrl() => $"{GetBaseUrl()}product/api/products/fastlisting";
private string GetCheckProductStatusUrl() => $"{GetBaseUrl()}product/api/products/check-product-status";
private string GetApprovePrematchUrl() => $"{GetBaseUrl()}product/api/products/approve-prematch";
private string GetTrackingIdHistoryUrl() => $"{GetBaseUrl()}product/api/products/trackingId-history";
private string GetCheckProductStatusByTrackingIdUrl(string trackingId) => $"{GetBaseUrl()}product/api/products/status/{trackingId}";
private string GetProductsByStatusUrl(string merchantId, string productStatus) => $"{GetBaseUrl()}product/api/products/products-by-merchant-and-status?merchantId={merchantId}&productStatus={productStatus}";
private string GetCheckDeleteProductProcessUrl(string trackingId) => $"{GetBaseUrl()}product/api/products/delete-process/{trackingId}";
private string GetMerchatProductsUrl(string merchantId) => $"{GetBaseUrl()}product/api/products/all-products-of-merchant/{merchantId}";

public HepsiburadaProductIntegration(string username, string password, bool isInProduction = true) : base(username, password, isInProduction)
{
Expand All @@ -18,19 +30,19 @@ public HepsiburadaProductIntegration(string username, string password, bool isIn
/// <inheritdoc/>
/// </summary>
/// <returns><inheritdoc/></returns>
public async Task<GetCategoriesResponseModel> GetCategoriesAsync()
public async Task<HepsiburadaBaseResponseModel<List<GetCategoriesResponseModel>>> GetCategoriesAsync()
{
return await InvokeRequestAsync<GetCategoriesResponseModel>((client) => client.GetAsync(GetCategoriesUrl()));
return await InvokeRequestAsync<HepsiburadaBaseResponseModel<List<GetCategoriesResponseModel>>>((client) => client.GetAsync(GetCategoriesUrl()));
}

/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="categoryId"><inheritdoc/></param>
/// <returns><inheritdoc/></returns>
public async Task<GetCategoryAttributesResponseModel> GetCategoryAttributesAsync(int categoryId)
public async Task<HepsiburadaBaseResponseModel<List<GetCategoryAttributesResponseModel>>> GetCategoryAttributesAsync(int categoryId)
{
return await InvokeRequestAsync<GetCategoryAttributesResponseModel>((client) => client.GetAsync(GetCategoryAttributesUrl(categoryId)));
return await InvokeRequestAsync<HepsiburadaBaseResponseModel<List<GetCategoryAttributesResponseModel>>>((client) => client.GetAsync(GetCategoryAttributesUrl(categoryId)));
}

/// <summary>
Expand All @@ -39,8 +51,110 @@ public async Task<GetCategoryAttributesResponseModel> GetCategoryAttributesAsync
/// <param name="categoryId"><inheritdoc/></param>
/// <param name="attributeId"><inheritdoc/></param>
/// <returns><inheritdoc/></returns>
public async Task<GetCategoryAttributeValuesResponseModel> GetCategoryAttributeValuesAsync(int categoryId, string attributeId)
public async Task<HepsiburadaBaseResponseModel<List<GetCategoryAttributeValuesResponseModel>>> GetCategoryAttributeValuesAsync(int categoryId, string attributeId)
{
return await InvokeRequestAsync<GetCategoryAttributeValuesResponseModel>((client) => client.GetAsync(GetCategoryAttributeValueUrl(categoryId, attributeId)));
return await InvokeRequestAsync<HepsiburadaBaseResponseModel<List<GetCategoryAttributeValuesResponseModel>>>((client) => client.GetAsync(GetCategoryAttributeValueUrl(categoryId, attributeId)));
}

/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="rejectPrematchRequestModel"><inheritdoc/></param>
/// <returns><inheritdoc/></returns>
public async Task<HepsiburadaBaseResponseModel<RejectPrematchResponseModel>> GetCategoryAttributeValuesAsync(RejectPrematchRequestModel rejectPrematchRequestModel)
{
return await InvokeRequestAsync<RejectPrematchRequestModel, HepsiburadaBaseResponseModel<RejectPrematchResponseModel>>((client, requestBody) => client.PostAsync(GetRejectPrematchUrl(), requestBody), rejectPrematchRequestModel);
}

/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="createProductRequestModels"><inheritdoc/></param>
/// <returns><inheritdoc/></returns>
public async Task<HepsiburadaBaseResponseModel<CreateProductResponseModel>> CreateProductsAsync(BulkModel<CreateProductRequestModel> createProductRequestModels)
{
var requestString = JsonSerializer.Serialize(createProductRequestModels);
//Todo copy request string to json file
return await InvokeRequestAsync<BulkModel<CreateProductRequestModel>, HepsiburadaBaseResponseModel<CreateProductResponseModel>>((client, requestBody) => client.PostAsync(GetCreateProductUrl(), requestBody), createProductRequestModels);
}

/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="fastListingRequestModels"><inheritdoc/></param>
/// <returns><inheritdoc/></returns>
public async Task<HepsiburadaBaseResponseModel<List<FastListingResponseModel>>> FastListingAsync(BulkModel<FastListingRequestModel> fastListingRequestModels)
{
return await InvokeRequestAsync<BulkModel<FastListingRequestModel>, HepsiburadaBaseResponseModel<List<FastListingResponseModel>>>((client, requestBody) => client.PostAsync(GetFastListingUrl(), requestBody), fastListingRequestModels);
}

/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="checkProductStatusRequestModels"><inheritdoc/></param>
/// <returns><inheritdoc/></returns>
public async Task<HepsiburadaBaseResponseModel<CheckProductStatusResponseModel>> CheckProductStatusAsync(BulkModel<CheckProductStatusRequestModel> checkProductStatusRequestModels)
{
return await InvokeRequestAsync<BulkModel<CheckProductStatusRequestModel>, HepsiburadaBaseResponseModel<CheckProductStatusResponseModel>>((client, requestBody) => client.PostAsync(GetCheckProductStatusUrl(), requestBody), checkProductStatusRequestModels);
}

/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="approvePrematchRequestModels"><inheritdoc/></param>
/// <returns><inheritdoc/></returns>
public async Task<HepsiburadaBaseResponseModel<ApprovePrematchResponseModel>> ApprovePrematchAsync(BulkModel<ApprovePrematchRequestModel> approvePrematchRequestModels)
{
return await InvokeRequestAsync<BulkModel<ApprovePrematchRequestModel>, HepsiburadaBaseResponseModel<ApprovePrematchResponseModel>>((client, requestBody) => client.PostAsync(GetApprovePrematchUrl(), requestBody), approvePrematchRequestModels);
}

/// <summary>
/// <inheritdoc/>
/// </summary>
/// <returns><inheritdoc/></returns>
public async Task<HepsiburadaBaseResponseModel<List<GetTrackingIdHistoriesResponseModel>>> GetTrackingIdHistoryAsync()
{
return await InvokeRequestAsync<HepsiburadaBaseResponseModel<List<GetTrackingIdHistoriesResponseModel>>>((client) => client.GetAsync(GetTrackingIdHistoryUrl()));
}

/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="trackingId"><inheritdoc/></param>
/// <returns><inheritdoc/></returns>
public async Task<HepsiburadaBaseResponseModel<CheckProductStatusByTrackingIdResponseModel>> GetProductStatusByTrackingIdAsync(string trackingId)
{
return await InvokeRequestAsync<HepsiburadaBaseResponseModel<CheckProductStatusByTrackingIdResponseModel>>((client) => client.GetAsync(GetCheckProductStatusByTrackingIdUrl(trackingId)));
}

/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="merchantId"><inheritdoc/></param>
/// <param name="productStatus"><inheritdoc/></param>
/// <returns><inheritdoc/></returns>
public async Task<HepsiburadaBaseResponseModel<List<GetProductByStatusResponseModel>>> GetProductsByStatusAsync(string merchantId, string productStatus)
{
return await InvokeRequestAsync<HepsiburadaBaseResponseModel<List<GetProductByStatusResponseModel>>>((client) => client.GetAsync(GetProductsByStatusUrl(merchantId, productStatus)));
}

/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="trackingId"><inheritdoc/></param>
/// <returns><inheritdoc/></returns>
public async Task<HepsiburadaBaseResponseModel<CheckDeleteProductProcessResponseModel>> CheckDeleteProductProcessAsync(string trackingId)
{
return await InvokeRequestAsync<HepsiburadaBaseResponseModel<CheckDeleteProductProcessResponseModel>>((client) => client.GetAsync(GetCheckDeleteProductProcessUrl(trackingId)));
}

/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="merchantId"><inheritdoc/></param>
/// <returns><inheritdoc/></returns>
public async Task<HepsiburadaBaseResponseModel<List<GetMerchantProductResponseModel>>> GetMerchantProductsAsync(string merchantId)
{
return await InvokeRequestAsync<HepsiburadaBaseResponseModel<List<GetMerchantProductResponseModel>>>((client) => client.GetAsync(GetMerchatProductsUrl(merchantId)));
}
}
Loading

0 comments on commit 3654fe1

Please sign in to comment.