mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-21 15:27:15 +00:00
Feature repricing min max (#10)
amazon settlement import/export improvements
This commit is contained in:
@@ -8,12 +8,18 @@ namespace bnhtrade.Core.Data.AmazonMWS
|
||||
{
|
||||
public class CredentialMws
|
||||
{
|
||||
public string merchantId { get { return "A3RUYNKLWWM5KW"; } }
|
||||
public string marketPlaceId { get { return "A1F83G8C2ARO7P"; } } // Amazon.co.uk
|
||||
public string accessKeyId { get { return "AKIAJU45WSYVINEN45UA"; } }
|
||||
public string secretAccessKey { get { return "cpS3HnTYDIVxAPSxaJwCwUbeH6PGPnpij5Un5bWI"; } }
|
||||
public string applicationName { get { return "bnhtrade.Core"; } }
|
||||
public string applicationVersion { get { return "0.1"; } }
|
||||
public string serviceURL { get { return "https://mws.amazonservices.co.uk"; } }
|
||||
public string MerchantId { get { return "A3RUYNKLWWM5KW"; } }
|
||||
|
||||
public string MarketPlaceIdUK { get { return "A1F83G8C2ARO7P"; } } // Amazon.co.uk
|
||||
|
||||
public string AccessKeyId { get { return "AKIAJU45WSYVINEN45UA"; } }
|
||||
|
||||
public string SecretAccessKey { get { return "cpS3HnTYDIVxAPSxaJwCwUbeH6PGPnpij5Un5bWI"; } }
|
||||
|
||||
public string ApplicationName { get { return "bnhtrade.Core"; } }
|
||||
|
||||
public string ApplicationVersion { get { return "0.1"; } }
|
||||
|
||||
public string ServiceURL { get { return "https://mws.amazonservices.co.uk"; } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace bnhtrade.Core.Data.AmazonMWS.FBAInbound
|
||||
return LastUpdatedBefore != null;
|
||||
}
|
||||
|
||||
public List<Model.AmazonFBAInbound.ShipmentItemInfo> GetByAmazonShipmentId(string amazonShipmentId)
|
||||
public List<Model.AmazonFba.ShipmentItemInfo> GetByAmazonShipmentId(string amazonShipmentId)
|
||||
{
|
||||
// checks
|
||||
if (amazonShipmentId.Length < 9)
|
||||
@@ -43,7 +43,7 @@ namespace bnhtrade.Core.Data.AmazonMWS.FBAInbound
|
||||
return ListInboundShipmentItemsGet(request);
|
||||
}
|
||||
|
||||
public List<Model.AmazonFBAInbound.ShipmentItemInfo> GetByDates(DateTime lastUpdatedAfter, DateTime lastUpdatedBefore)
|
||||
public List<Model.AmazonFba.ShipmentItemInfo> GetByDates(DateTime lastUpdatedAfter, DateTime lastUpdatedBefore)
|
||||
{
|
||||
//checks
|
||||
if (lastUpdatedAfter >= lastUpdatedBefore)
|
||||
@@ -61,7 +61,7 @@ namespace bnhtrade.Core.Data.AmazonMWS.FBAInbound
|
||||
return ListInboundShipmentItemsGet(request);
|
||||
}
|
||||
|
||||
private List<Model.AmazonFBAInbound.ShipmentItemInfo> ListInboundShipmentItemsGet(ListInboundShipmentItemsRequest request)
|
||||
private List<Model.AmazonFba.ShipmentItemInfo> ListInboundShipmentItemsGet(ListInboundShipmentItemsRequest request)
|
||||
{
|
||||
// variables
|
||||
int mwsPollFrequency = 500;
|
||||
@@ -72,7 +72,7 @@ namespace bnhtrade.Core.Data.AmazonMWS.FBAInbound
|
||||
if (!request.IsSetSellerId())
|
||||
{
|
||||
var cred = new AmazonMWS.CredentialMws();
|
||||
request.SellerId = cred.merchantId;
|
||||
request.SellerId = cred.MerchantId;
|
||||
}
|
||||
|
||||
// checks
|
||||
@@ -108,7 +108,7 @@ namespace bnhtrade.Core.Data.AmazonMWS.FBAInbound
|
||||
}
|
||||
|
||||
// create the return list
|
||||
var returnList = new List<Model.AmazonFBAInbound.ShipmentItemInfo>();
|
||||
var returnList = new List<Model.AmazonFba.ShipmentItemInfo>();
|
||||
|
||||
// check a result was returned, return empty list on no results
|
||||
if (!result.IsSetItemData())
|
||||
@@ -171,7 +171,7 @@ namespace bnhtrade.Core.Data.AmazonMWS.FBAInbound
|
||||
// load data set into returnList
|
||||
foreach (var item in infoList)
|
||||
{
|
||||
var returnItem = new Model.AmazonFBAInbound.ShipmentItemInfo();
|
||||
var returnItem = new Model.AmazonFba.ShipmentItemInfo();
|
||||
returnItem.AmazonShipmentId = item.ShipmentId;
|
||||
returnItem.SKUNumber = item.SellerSKU;
|
||||
returnItem.AmazonFNSKU = item.FulfillmentNetworkSKU;
|
||||
|
||||
@@ -14,31 +14,37 @@ namespace bnhtrade.Core.Data.AmazonMWS.FBAInbound
|
||||
/// List of Shipment Status' to return. Default is all status' returned.
|
||||
/// </summary>
|
||||
public List<string> ShipmentStatusList { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// List of Shipment Id to return.
|
||||
/// </summary>
|
||||
public List<string> ShipmentIdList { get; set; }
|
||||
|
||||
public DateTime LastUpdatedAfter { get; set; }
|
||||
|
||||
public DateTime LastUpdatedBefore { get; set; }
|
||||
|
||||
public bool IsSetShipmentStatusList()
|
||||
{
|
||||
return ShipmentStatusList != null;
|
||||
}
|
||||
|
||||
public bool IsSetShipmentIdList()
|
||||
{
|
||||
return ShipmentIdList != null;
|
||||
}
|
||||
|
||||
public bool IsSetLastUpdatedAfter()
|
||||
{
|
||||
return LastUpdatedAfter != null;
|
||||
}
|
||||
|
||||
public bool IsSetLastUpdatedBefore()
|
||||
{
|
||||
return LastUpdatedBefore != null;
|
||||
}
|
||||
|
||||
public List<Core.Model.AmazonFBAInbound.ShipmentInfo> GetShipmentInfo()
|
||||
public List<Core.Model.AmazonFba.ShipmentInfo> GetShipmentInfo()
|
||||
{
|
||||
// variables
|
||||
int mwsPollFrequency = 500; // restore rate of two requests every second
|
||||
@@ -72,7 +78,7 @@ namespace bnhtrade.Core.Data.AmazonMWS.FBAInbound
|
||||
var request = new ListInboundShipmentsRequest();
|
||||
|
||||
var cred = new AmazonMWS.CredentialMws();
|
||||
request.SellerId = cred.merchantId;
|
||||
request.SellerId = cred.MerchantId;
|
||||
|
||||
// add shipment status to request
|
||||
if (!IsSetShipmentStatusList() && !IsSetShipmentIdList())
|
||||
@@ -204,12 +210,12 @@ namespace bnhtrade.Core.Data.AmazonMWS.FBAInbound
|
||||
}
|
||||
|
||||
// build return value
|
||||
var returnItem = new List<Core.Model.AmazonFBAInbound.ShipmentInfo>();
|
||||
var returnItem = new List<Core.Model.AmazonFba.ShipmentInfo>();
|
||||
//var lastUpdated = infoList.
|
||||
foreach( InboundShipmentInfo item in infoList)
|
||||
{
|
||||
var listItem = new Core.Model.AmazonFBAInbound.ShipmentInfo();
|
||||
listItem.AmazonShipmentId = item.ShipmentId;
|
||||
var listItem = new Core.Model.AmazonFba.ShipmentInfo();
|
||||
listItem.FbaShipmentId = item.ShipmentId;
|
||||
listItem.DestinationFulfillmentCenterId = item.DestinationFulfillmentCenterId;
|
||||
listItem.ShipmentName = item.ShipmentName;
|
||||
listItem.ShipmentStatus = item.ShipmentStatus;
|
||||
|
||||
135
src/bnhtrade.Core/Data/AmazonMWS/Feeds/GetFeedSubmissions.cs
Normal file
135
src/bnhtrade.Core/Data/AmazonMWS/Feeds/GetFeedSubmissions.cs
Normal file
@@ -0,0 +1,135 @@
|
||||
using MarketplaceWebService;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bnhtrade.Core.Data.AmazonMWS.Feeds
|
||||
{
|
||||
public class GetFeedSubmissions
|
||||
{
|
||||
private Logic.Log.LogEvent logEvent = new Logic.Log.LogEvent();
|
||||
|
||||
public List<string> FeedSubmissionIdList { get; set; } = new List<string>();
|
||||
|
||||
public int MaxCount { get; set; } = 100;
|
||||
|
||||
public List<MarketplaceWebService.Model.FeedSubmissionInfo> Invoke()
|
||||
{
|
||||
//build the request
|
||||
var cred = new AmazonMWS.CredentialMws();
|
||||
var request = new MarketplaceWebService.Model.GetFeedSubmissionListRequest();
|
||||
request.MaxCount = MaxCount;
|
||||
request.Merchant = cred.MerchantId;
|
||||
|
||||
if (FeedSubmissionIdList.Any())
|
||||
{
|
||||
var idList = new MarketplaceWebService.Model.IdList();
|
||||
idList.Id = FeedSubmissionIdList;
|
||||
request.FeedSubmissionIdList = idList;
|
||||
}
|
||||
|
||||
string error = "GetFeedSubmissionList failed: ";
|
||||
string errorLong = null;
|
||||
int i = 0;
|
||||
int loopMax = 100;
|
||||
|
||||
try
|
||||
{
|
||||
var service = new Data.AmazonMWS.Service().MarketPlaceWeb;
|
||||
|
||||
// set the return list
|
||||
var feedInfoList = new List<MarketplaceWebService.Model.FeedSubmissionInfo>();
|
||||
|
||||
string nextToken = null;
|
||||
while (i < loopMax)
|
||||
{
|
||||
i++;
|
||||
try
|
||||
{
|
||||
if (nextToken == null)
|
||||
{
|
||||
var responseList = service.GetFeedSubmissionList(request);
|
||||
if (responseList.IsSetGetFeedSubmissionListResult())
|
||||
{
|
||||
var getFeedListResult = responseList.GetFeedSubmissionListResult;
|
||||
feedInfoList = getFeedListResult.FeedSubmissionInfo;
|
||||
if (getFeedListResult.HasNext)
|
||||
{
|
||||
nextToken = getFeedListResult.NextToken;
|
||||
}
|
||||
else
|
||||
{
|
||||
return feedInfoList;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
errorLong = responseList.ToXML();
|
||||
throw new Exception("FeedSubmissionListResult was not set");
|
||||
}
|
||||
if (nextToken == null)
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
var requestToken = new MarketplaceWebService.Model.GetFeedSubmissionListByNextTokenRequest();
|
||||
requestToken.NextToken = nextToken;
|
||||
requestToken.Merchant = cred.MerchantId;
|
||||
|
||||
var responseList = service.GetFeedSubmissionListByNextToken(requestToken);
|
||||
if (responseList.IsSetGetFeedSubmissionListByNextTokenResult())
|
||||
{
|
||||
var getFeedListResult = responseList.GetFeedSubmissionListByNextTokenResult;
|
||||
feedInfoList.AddRange(getFeedListResult.FeedSubmissionInfo);
|
||||
if (getFeedListResult.HasNext)
|
||||
{
|
||||
nextToken = getFeedListResult.NextToken;
|
||||
}
|
||||
else
|
||||
{
|
||||
return feedInfoList;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
errorLong = responseList.ToXML();
|
||||
throw new Exception("FeedSubmissionListResult was not set");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (MarketplaceWebServiceException ex) when (ex.ErrorCode == "RequestThrottled")
|
||||
{
|
||||
if (nextToken == null) { MiscFunction.MwsThrottleWait(60); } // 10 intial requests, 1 restore every 45 seconds
|
||||
else { MiscFunction.MwsThrottleWait(5); } // 30 intial requests, 1 restore every 2 seconds
|
||||
}
|
||||
catch (MarketplaceWebServiceException ex)
|
||||
{
|
||||
errorLong = "Caught Exception: " + ex.Message +
|
||||
"\r\nResponse Status Code: " + ex.StatusCode +
|
||||
"\r\nError Code: " + ex.ErrorCode +
|
||||
"\r\nError Type: " + ex.ErrorType +
|
||||
"\r\nRequest ID: " + ex.RequestId +
|
||||
"\r\nResponseHeaderMetadata: " + ex.ResponseHeaderMetadata +
|
||||
"\r\nXML:\r\n" + ex.XML;
|
||||
|
||||
throw new Exception("MarketplaceWebServiceException");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = error + ex.Message;
|
||||
}
|
||||
|
||||
// should never get here
|
||||
if (i == loopMax)
|
||||
error += "Timeout";
|
||||
|
||||
logEvent.LogError(error, errorLong);
|
||||
throw new Exception(error);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
120
src/bnhtrade.Core/Data/AmazonMWS/Feeds/SubmitFeed.cs
Normal file
120
src/bnhtrade.Core/Data/AmazonMWS/Feeds/SubmitFeed.cs
Normal file
@@ -0,0 +1,120 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MarketplaceWebService;
|
||||
using bnhtrade.Core.Logic;
|
||||
|
||||
namespace bnhtrade.Core.Data.AmazonMWS.Feeds
|
||||
{
|
||||
public class SubmitFeed
|
||||
{
|
||||
private Logic.Log.LogEvent logEvent = new Logic.Log.LogEvent();
|
||||
|
||||
public bool FeedSubmissionRecived { get; set; } = false;
|
||||
|
||||
public SubmitFeed(Model.Export.AmazonFeedSubmission feedSubmission)
|
||||
{
|
||||
FeedSubmissionRecived = false;
|
||||
|
||||
var cred = new CredentialMws();
|
||||
var config = new MarketplaceWebService.MarketplaceWebServiceConfig();
|
||||
config.ServiceURL = cred.ServiceURL;
|
||||
|
||||
|
||||
var marketPlaceList = new MarketplaceWebService.Model.IdList();
|
||||
marketPlaceList.Id = new List<string> { cred.MarketPlaceIdUK };
|
||||
|
||||
var request = new MarketplaceWebService.Model.SubmitFeedRequest();
|
||||
request.MarketplaceIdList = marketPlaceList;
|
||||
request.Merchant = cred.MerchantId;
|
||||
request.FeedContent = feedSubmission.File.FileData;
|
||||
request.FeedType = feedSubmission.FeedType;
|
||||
request.ContentMD5 = feedSubmission.File.FileMD5base64;
|
||||
request.FeedContent.Position = 0;
|
||||
|
||||
var service = new Data.AmazonMWS.Service().MarketPlaceWeb;
|
||||
|
||||
bool repeat = true;
|
||||
var response = new MarketplaceWebService.Model.SubmitFeedResponse();
|
||||
|
||||
// try for a response
|
||||
while (repeat)
|
||||
{
|
||||
try
|
||||
{
|
||||
response = service.SubmitFeed(request);
|
||||
repeat = false;
|
||||
}
|
||||
catch (MarketplaceWebServiceException ex) when (ex.ErrorCode == "RequestThrottled")
|
||||
{
|
||||
MiscFunction.MwsThrottleWait(150); // 15 inital requests, restore 1 every 2 minutes
|
||||
}
|
||||
catch (MarketplaceWebService.MarketplaceWebServiceException ex)
|
||||
{
|
||||
string errorLong = "Caught Exception: " + ex.Message + Environment.NewLine
|
||||
+ "Response Status Code: " + ex.StatusCode + Environment.NewLine
|
||||
+ "Error Code: " + ex.ErrorCode + Environment.NewLine
|
||||
+ "Error Type: " + ex.ErrorType + Environment.NewLine
|
||||
+ "Request ID: " + ex.RequestId + Environment.NewLine
|
||||
+ "XML: " + Environment.NewLine + ex.XML + Environment.NewLine
|
||||
+ "ResponseHeaderMetadata: " + ex.ResponseHeaderMetadata + Environment.NewLine;
|
||||
|
||||
logEvent.LogError("Unhandled MarketplaceWebServiceException while running InvokeSubmitFeed", errorLong);
|
||||
throw new Exception("Unhandled MarketplaceWebServiceException while running InvokeSubmitFeed");
|
||||
}
|
||||
}
|
||||
|
||||
// test the response
|
||||
if (response.IsSetSubmitFeedResult())
|
||||
{
|
||||
MarketplaceWebService.Model.SubmitFeedResult submitFeedResult = response.SubmitFeedResult;
|
||||
|
||||
if (submitFeedResult.IsSetFeedSubmissionInfo())
|
||||
{
|
||||
MarketplaceWebService.Model.FeedSubmissionInfo feedSubmissionInfo = submitFeedResult.FeedSubmissionInfo;
|
||||
if (feedSubmissionInfo.IsSetFeedSubmissionId())
|
||||
{
|
||||
feedSubmission.FeedSubmissionId = feedSubmissionInfo.FeedSubmissionId;
|
||||
FeedSubmissionRecived = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
logEvent.LogError("Response from MWS SubmitFeed did not contain a 'FeedSubmissionId'", submitFeedResult.ToString());
|
||||
return;
|
||||
}
|
||||
if (feedSubmissionInfo.IsSetFeedProcessingStatus())
|
||||
{
|
||||
feedSubmission.FeedProcessingStatus = feedSubmissionInfo.FeedProcessingStatus;
|
||||
}
|
||||
if (feedSubmissionInfo.IsSetCompletedProcessingDate())
|
||||
{
|
||||
feedSubmission.CompletedProcessingDate = DateTime.SpecifyKind(feedSubmissionInfo.CompletedProcessingDate, DateTimeKind.Utc);
|
||||
}
|
||||
if (feedSubmissionInfo.IsSetStartedProcessingDate())
|
||||
{
|
||||
feedSubmission.StartedProcessingDate = DateTime.SpecifyKind(feedSubmissionInfo.StartedProcessingDate, DateTimeKind.Utc);
|
||||
}
|
||||
if (feedSubmissionInfo.IsSetSubmittedDate())
|
||||
{
|
||||
if (feedSubmissionInfo.SubmittedDate != null)
|
||||
{
|
||||
feedSubmission.SubmittedDate = DateTime.SpecifyKind(DateTime.Parse(feedSubmissionInfo.SubmittedDate), DateTimeKind.Utc);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logEvent.LogError("Response from MWS SubmitFeed did not contain a 'FeedSubmissionInfo'", response.ToXML());
|
||||
throw new Exception("Request FeedSubmissionInfo not set."); // no idea what to do here, what happened, has it been submitted?
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logEvent.LogError("Response from MWS SubmitFeed did not contain a 'SubmitFeedResult'", response.ToXML());
|
||||
throw new Exception("Request SubmitFeedResult not set."); // no idea what to do here, what happened, has it been submitted?
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,17 +25,16 @@ namespace bnhtrade.Core.Data.AmazonMWS
|
||||
{
|
||||
var cred = new AmazonMWS.CredentialMws();
|
||||
|
||||
this.merchantId = cred.merchantId;
|
||||
this.marketplaceId = cred.marketPlaceId;
|
||||
this.accessKeyId = cred.accessKeyId;
|
||||
this.secretAccessKey = cred.secretAccessKey;
|
||||
this.applicationName = cred.applicationName;
|
||||
this.applicationVersion = cred.applicationVersion;
|
||||
this.serviceURL = cred.serviceURL;
|
||||
this.merchantId = cred.MerchantId;
|
||||
this.marketplaceId = cred.MarketPlaceIdUK;
|
||||
this.accessKeyId = cred.AccessKeyId;
|
||||
this.secretAccessKey = cred.SecretAccessKey;
|
||||
this.applicationName = cred.ApplicationName;
|
||||
this.applicationVersion = cred.ApplicationVersion;
|
||||
this.serviceURL = cred.ServiceURL;
|
||||
}
|
||||
|
||||
public MarketplaceWebService.MarketplaceWebService MarketPlaceWeb
|
||||
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user