Skip to content

Commit

Permalink
Improve get PII
Browse files Browse the repository at this point in the history
  • Loading branch information
abuzuhri committed Nov 23, 2022
1 parent db98ab3 commit 803451e
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 16 deletions.
30 changes: 26 additions & 4 deletions Source/FikaAmazonAPI.SampleCode/OrdersSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,26 @@ public void GetOrders()
/// <summary>
/// You must have valid PII developer to be able to call this method
/// </summary>
public void GetOrdersPII()
public void GetOrdersPIISimple()
{
ParameterOrderList serachOrderList = new ParameterOrderList();
serachOrderList.CreatedAfter = DateTime.UtcNow.AddMinutes(-600000);

serachOrderList.OrderStatuses = new List<OrderStatuses>();
serachOrderList.OrderStatuses.Add(OrderStatuses.Pending);
serachOrderList.OrderStatuses.Add(OrderStatuses.Unshipped);

serachOrderList.AmazonOrderIds = new List<string>();
serachOrderList.AmazonOrderIds.Add("405-0426616-1636335");
//You must have valid PII developer to be able to call this
serachOrderList.IsNeedRestrictedDataToken = true;

var orders = amazonConnection.Orders.GetOrders(serachOrderList);
}
public void GetOrdersPIIAdvance()
{
ParameterOrderList serachOrderList = new ParameterOrderList();
serachOrderList.CreatedAfter = DateTime.UtcNow.AddMinutes(-600000);

serachOrderList.OrderStatuses = new List<OrderStatuses>();
serachOrderList.OrderStatuses.Add(OrderStatuses.Unshipped);

//You must have valid PII developer to be able to call this
var restrictedResource = new RestrictedResource();
Expand Down Expand Up @@ -100,6 +110,18 @@ public void GetOrderItems()
{
var Items = amazonConnection.Orders.GetOrderItems("402-0467973-4229120");
}

/// <summary>
/// You must have valid PII developer to be able to call this method
/// </summary>
public void GetOrderItemsPIISimple()
{
ParameterBasedPII parameterBasedPII = new ParameterBasedPII();
parameterBasedPII.IsNeedRestrictedDataToken = true;

var order = amazonConnection.Orders.GetOrderItems("405-0426616-1636335", parameterBasedPII);
}

/// <summary>
/// You must have valid PII developer to be able to call this method
/// </summary>
Expand Down
9 changes: 6 additions & 3 deletions Source/FikaAmazonAPI.SampleCode/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ static async Task Main(string[] args)
ClientSecret = config.GetSection("FikaAmazonAPI:ClientSecret").Value,
RefreshToken = config.GetSection("FikaAmazonAPI:RefreshToken").Value,
MarketPlace = MarketPlace.GetMarketPlaceByID(config.GetSection("FikaAmazonAPI:MarketPlaceID").Value),
IsDebugMode=true
IsDebugMode = true
});

OrdersSample ordersSample1 = new OrdersSample(amazonConnection);
ordersSample1.GetOrdersPIIAdvance();
ordersSample1.GetOrdersPIISimple();


