Added logging + array based processing.
This commit is contained in:
@@ -71,113 +71,49 @@ namespace BodyshopPartner.Utils
|
||||
}
|
||||
}
|
||||
|
||||
public static string[] parseInvoiceAddRs(string xml)
|
||||
public static Models.QbXmlResponse ParseResponseXml(XDocument response)
|
||||
{
|
||||
string[] retVal = new string[3];
|
||||
try
|
||||
XElement QueryResponse = response.Root.Descendants("QBXMLMsgsRs").Descendants().FirstOrDefault();
|
||||
XAttribute StatusCode = QueryResponse.Attribute("statusCode");
|
||||
XAttribute StatusSeverity = QueryResponse.Attribute("statusSeverity");
|
||||
XAttribute statusMessage = QueryResponse.Attribute("statusMessage");
|
||||
|
||||
return new Models.QbXmlResponse()
|
||||
{
|
||||
XmlNodeList RsNodeList = null;
|
||||
XmlDocument Doc = new XmlDocument();
|
||||
Doc.LoadXml(xml);
|
||||
RsNodeList = Doc.GetElementsByTagName("InvoiceAddRs");
|
||||
XmlAttributeCollection rsAttributes = RsNodeList.Item(0).Attributes;
|
||||
XmlNode statusCode = rsAttributes.GetNamedItem("statusCode");
|
||||
retVal[0] = Convert.ToString(statusCode.Value);
|
||||
XmlNode statusSeverity = rsAttributes.GetNamedItem("statusSeverity");
|
||||
retVal[1] = Convert.ToString(statusSeverity.Value);
|
||||
XmlNode statusMessage = rsAttributes.GetNamedItem("statusMessage");
|
||||
retVal[2] = Convert.ToString(statusMessage.Value);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.Error("Error encountered when parsing Invoice info returned from QuickBooks: " + e.Message);
|
||||
retVal = null;
|
||||
}
|
||||
return retVal;
|
||||
StatusCode = System.Text.RegularExpressions.Regex.Unescape(StatusCode.Value),
|
||||
StatusMessage = System.Text.RegularExpressions.Regex.Unescape(statusMessage.Value),
|
||||
StatusSeverity = System.Text.RegularExpressions.Regex.Unescape(StatusSeverity.Value),
|
||||
ResponseType = System.Text.RegularExpressions.Regex.Unescape(QueryResponse.Name.LocalName),
|
||||
Response = response
|
||||
};
|
||||
//response.
|
||||
}
|
||||
|
||||
public static string CreateCustomerIfNotExist(XDocument requestXML)
|
||||
{
|
||||
string ListID = ParseCustomerId(requestXML);
|
||||
if (string.IsNullOrEmpty(ListID))
|
||||
//Could be null or exist, we need to check.
|
||||
{
|
||||
QBSessionManager sessionManager = new QBSessionManager();
|
||||
IMsgSetRequest requestMsgSet = sessionManager.CreateMsgSetRequest("CA", 13, 0);
|
||||
requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;
|
||||
//public static string[] parseInvoiceAddRs(string xml)
|
||||
//{
|
||||
// string[] retVal = new string[3];
|
||||
// try
|
||||
// {
|
||||
// XmlNodeList RsNodeList = null;
|
||||
// XmlDocument Doc = new XmlDocument();
|
||||
// Doc.LoadXml(xml);
|
||||
// RsNodeList = Doc.GetElementsByTagName("InvoiceAddRs");
|
||||
// XmlAttributeCollection rsAttributes = RsNodeList.Item(0).Attributes;
|
||||
// XmlNode statusCode = rsAttributes.GetNamedItem("statusCode");
|
||||
// retVal[0] = Convert.ToString(statusCode.Value);
|
||||
// XmlNode statusSeverity = rsAttributes.GetNamedItem("statusSeverity");
|
||||
// retVal[1] = Convert.ToString(statusSeverity.Value);
|
||||
// XmlNode statusMessage = rsAttributes.GetNamedItem("statusMessage");
|
||||
// retVal[2] = Convert.ToString(statusMessage.Value);
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// logger.Error("Error encountered when parsing Invoice info returned from QuickBooks: " + e.Message);
|
||||
// retVal = null;
|
||||
// }
|
||||
// return retVal;
|
||||
//}
|
||||
|
||||
ICustomerAdd CustomerAddRq = requestMsgSet.AppendCustomerAddRq();
|
||||
//Get the address & Other information from the request XML DOC.
|
||||
CustomerAddRq.Name.SetValue(requestXML.Descendants("CustomerRef").First()?.Element("FullName")?.Value);
|
||||
|
||||
// ICustomerQuery CustomerQueryRq = requestMsgSet.AppendCustomerQueryRq();
|
||||
//CustomerQueryRq.ORCustomerListQuery.ListIDList.Add(ListID);
|
||||
|
||||
string ret = ProcessQBXmlRequest(requestMsgSet.ToXMLString());
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ListID;
|
||||
}
|
||||
|
||||
}
|
||||
public static string[] parseCustomerQueryRs(string xml)
|
||||
{
|
||||
string[] retVal;
|
||||
try
|
||||
{
|
||||
XDocument responseXml = XDocument.Parse(xml);
|
||||
XElement CustomerQueryRs = responseXml.Descendants("CustomerQueryRs").First();
|
||||
XAttribute statusCode = CustomerQueryRs.Attribute(XName.Get("statusCode"));
|
||||
|
||||
if (statusCode.Value?.ToString() == "0")
|
||||
{
|
||||
//All good, return the ID.
|
||||
}
|
||||
else
|
||||
{
|
||||
//Need to create a new customer and return that ID.
|
||||
}
|
||||
|
||||
//XmlNodeList RsNodeList = null;
|
||||
//XmlDocument Doc = new XmlDocument();
|
||||
//Doc.LoadXml(xml);
|
||||
//RsNodeList = Doc.GetElementsByTagName("CustomerQueryRs");
|
||||
//XmlAttributeCollection rsAttributes = RsNodeList.Item(0).Attributes;
|
||||
//XmlNode statusCode = rsAttributes.GetNamedItem("statusCode");
|
||||
//if (Convert.ToString(statusCode.Value) == "0")
|
||||
//{
|
||||
// //Found an ID for this person. Looks all good.
|
||||
// retVal = new string[1];
|
||||
// //xml.Desce
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// retVal = new string[3];
|
||||
// retVal[0] = Convert.ToString(statusCode.Value);
|
||||
// XmlNode statusSeverity = rsAttributes.GetNamedItem("statusSeverity");
|
||||
// retVal[1] = Convert.ToString(statusSeverity.Value);
|
||||
// XmlNode statusMessage = rsAttributes.GetNamedItem("statusMessage");
|
||||
// retVal[2] = Convert.ToString(statusMessage.Value);
|
||||
//}
|
||||
//;
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.Error("Error encountered when parsing Invoice info returned from QuickBooks: " + e.Message);
|
||||
retVal = null;
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
private static string ParseCustomerId(XDocument xml)
|
||||
{
|
||||
XElement CustomerRef = xml.Descendants("CustomerRef").First();
|
||||
string ListId = CustomerRef.Element("ListID")?.Value;
|
||||
return ListId;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user