Added checking for customer ID and started creation of new customer ID.

This commit is contained in:
Patrick Fic
2020-05-28 15:41:30 -07:00
parent be049fe4f6
commit fcb816d1e2
4 changed files with 111 additions and 27 deletions

View File

@@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using Interop.QBFC13;
using Interop.QBXMLRP2;
@@ -21,7 +23,6 @@ namespace BodyshopPartner.Utils
public static void ConnectToQuickBooks()
{
try
{
rp = new RequestProcessor2Class();
@@ -53,18 +54,72 @@ namespace BodyshopPartner.Utils
}
}
}
public static string processRequestFromQB(string request)
public static string ProcessQBXmlRequest(string request)
{
try
{
return rp.ProcessRequest(ticket, request);
ConnectToQuickBooks();
var ret = rp.ProcessRequest(ticket, request);
DisconnectFromQuickBooks();
return ret;
}
catch (Exception e)
{
logger.Error(e.Message);
DisconnectFromQuickBooks();
return null;
}
}
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;
}
public static string CreateCustomerIfNotExist(XDocument requestXML)
{
string ListID = ParseCustomerId(requestXML);
//Could be null or exist, we need to check.
QBSessionManager sessionManager = new QBSessionManager();
//Create the message set request object to hold our request
IMsgSetRequest requestMsgSet = sessionManager.CreateMsgSetRequest("CA", 13, 0);
requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;
ICustomerQuery CustomerQueryRq = requestMsgSet.AppendCustomerQueryRq();
CustomerQueryRq.ORCustomerListQuery.ListIDList.Add(ListID);
string ret = ProcessQBXmlRequest(requestMsgSet.ToXMLString());
return requestMsgSet.ToXMLString();
}
private static string ParseCustomerId(XDocument xml)
{
XElement CustomerRef = xml.Descendants("CustomerRef").First();
string ListId = CustomerRef.Element("ListID")?.Value;
return ListId;
}
}
}