private string buildCustomerAddRqXML(QBCustomerInfo cst) { //step2: create the qbXML request XmlDocument inputXMLDoc = new XmlDocument(); inputXMLDoc.AppendChild(inputXMLDoc.CreateXmlDeclaration("1.0", null, null)); inputXMLDoc.AppendChild(inputXMLDoc.CreateProcessingInstruction("qbxml", "version=\"2.0\"")); XmlElement qbXML = inputXMLDoc.CreateElement("QBXML"); inputXMLDoc.AppendChild(qbXML); XmlElement qbXMLMsgsRq = inputXMLDoc.CreateElement("QBXMLMsgsRq"); qbXML.AppendChild(qbXMLMsgsRq); qbXMLMsgsRq.SetAttribute("onError", "stopOnError"); XmlElement custAddRq = inputXMLDoc.CreateElement("CustomerAddRq"); qbXMLMsgsRq.AppendChild(custAddRq); custAddRq.SetAttribute("requestID", "1"); XmlElement custAdd = inputXMLDoc.CreateElement("CustomerAdd"); custAddRq.AppendChild(custAdd); custAdd.AppendChild(inputXMLDoc.CreateElement("Name")).InnerText = cst.Name; custAdd.AppendChild(inputXMLDoc.CreateElement("FirstName")).InnerText = cst.FirstName; custAdd.AppendChild(inputXMLDoc.CreateElement("LastName")).InnerText = cst.LastName; if (cst.Phone.Length > 0) { custAdd.AppendChild(inputXMLDoc.CreateElement("Phone")).InnerText = cst.Phone; } string input = inputXMLDoc.OuterXml; return(input); }
public async Task <string> AddCustomer(QBCustomerInfo cst) { string msg = ""; string requestXML = buildCustomerAddRqXML(cst); if (requestXML == null) { msg = "One of the input is missing. Double-check your entries and then click Save again. Error saving invoice"; return(msg); } await connectToQB(); string response = await processRequestFromQB(requestXML); disconnectFromQB(); string[] status = new string[3]; if (response != null) { status = parseCustomerAddRs(response); } if (response != null & status[0] == "0") { msg = "Customer was added successfully!"; } else { msg = "Could not add customer."; } msg = msg + "\n\n"; msg = msg + "Status Code = " + status[0] + "\n"; msg = msg + "Status Severity = " + status[1] + "\n"; msg = msg + "Status Message = " + status[2] + "\n"; //MessageBox.Show(msg); return(msg); }