var offfers = amazonConnection.ProductPricing.GetItemOffers(new Parameter.ProductPricing.ParameterGetItemOffers
{
Expand All @@ -51,8 +55,7 @@ static async Task Main(string[] args)
var dddd = amazonConnection.Seller.GetMarketplaceParticipations();

FeedsSample feedsSample = new FeedsSample(amazonConnection);
OrdersSample ordersSample1 = new OrdersSample(amazonConnection);
ordersSample1.GetOrdersPII();



ReportManager reportManageree = new ReportManager(amazonConnection);
Expand Down
6 changes: 3 additions & 3 deletions Source/FikaAmazonAPI/FikaAmazonAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<Product>CSharp Amazon Sp API</Product>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<LangVersion>8.0</LangVersion>
<Version>1.5.16</Version>
<AssemblyVersion>1.5.16</AssemblyVersion>
<FileVersion>1.5.16</FileVersion>
<Version>1.5.17</Version>
<AssemblyVersion>1.5.17</AssemblyVersion>
<FileVersion>1.5.17</FileVersion>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageProjectUrl>https://github.com/abuzuhri/Amazon-SP-API-CSharp</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
58 changes: 56 additions & 2 deletions Source/FikaAmazonAPI/Services/MerchantFulfillmentService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using FikaAmazonAPI.AmazonSpApiSDK.Models.MerchantFulfillment;
using FikaAmazonAPI.AmazonSpApiSDK.Models.Token;
using FikaAmazonAPI.Search;
using FikaAmazonAPI.Utils;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace FikaAmazonAPI.Services
Expand Down Expand Up @@ -43,6 +45,19 @@ public Shipment GetShipment(string shipmentId, IParameterBasedPII ParameterBased
Task.Run(() => GetShipmentAsync(shipmentId, ParameterBasedPII = null)).ConfigureAwait(false).GetAwaiter().GetResult();
public async Task<Shipment> GetShipmentAsync(string shipmentId, IParameterBasedPII ParameterBasedPII = null)
{
if (ParameterBasedPII != null && ParameterBasedPII.IsNeedRestrictedDataToken && ParameterBasedPII.RestrictedDataTokenRequest == null)
{
var restrictedResource = new RestrictedResource();
restrictedResource.method = Method.GET.ToString();
restrictedResource.path = MerchantFulfillmentApiUrls.GetShipment(shipmentId);

var createRDT = new CreateRestrictedDataTokenRequest()
{
restrictedResources = new List<RestrictedResource> { restrictedResource }
};
ParameterBasedPII.RestrictedDataTokenRequest = createRDT;
}

await CreateAuthorizedRequestAsync(MerchantFulfillmentApiUrls.GetShipment(shipmentId), RestSharp.Method.Get, parameter: ParameterBasedPII);

var response = await ExecuteRequestAsync<GetShipmentResponse>(RateLimitType.MerchantFulFillment_GetShipment);
Expand All @@ -54,6 +69,19 @@ public Shipment CancelShipment(string shipmentId, IParameterBasedPII parameterBa
Task.Run(() => CancelShipmentAsync(shipmentId, parameterBasedPII)).ConfigureAwait(false).GetAwaiter().GetResult();
public async Task<Shipment> CancelShipmentAsync(string shipmentId, IParameterBasedPII parameterBasedPII = null)
{
if (parameterBasedPII != null && parameterBasedPII.IsNeedRestrictedDataToken && parameterBasedPII.RestrictedDataTokenRequest == null)
{
var restrictedResource = new RestrictedResource();
restrictedResource.method = Method.DELETE.ToString();
restrictedResource.path = MerchantFulfillmentApiUrls.GetShipment(shipmentId);

var createRDT = new CreateRestrictedDataTokenRequest()
{
restrictedResources = new List<RestrictedResource> { restrictedResource }
};
parameterBasedPII.RestrictedDataTokenRequest = createRDT;
}

await CreateAuthorizedRequestAsync(MerchantFulfillmentApiUrls.GetShipment(shipmentId), RestSharp.Method.Delete, parameter: parameterBasedPII);

var response = await ExecuteRequestAsync<GetShipmentResponse>(RateLimitType.MerchantFulFillment_CancelShipment);
Expand All @@ -64,9 +92,22 @@ public async Task<Shipment> CancelShipmentAsync(string shipmentId, IParameterBas

public Shipment CancelShipmentOld(string shipmentId, IParameterBasedPII parameterBasedPII = null) =>
Task.Run(() => CancelShipmentOldAsync(shipmentId, parameterBasedPII)).ConfigureAwait(false).GetAwaiter().GetResult();
public async Task<Shipment> CancelShipmentOldAsync(string shipmentId, IParameterBasedPII ParameterBasedPII = null)
public async Task<Shipment> CancelShipmentOldAsync(string shipmentId, IParameterBasedPII parameterBasedPII = null)
{
await CreateAuthorizedRequestAsync(MerchantFulfillmentApiUrls.CancelShipmentOld(shipmentId), RestSharp.Method.Put, parameter: ParameterBasedPII);
if (parameterBasedPII != null && parameterBasedPII.IsNeedRestrictedDataToken && parameterBasedPII.RestrictedDataTokenRequest == null)
{
var restrictedResource = new RestrictedResource();
restrictedResource.method = Method.PUT.ToString();
restrictedResource.path = MerchantFulfillmentApiUrls.CancelShipmentOld(shipmentId);

var createRDT = new CreateRestrictedDataTokenRequest()
{
restrictedResources = new List<RestrictedResource> { restrictedResource }
};
parameterBasedPII.RestrictedDataTokenRequest = createRDT;
}

await CreateAuthorizedRequestAsync(MerchantFulfillmentApiUrls.CancelShipmentOld(shipmentId), RestSharp.Method.Put, parameter: parameterBasedPII);

var response = await ExecuteRequestAsync<GetShipmentResponse>(RateLimitType.MerchantFulFillment_CancelShipmentOld);
if (response != null && response.Payload != null)
Expand All @@ -78,6 +119,19 @@ public Shipment CreateShipment(CreateShipmentRequest createShipmentRequest, IPar
Task.Run(() => CreateShipmentAsync(createShipmentRequest, parameterBasedPII)).ConfigureAwait(false).GetAwaiter().GetResult();
public async Task<Shipment> CreateShipmentAsync(CreateShipmentRequest createShipmentRequest, IParameterBasedPII parameterBasedPII = null)
{
if (parameterBasedPII != null && parameterBasedPII.IsNeedRestrictedDataToken && parameterBasedPII.RestrictedDataTokenRequest == null)
{
var restrictedResource = new RestrictedResource();
restrictedResource.method = Method.POST.ToString();
restrictedResource.path = MerchantFulfillmentApiUrls.CreateShipment;

var createRDT = new CreateRestrictedDataTokenRequest()
{
restrictedResources = new List<RestrictedResource> { restrictedResource }
};
parameterBasedPII.RestrictedDataTokenRequest = createRDT;
}

await CreateAuthorizedRequestAsync(MerchantFulfillmentApiUrls.CreateShipment, RestSharp.Method.Post, postJsonObj: createShipmentRequest, parameter: parameterBasedPII);

var response = await ExecuteRequestAsync<CreateShipmentResponse>(RateLimitType.MerchantFulFillment_CreateShipment);
Expand Down
50 changes: 48 additions & 2 deletions Source/FikaAmazonAPI/Services/OrderService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FikaAmazonAPI.AmazonSpApiSDK.Models.Orders;
using FikaAmazonAPI.AmazonSpApiSDK.Models.Token;
using FikaAmazonAPI.Parameter.Order;
using FikaAmazonAPI.Search;
using System.Collections.Generic;
Expand All @@ -19,13 +20,30 @@ public OrderList GetOrders(ParameterOrderList searchOrderList) =>
Task.Run(() => GetOrdersAsync(searchOrderList)).ConfigureAwait(false).GetAwaiter().GetResult();
public async Task<OrderList> GetOrdersAsync(ParameterOrderList searchOrderList)
{

var orderList = new OrderList();

if (searchOrderList.MarketplaceIds == null || searchOrderList.MarketplaceIds.Count == 0)
{
searchOrderList.MarketplaceIds = new List<string>();
searchOrderList.MarketplaceIds.Add(AmazonCredential.MarketPlace.ID);
}

if (searchOrderList.IsNeedRestrictedDataToken && searchOrderList.RestrictedDataTokenRequest == null)
{
var restrictedResource = new RestrictedResource();
restrictedResource.method = Method.GET.ToString();
restrictedResource.path = OrdersApiUrls.Orders;
restrictedResource.dataElements = new List<string> { "buyerInfo", "shippingAddress" };


var createRDT = new CreateRestrictedDataTokenRequest()
{
restrictedResources = new List<RestrictedResource> { restrictedResource }
};
searchOrderList.RestrictedDataTokenRequest = createRDT;
}

var queryParameters = searchOrderList.getParameters();

await CreateAuthorizedRequestAsync(OrdersApiUrls.Orders, RestSharp.Method.Get, queryParameters, parameter: searchOrderList);
Expand Down Expand Up @@ -76,19 +94,47 @@ public Order GetOrder(ParameterGetOrder parameter) =>
Task.Run(() => GetOrderAsync(parameter)).ConfigureAwait(false).GetAwaiter().GetResult();
public async Task<Order> GetOrderAsync(ParameterGetOrder parameter)
{
if (parameter.IsNeedRestrictedDataToken && parameter.RestrictedDataTokenRequest == null)
{
var restrictedResource = new RestrictedResource();
restrictedResource.method = Method.GET.ToString();
restrictedResource.path = OrdersApiUrls.Order(parameter.OrderId);
restrictedResource.dataElements = new List<string> { "buyerInfo", "shippingAddress" };


var createRDT = new CreateRestrictedDataTokenRequest()
{
restrictedResources = new List<RestrictedResource> { restrictedResource }
};
parameter.RestrictedDataTokenRequest = createRDT;
}

await CreateAuthorizedRequestAsync(OrdersApiUrls.Order(parameter.OrderId), RestSharp.Method.Get, parameter: parameter);
var response = await ExecuteRequestAsync<GetOrderResponse>(Utils.RateLimitType.Order_GetOrder);
if (response != null && response.Payload != null)
return response.Payload;
else return null;
}


public OrderItemList GetOrderItems(string orderId, IParameterBasedPII parameterBasedPII = null) =>
Task.Run(() => GetOrderItemsAsync(orderId, parameterBasedPII)).ConfigureAwait(false).GetAwaiter().GetResult();
public async Task<OrderItemList> GetOrderItemsAsync(string orderId, IParameterBasedPII ParameterBasedPII = null)
{
var orderItemList = new OrderItemList();

if (ParameterBasedPII != null && ParameterBasedPII.IsNeedRestrictedDataToken && ParameterBasedPII.RestrictedDataTokenRequest == null)
{
var restrictedResource = new RestrictedResource();
restrictedResource.method = Method.GET.ToString();
restrictedResource.path = OrdersApiUrls.OrderItems(orderId);
restrictedResource.dataElements = new List<string> { "buyerInfo", "shippingAddress" };

var createRDT = new CreateRestrictedDataTokenRequest()
{
restrictedResources = new List<RestrictedResource> { restrictedResource }
};
ParameterBasedPII.RestrictedDataTokenRequest = createRDT;
}

await CreateAuthorizedRequestAsync(OrdersApiUrls.OrderItems(orderId), RestSharp.Method.Get, parameter: ParameterBasedPII);
var response = await ExecuteRequestAsync<GetOrderItemsResponse>(Utils.RateLimitType.Order_GetOrderItems);
var nextToken = response.Payload.NextToken;
Expand Down
4 changes: 2 additions & 2 deletions Source/FikaAmazonAPI/Services/RequestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ private void LogRequest(RestRequest request, RestResponse response)
responseUri = response.ResponseUri,
errorMessage = response.ErrorMessage,
};

Console.WriteLine(string.Format("Request completed, Request: {0}, Response: {1}",
Console.WriteLine("\n\n");
Console.WriteLine(string.Format("Request completed, \nRequest: {0} \n\nResponse: {1}",
JsonConvert.SerializeObject(requestToLog),
JsonConvert.SerializeObject(responseToLog)));
}
Expand Down

0 comments on commit 803451e

Please sign in to comment.