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
+61 -79
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.");
}
}
}