Migration from Amazon MWS to Selling Partner API

This commit is contained in:
Bobbie Hodgetts
2024-04-11 12:26:13 +01:00
committed by GitHub
parent e054278cdd
commit a7bc00e73a
1318 changed files with 2778105 additions and 5936 deletions

View File

@@ -1,19 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="bnhtradeDbConnString" connectionString="Data Source=SQL-Server;Initial Catalog=e2A;Persist Security Info=TRUE;User ID=e2A Client;Password=eSYH4EYoK6Guc5KIclhgFDlGc4;MultipleActiveResultSets=TRUE" />
</connectionStrings>
<appSettings configSource="app.local.config" />
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1" />
</startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="RestSharp" publicKeyToken="598062e77f915f75" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-106.13.0.0" newVersion="106.13.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.2" newVersion="7.0.0.2" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
</configuration>

View File

@@ -15,7 +15,27 @@ namespace bnhtradeScheduledTasks
{
class Program
{
static string sqlConnectionString = ConfigurationManager.ConnectionStrings["bnhtradeDbConnString"].ConnectionString;
static private bnhtrade.Core.Model.Credentials.bnhtradeDB dbCredentials;
static private bnhtrade.Core.Model.Credentials.AmazonSPAPI spapiCredentials;
static Program()
{
dbCredentials = new bnhtrade.Core.Model.Credentials.bnhtradeDB(
ConfigurationManager.AppSettings["DbDataSource"]
, ConfigurationManager.AppSettings["DbUserId"]
, ConfigurationManager.AppSettings["DbUserPassword"]
);
spapiCredentials = new bnhtrade.Core.Model.Credentials.AmazonSPAPI(
ConfigurationManager.AppSettings["SpapiAccessKey"]
, ConfigurationManager.AppSettings["SpapiSecretKey"]
, ConfigurationManager.AppSettings["SpapiRoleArn"]
, ConfigurationManager.AppSettings["SpapiClientId"]
, ConfigurationManager.AppSettings["SpapiClientSecret"]
, ConfigurationManager.AppSettings["SpapiRefreshToken"]
);
}
//public static string BNHtradeDbConnectionString()
//{
// return ConfigurationManager.ConnectionStrings["bnhtradeDbConnString"].ConnectionString;
@@ -84,73 +104,64 @@ namespace bnhtradeScheduledTasks
else if (input == "1")
{
Console.Clear();
DownloadAll();
new bnhtrade.Core.Logic.Utilities.NightlyRoutine(spapiCredentials, dbCredentials).DownloadAll();
Console.WriteLine("Complete, press any key to continue...");
Console.ReadKey();
}
else if (input == "2")
{
Console.Clear();
var task = new AmazonReport();
task.UpdateFbaInventoryData(sqlConnectionString);
new bnhtrade.Core.Logic.Import.AmazonFbaInventory().SyncDatabaseWithAmazon();
Console.WriteLine("Complete, press any key to continue...");
Console.ReadKey();
}
else if (input == "3")
{
Console.Clear();
var task = new AmazonReport();
task.UpdateFbaInventoryAgeData(sqlConnectionString);
new bnhtrade.Core.Logic.Import.AmazonFbaInventoryAge().SyncDatabaseWithAmazon();
Console.WriteLine("Complete, press any key to continue...");
Console.ReadKey();
}
else if (input == "4")
{
Console.Clear();
var task = new AmazonReport();
var task2 = new bnhtrade.Core.Logic.Export.AmazonSettlement(sqlConnectionString);
task.UpdateAmazonSettlementData(sqlConnectionString);
task2.ToInvoice();
new bnhtrade.Core.Logic.Import.AmazonSettlement(spapiCredentials).SyncDatabase(dbCredentials.ConnectionString);
new bnhtrade.Core.Logic.Export.AmazonSettlement(dbCredentials.ConnectionString).ToInvoice();
Console.WriteLine("Complete, press any key to continue...");
Console.ReadKey();
}
else if (input == "5")
{
Console.Clear();
var task = new AmazonReport();
task.UpdateFbaInventoryReceiptData(sqlConnectionString);
new bnhtrade.Core.Logic.Import.AmazonFbaInventoryReceipt().SyncDatabaseWithAmazon();
Console.WriteLine("Complete, press any key to continue...");
Console.ReadKey();
}
else if (input == "6")
{
Console.Clear();
var task = new AmazonReport();
task.UpdateFbaSaleShipmentData(sqlConnectionString);
new bnhtrade.Core.Logic.Import.AmazonFbaSaleShipment().SyncDatabaseWithAmazon();
Console.WriteLine("Complete, press any key to continue...");
Console.ReadKey();
}
else if (input == "7")
{
Console.Clear();
var task = new AmazonReport();
task.UpdateFbaReturnData(sqlConnectionString);
new bnhtrade.Core.Logic.Import.AmazonFbaCustomerReturn().SyncDatabaseWithAmazon();
Console.WriteLine("Complete, press any key to continue...");
Console.ReadKey();
}
else if (input == "8")
{
Console.Clear();
var task = new AmazonReport();
task.UpdateFbaAdustmentData(sqlConnectionString);
new bnhtrade.Core.Logic.Import.AmazonFbaInventoryAdjustment().SyncDatabaseWithAmazon();
Console.WriteLine("Complete, press any key to continue...");
Console.ReadKey();
}
else if (input == "9")
{
Console.Clear();
var task = new AmazonReport();
task.UpdateFbaRemovalOrderReport(sqlConnectionString);
new bnhtrade.Core.Logic.Import.AmazonFbaRemovalOrder().SyncDatabaseWithAmazon();
Console.WriteLine("Complete, press any key to continue...");
Console.ReadKey();
}
@@ -188,7 +199,7 @@ namespace bnhtradeScheduledTasks
var task = new StockReconciliation();
try
{
task.UpdateFbaStockImportData(sqlConnectionString);
task.UpdateFbaStockImportData(dbCredentials.ConnectionString);
}
catch (Exception ex)
{
@@ -203,7 +214,7 @@ namespace bnhtradeScheduledTasks
var task = new StockReconciliation();
try
{
task.ProcessFbaStockImportData(sqlConnectionString);
task.ProcessFbaStockImportData(dbCredentials.ConnectionString);
}
catch (Exception ex)
{
@@ -217,7 +228,7 @@ namespace bnhtradeScheduledTasks
Console.Clear();
//try
//{
var recon = new bnhtrade.Core.Logic.Stock.SkuTransactionReconcile(sqlConnectionString);
var recon = new bnhtrade.Core.Logic.Stock.SkuTransactionReconcile(dbCredentials.ConnectionString);
recon.ReconcileStockTransactions(false);
Console.WriteLine(recon.ItemsCompleted + " of " + (recon.ItemsCompleted + recon.ItemsRemaining) + " items completed.");
Console.WriteLine("Current transaction ID=" + recon.CurrentSkuTransaction.SkuTransactionId);
@@ -237,9 +248,9 @@ namespace bnhtradeScheduledTasks
var task = new StockReconciliation();
try
{
task.UpdateFbaStockImportData(sqlConnectionString);
task.ProcessFbaStockImportData(sqlConnectionString);
new bnhtrade.Core.Logic.Stock.SkuTransactionReconcile(sqlConnectionString).ReconcileStockTransactions(false);
task.UpdateFbaStockImportData(dbCredentials.ConnectionString);
task.ProcessFbaStockImportData(dbCredentials.ConnectionString);
new bnhtrade.Core.Logic.Stock.SkuTransactionReconcile(dbCredentials.ConnectionString).ReconcileStockTransactions(false);
}
catch (Exception ex)
{
@@ -271,7 +282,7 @@ namespace bnhtradeScheduledTasks
else if (input == "8")
{
Console.Clear();
DownloadAll();
new bnhtrade.Core.Logic.Utilities.NightlyRoutine(spapiCredentials, dbCredentials).DownloadAll();
Console.WriteLine("Complete, press any key to continue...");
Console.ReadKey();
}
@@ -283,7 +294,7 @@ namespace bnhtradeScheduledTasks
Console.WriteLine(consoleHeader);
Console.WriteLine("Main Menu > Dev Funcions");
Console.WriteLine();
Console.WriteLine("<1> Get Amazon UTC time");
Console.WriteLine("<1> Test some randon function I've set here");
Console.WriteLine("<2> Test Account");
Console.WriteLine("<3> Test Export");
Console.WriteLine("<4> Test Import");
@@ -292,6 +303,7 @@ namespace bnhtradeScheduledTasks
Console.WriteLine("<7> Test Stock");
Console.WriteLine("<8> Test AmazonMWS Report");
Console.WriteLine("<9> Test Log");
Console.WriteLine("<a> Test SP-API Fulfilment Inbound");
Console.WriteLine();
Console.WriteLine("<0> Back");
Console.WriteLine("");
@@ -306,8 +318,7 @@ namespace bnhtradeScheduledTasks
{
Console.Clear();
var task = new bnhtrade.Core.Data.AmazonMWS.CurrentDateTime();
task.GetUtc();
var obj = new bnhtrade.Core.Test.Amazon.SP_API.VariousCalls();
Console.WriteLine("Complete, press any key to continue...");
Console.ReadKey();
@@ -316,7 +327,7 @@ namespace bnhtradeScheduledTasks
{
Console.Clear();
new bnhtrade.Core.Test.Account.Account(sqlConnectionString);
new bnhtrade.Core.Test.Account.Account(dbCredentials.ConnectionString);
Console.WriteLine("Done");
Console.WriteLine("Complete, press any key to continue...");
@@ -326,7 +337,7 @@ namespace bnhtradeScheduledTasks
{
Console.Clear();
new bnhtrade.Core.Test.Export.Export(sqlConnectionString);
//new bnhtrade.Core.Test.Export.Export(dbCredentials.ConnectionString);
Console.WriteLine("Done");
Console.WriteLine("Complete, press any key to continue...");
@@ -336,7 +347,7 @@ namespace bnhtradeScheduledTasks
{
Console.Clear();
new bnhtrade.Core.Test.Import.Import(sqlConnectionString);
new bnhtrade.Core.Test.Import.Report(dbCredentials, spapiCredentials);
Console.WriteLine("Done");
Console.WriteLine("Complete, press any key to continue...");
@@ -346,7 +357,7 @@ namespace bnhtradeScheduledTasks
{
Console.Clear();
new bnhtrade.Core.Test.Logic.Logic(sqlConnectionString);
new bnhtrade.Core.Test.Logic.Logic(dbCredentials.ConnectionString);
Console.WriteLine("Done");
Console.WriteLine("Complete, press any key to continue...");
@@ -356,7 +367,7 @@ namespace bnhtradeScheduledTasks
{
Console.Clear();
new bnhtrade.Core.Logic.Sku.Price.FbaPricing(sqlConnectionString).Update();
new bnhtrade.Core.Logic.Sku.Price.FbaPricing(dbCredentials.ConnectionString).Update();
Console.WriteLine("Done");
Console.WriteLine("Complete, press any key to continue...");
@@ -366,7 +377,7 @@ namespace bnhtradeScheduledTasks
{
Console.Clear();
new bnhtrade.Core.Test.Stock.Stock(sqlConnectionString);
new bnhtrade.Core.Test.Stock.Stock(dbCredentials.ConnectionString);
Console.WriteLine("Done");
Console.WriteLine("Complete, press any key to continue...");
@@ -376,7 +387,7 @@ namespace bnhtradeScheduledTasks
{
Console.Clear();
new bnhtrade.Core.Test.AmazonMWS.Report(sqlConnectionString);
new bnhtrade.Core.Test.Amazon.MWS.Report(dbCredentials.ConnectionString);
Console.WriteLine("Done");
Console.WriteLine("Complete, press any key to continue...");
@@ -387,13 +398,23 @@ namespace bnhtradeScheduledTasks
Console.Clear();
var timeeee = new DateTime(2014, 9, 1);
var logdate = new bnhtrade.Core.Data.Database.Log.DateTimeLog(sqlConnectionString);
var logdate = new bnhtrade.Core.Data.Database.Log.DateTimeLog();
logdate.NewDateTimeUtc("_GET_AMAZON_FULFILLED_SHIPMENTS_DATA_", timeeee);
logdate.NewDateTimeUtc("_GET_FBA_FULFILLMENT_CUSTOMER_RETURNS_DATA_", timeeee);
logdate.NewDateTimeUtc("_GET_FBA_FULFILLMENT_INVENTORY_ADJUSTMENTS_DATA_", timeeee);
logdate.NewDateTimeUtc("_GET_FBA_REIMBURSEMENTS_DATA_", timeeee);
logdate.NewDateTimeUtc("_GET_FBA_FULFILLMENT_REMOVAL_ORDER_DETAIL_DATA_", timeeee);
Console.WriteLine("Done");
Console.WriteLine("Complete, press any key to continue...");
Console.ReadKey();
}
else if (input == "a")
{
Console.Clear();
new bnhtrade.Core.Test.Amazon.SP_API.FulfillmentInboundV0();
Console.WriteLine("Done");
Console.WriteLine("Complete, press any key to continue...");
Console.ReadKey();
@@ -416,7 +437,7 @@ namespace bnhtradeScheduledTasks
Console.WriteLine("Starting all reports download...");
Thread.Sleep(3000);
Console.Clear();
DownloadAll();
new bnhtrade.Core.Logic.Utilities.NightlyRoutine(spapiCredentials, dbCredentials).DownloadAll();
Console.WriteLine("Finished!! Exiting application...");
Thread.Sleep(3000);
}
@@ -425,7 +446,7 @@ namespace bnhtradeScheduledTasks
Console.WriteLine("Starting (unsafe) stock reconciliation...");
Console.Clear();
StockReconciliation task = new StockReconciliation();
var recon = new bnhtrade.Core.Logic.Stock.SkuTransactionReconcile(sqlConnectionString);
var recon = new bnhtrade.Core.Logic.Stock.SkuTransactionReconcile(dbCredentials.ConnectionString);
recon.ReconcileStockTransactions(false);
Console.WriteLine("Progress: " + recon.ProgressMessage);
Console.WriteLine("Reconciled date: " + recon.LastItemDateTime.ToString());
@@ -446,44 +467,5 @@ namespace bnhtradeScheduledTasks
Environment.Exit(0);
}
}
private static void DownloadAll()
{
MiscFunction.EventLogInsert("Nightly scheduled tasks started.");
var account = new AmazonReport();
var stock = new StockReconciliation();
var export = new bnhtrade.Core.Logic.Export.AmazonSettlement(sqlConnectionString);
bool accountUpdate = false;
bool stockUpdate = false;
bool accountProcess = false;
bool stockProcess = false;
while (true)
{
try
{
if (accountUpdate == false) { accountUpdate = true; account.UpdateAmazonSettlementData(sqlConnectionString); }
if (accountProcess == false) { accountProcess = true; export.ToInvoice(); }
if (stockUpdate == false) { stockUpdate = true; stock.UpdateFbaStockImportData(sqlConnectionString); }
// if (stockProcess == false) { stockProcess = true; stock.ProcessFbaStockImportData(); }
// ^^^^^^ best to process manually, case, fba inventory recepts, if a correction is made days later (ie -1) the already incorrect value
// will have been entered in the stocktransaction table and maked as processed in the inventoryreceipt table
break;
}
catch (Exception ex)
{
MiscFunction.EventLogInsert(
"Exception caught running all report get method, see for further details",
1,
ex.ToString()
);
}
}
MiscFunction.EventLogInsert("Nightly scheduled tasks finished.");
}
}
}

View File

@@ -22,28 +22,5 @@ namespace bnhtrade_Scheduled_Tasks.Properties {
return defaultInstance;
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.ConnectionString)]
[global::System.Configuration.DefaultSettingValueAttribute("Data Source=SQL-Server;Initial Catalog=e2A;Persist Security Info=TRUE;User ID=e2A" +
" Client;Password=eSYH4EYoK6Guc5KIclhgFDlGc4;MultipleActiveResultSets=TRUE")]
public string bnhtradeDbConnString {
get {
return ((string)(this["bnhtradeDbConnString"]));
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string bnhtradeDb {
get {
return ((string)(this["bnhtradeDb"]));
}
set {
this["bnhtradeDb"] = value;
}
}
}
}

View File

@@ -1,13 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="bnhtrade_Scheduled_Tasks.Properties" GeneratedClassName="Settings">
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles />
<Settings>
<Setting Name="bnhtradeDbConnString" Type="(Connection string)" Scope="Application">
<DesignTimeValue Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;SerializableConnectionString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
&lt;ConnectionString&gt;Data Source=SQL-Server;Initial Catalog=e2A;Persist Security Info=TRUE;User ID=e2A Client;Password=eSYH4EYoK6Guc5KIclhgFDlGc4;MultipleActiveResultSets=TRUE&lt;/ConnectionString&gt;
&lt;/SerializableConnectionString&gt;</DesignTimeValue>
<Value Profile="(Default)">Data Source=SQL-Server;Initial Catalog=e2A;Persist Security Info=TRUE;User ID=e2A Client;Password=eSYH4EYoK6Guc5KIclhgFDlGc4;MultipleActiveResultSets=TRUE</Value>
</Setting>
</Settings>
<Settings />
</SettingsFile>

View File

@@ -9,7 +9,7 @@
<OutputType>Exe</OutputType>
<RootNamespace>bnhtrade_Scheduled_Tasks</RootNamespace>
<AssemblyName>bnhtradeScheduledTasks</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<PublishUrl>publish\</PublishUrl>
@@ -29,6 +29,7 @@
<BootstrapperEnabled>true</BootstrapperEnabled>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -75,6 +76,9 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="app.local.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>