Genericized QB response.

This commit is contained in:
Patrick Fic
2020-06-02 16:41:56 -07:00
parent 9e39d42410
commit 6a035dcdf4

View File

@@ -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();
}