Added models for qb request and responses to communicate with web app.
This commit is contained in:
@@ -8,6 +8,7 @@ using System.Xml.Linq;
|
||||
using Newtonsoft;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using BodyshopPartner.Models;
|
||||
|
||||
namespace BodyshopPartner.Utils
|
||||
{
|
||||
@@ -38,26 +39,48 @@ namespace BodyshopPartner.Utils
|
||||
|
||||
private static void HandleQbPost(System.Net.HttpListenerRequest req, System.Net.HttpListenerResponse res)
|
||||
{
|
||||
logger.Debug("/qb/ - POST");
|
||||
//Input will be an array of XMLs.
|
||||
|
||||
string[] requestXMLstrings = ParseBodyToArray(req);
|
||||
logger.Trace("/qb/ - POST");
|
||||
hlog("Received QuickBooks Receivable request.");
|
||||
//Input will be an array of objects containing XMLs.
|
||||
|
||||
List<QbRequestItem> AllRequests = ParseRequest(req);
|
||||
List<QbResponseItem> HttpResponse = new List<QbResponseItem>();
|
||||
|
||||
// string requestXMLstring = ParseBodyToString(req);
|
||||
foreach (var requestXMLstring in requestXMLstrings)
|
||||
foreach (QbRequestItem request in AllRequests)
|
||||
{
|
||||
XDocument requestXMLdoc = ParseStringToXml(requestXMLstring);
|
||||
XDocument response = XDocument.Parse(QuickBooksInterop.ProcessQBXmlRequest(requestXMLstring));
|
||||
Models.QbXmlResponse ResponseStatus = QuickBooksInterop.ParseResponseXml(response);
|
||||
logger.Info(response.ToString());
|
||||
logger.Info(ResponseStatus.ToString());
|
||||
XDocument response = XDocument.Parse(QuickBooksInterop.ProcessQBXmlRequest(request.QbXML));
|
||||
QbXmlResponse ResponseStatus = QuickBooksInterop.ParseResponseXml(response);
|
||||
|
||||
logger.Trace(response.ToString());
|
||||
logger.Debug(ResponseStatus.ToString());
|
||||
hlog(ResponseStatus.ToString());
|
||||
|
||||
QbResponseItem r = new QbResponseItem()
|
||||
{
|
||||
Id = request.Id,
|
||||
Success = ResponseStatus.StatusCode == "0" || request.OkStatusCodes.Contains(ResponseStatus.StatusCode),
|
||||
ErrorMessage = ResponseStatus.StatusMessage
|
||||
};
|
||||
|
||||
HttpResponse.Add(r);
|
||||
}
|
||||
|
||||
hlog("Completed QuickBooks request.");
|
||||
res.WithCORS().Close();
|
||||
|
||||
res.WithCORS().AsText(JsonConvert.SerializeObject(HttpResponse));
|
||||
}
|
||||
|
||||
public static List<QbRequestItem> ParseRequest(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);
|
||||
string s = reader.ReadToEnd();
|
||||
body.Close();
|
||||
reader.Close();
|
||||
|
||||
return JsonConvert.DeserializeObject<List<QbRequestItem>>(s);
|
||||
}
|
||||
|
||||
public static string[] ParseBodyToArray(System.Net.HttpListenerRequest req)
|
||||
|
||||
Reference in New Issue
Block a user