From 6a035dcdf43300ad4a356cc9573e42507d85a6ae Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Tue, 2 Jun 2020 16:41:56 -0700 Subject: [PATCH] Genericized QB response. --- BodyshopUploader/Utils/HTTPServer.cs | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/BodyshopUploader/Utils/HTTPServer.cs b/BodyshopUploader/Utils/HTTPServer.cs index d6e1c4b..8134683 100644 --- a/BodyshopUploader/Utils/HTTPServer.cs +++ b/BodyshopUploader/Utils/HTTPServer.cs @@ -18,15 +18,15 @@ namespace BodyshopPartner.Utils private static HttpLogger hlog; public static void InitHttpServer(HttpLogger HttpLogger) { - Route.Add("/qb/receivables", (req, res, props) => + Route.Add("/qb/", (req, res, props) => { res.WithCORS(); //res.AddHeader("Access-Control-Allow-Origin", "http://localhost:3000 https://localhost:3000 http://localhost:5000 https://localhost:5000 https://*.imex.online,imex.online"); res.Close(); }, "OPTIONS"); - Route.Add("/qb/receivables", - (req, res, props) => { HandleQbReceivables(req, res); } + Route.Add("/qb/", + (req, res, props) => { HandleQbPost(req, res); } , "POST"); logger.Trace("Starting HTTP server..."); @@ -36,9 +36,9 @@ namespace BodyshopPartner.Utils HttpServer.ListenAsync(1337, System.Threading.CancellationToken.None, Route.OnHttpRequestAsync).Wait(); } - private static void HandleQbReceivables(System.Net.HttpListenerRequest req, System.Net.HttpListenerResponse res) + private static void HandleQbPost(System.Net.HttpListenerRequest req, System.Net.HttpListenerResponse res) { - logger.Debug("/qb/receivables - POST"); + logger.Debug("/qb/ - POST"); //Input will be an array of XMLs. string[] requestXMLstrings = ParseBodyToArray(req); @@ -50,20 +50,13 @@ namespace BodyshopPartner.Utils XDocument requestXMLdoc = ParseStringToXml(requestXMLstring); XDocument response = XDocument.Parse(QuickBooksInterop.ProcessQBXmlRequest(requestXMLstring)); Models.QbXmlResponse ResponseStatus = QuickBooksInterop.ParseResponseXml(response); - - - logger.Info(response.ToString()); + logger.Info(response.ToString()); logger.Info(ResponseStatus.ToString()); hlog(ResponseStatus.ToString()); - //string[] status = new string[3]; - //if (InvoiceAddResponse != null) status = QuickBooksInterop.parseInvoiceAddRs(InvoiceAddResponse); - //if (InvoiceAddResponse != null && status[0] == "0") - //{ logger.Debug("Invoice added successfully."); res.StatusCode = 200; } - //else - //{ logger.Error("Error adding Invoice.\nStatus Code: {0} \nSeverity: {1} \nMessage {2}", status[0], status[1], status[2]); res.StatusCode = 400; } } - hlog("Completed QuickBooks Receivable request."); + + hlog("Completed QuickBooks request."); res.WithCORS().Close(); }