Added checking for customer ID and started creation of new customer ID.
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SimpleHttp;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace BodyshopPartner.Utils
|
||||
{
|
||||
@@ -20,21 +21,9 @@ namespace BodyshopPartner.Utils
|
||||
res.Close();
|
||||
}, "OPTIONS");
|
||||
|
||||
Route.Add("/qb/receivables", (req, res, props) =>
|
||||
{
|
||||
logger.Debug("/qb/receivables - POST");
|
||||
string AuthToken = req.Headers.Get("Authorization");
|
||||
string requestXML = ParseBody(req);
|
||||
logger.Trace("Incoming Request XML", requestXML);
|
||||
|
||||
//res.WithCORS();
|
||||
Utils.QuickBooksInterop.ConnectToQuickBooks();
|
||||
string result = Utils.QuickBooksInterop.processRequestFromQB(requestXML);
|
||||
Utils.QuickBooksInterop.DisconnectFromQuickBooks();
|
||||
|
||||
|
||||
res.WithCORS().AsText("Hello.");
|
||||
}, "POST");
|
||||
Route.Add("/qb/receivables",
|
||||
(req, res, props) => { HandleQbReceivables(req, res); }
|
||||
, "POST");
|
||||
|
||||
logger.Trace("Starting HTTP server...");
|
||||
|
||||
@@ -42,24 +31,58 @@ namespace BodyshopPartner.Utils
|
||||
HttpServer.ListenAsync(1337, System.Threading.CancellationToken.None, Route.OnHttpRequestAsync).Wait();
|
||||
}
|
||||
|
||||
public static string ParseBody(System.Net.HttpListenerRequest req)
|
||||
private static void HandleQbReceivables(System.Net.HttpListenerRequest req, System.Net.HttpListenerResponse res)
|
||||
{
|
||||
logger.Debug("/qb/receivables - POST");
|
||||
|
||||
string requestXMLstring = ParseBodyToString(req);
|
||||
XDocument requestXMLdoc = ParseStringToXml(requestXMLstring);
|
||||
|
||||
string CustomerId = QuickBooksInterop.CreateCustomerIfNotExist(requestXMLdoc);
|
||||
|
||||
|
||||
string InvoiceAddResponse = QuickBooksInterop.ProcessQBXmlRequest(requestXMLstring);
|
||||
|
||||
|
||||
string[] status = new string[3];
|
||||
if (InvoiceAddResponse != null) status = QuickBooksInterop.parseInvoiceAddRs(InvoiceAddResponse);
|
||||
|
||||
if (InvoiceAddResponse != null && status[0] == "0")
|
||||
{
|
||||
logger.Debug("Invoice added successfully.");
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Error("Error adding Invoice.\nStatus Code: {0} \nSeverity: {1} \nMessage {2}", status[0], status[1], status[2]);
|
||||
}
|
||||
res.WithCORS().AsText("Hello.");
|
||||
}
|
||||
|
||||
public static string ParseBodyToString(System.Net.HttpListenerRequest req)
|
||||
{
|
||||
System.IO.Stream body = req.InputStream;
|
||||
System.Text.Encoding encoding = req.ContentEncoding;
|
||||
System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding);
|
||||
if (req.ContentType != null)
|
||||
{
|
||||
Console.WriteLine("Client data content type {0}", req.ContentType);
|
||||
}
|
||||
Console.WriteLine("Client data content length {0}", req.ContentLength64);
|
||||
//if (req.ContentType != null)
|
||||
//{
|
||||
// Console.WriteLine("Client data content type {0}", req.ContentType);
|
||||
//}
|
||||
//Console.WriteLine("Client data content length {0}", req.ContentLength64);
|
||||
|
||||
Console.WriteLine("Start of client data:");
|
||||
//Console.WriteLine("Start of client data:");
|
||||
// Convert the data to a string and display it on the console.
|
||||
string s = reader.ReadToEnd();
|
||||
Console.WriteLine(s);
|
||||
Console.WriteLine("End of client data:");
|
||||
//Console.WriteLine(s);
|
||||
//Console.WriteLine("End of client data:");
|
||||
body.Close();
|
||||
return s;
|
||||
}
|
||||
|
||||
public static XDocument ParseStringToXml(string input)
|
||||
{
|
||||
return XDocument.Parse(input);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user