/// <summary> /// Create a new customer based on the passed in CustomerPost object /// </summary> /// <param name="customer">A CustomerPost object that represents a customer to be created</param> /// <returns>A newly created Customer object</returns> public static Customer CreateCustomer(CustomerPost customer) { Customers customers = new Customers(); Customer newCustomer = new Customer(); try { string urlBase = "https://cheddargetter.com/xml"; string urlPath = string.Format("/customers/new/productCode/{0}", _ProductCode); string postParams = string.Format( "code={0}" + "&firstName={1}" + "&lastName={2}" + "&email={3}" + "&company={4}" + "¬es={5}" + "&subscription[planCode]={6}" + "&subscription[ccFirstName]={7}" + "&subscription[ccLastName]={8}" + "&subscription[ccNumber]={9}" + "&subscription[ccExpiration]={10}" + "&subscription[ccCardCode]={11}" + "&subscription[ccZip]={12}", HttpUtility.UrlEncode(customer.Code), HttpUtility.UrlEncode(customer.FirstName), HttpUtility.UrlEncode(customer.LastName), HttpUtility.UrlEncode(customer.Email), HttpUtility.UrlEncode(customer.Company), HttpUtility.UrlEncode(customer.Notes), HttpUtility.UrlEncode(customer.PlanCode.ToString().ToUpper()), HttpUtility.UrlEncode(customer.CCFirstName), HttpUtility.UrlEncode(customer.CCLastName), HttpUtility.UrlEncode(customer.CCNumber), HttpUtility.UrlEncode(customer.CCExpiration), HttpUtility.UrlEncode(customer.CCCardCode), HttpUtility.UrlEncode(customer.CCZip)); string result = postRequest(urlBase, urlPath, postParams); XDocument newCustomerXML = XDocument.Parse(result); customers = getCustomerList(newCustomerXML); if (customers.CustomerList.Count > 0) { newCustomer = customers.CustomerList[0]; } } catch (Exception ex) { throw ex; } return(newCustomer); }
/// <summary> /// Update a customer's subscription /// </summary> /// <param name="customer">A CustomerPost object with the subscription details to update</param> /// <returns>A Customer object with the applied changes</returns> public static Customer UpdateSubscription(CustomerPost customer) { Customers customers = new Customers(); Customer updatedCustomer = new Customer(); try { // Create the web request string urlBase = "https://cheddargetter.com/xml"; string urlPath = string.Format("/customers/edit-subscription/productCode/{0}/code/{1}", _ProductCode, customer.Code); //note: expiration date must be in MM/YYYY format StringBuilder postParamsSB = new StringBuilder(); postParamsSB.Append(string.Format("planCode={0}", HttpUtility.UrlEncode(customer.PlanCode.ToString().ToUpper()))); postParamsSB.Append(string.Format("&ccFirstName={0}", HttpUtility.UrlEncode(customer.CCFirstName))); postParamsSB.Append(string.Format("&ccLastName={0}", HttpUtility.UrlEncode(customer.CCLastName))); if (!string.IsNullOrEmpty(customer.CCNumber)) { postParamsSB.Append(string.Format("&ccNumber={0}", HttpUtility.UrlEncode(customer.CCNumber))); } postParamsSB.Append(string.Format("&ccExpiration={0}", HttpUtility.UrlEncode(string.Format("{0}/{1}", formatMonth(customer.CCExpMonth), customer.CCExpYear)))); if (!string.IsNullOrEmpty(customer.CCCardCode)) { postParamsSB.Append(string.Format("&ccCardCode={0}", HttpUtility.UrlEncode(customer.CCCardCode))); } postParamsSB.Append(string.Format("&ccZip={0}", HttpUtility.UrlEncode(customer.CCZip))); string result = postRequest(urlBase, urlPath, postParamsSB.ToString()); XDocument newCustomerXML = XDocument.Parse(result); customers = getCustomerList(newCustomerXML); if (customers.CustomerList.Count > 0) { updatedCustomer = customers.CustomerList[0]; } } catch (Exception ex) { throw ex; } return(updatedCustomer); }
/// <summary> /// Update a customer's subscription with only partial subscription information /// </summary> /// <param name="customer">A CustomerPost object with the changes that are to be updated</param> /// <returns>A Customer object with the applied changes</returns> public static Customer UpdateSubscriptionPartial(CustomerPost customer) { Customers customers = new Customers(); Customer updatedCustomer = new Customer(); try { // Create the web request string urlBase = "https://cheddargetter.com/xml"; string urlPath = string.Format("/customers/edit-subscription/productCode/{0}/code/{1}", _ProductCode, customer.Code); //note: expiration date must be in MM/YYYY format string postParams = string.Format( "planCode={0}" + "&ccFirstName={1}" + "&ccLastName={2}" + "&ccZip={3}", HttpUtility.UrlEncode(customer.PlanCode.ToString().ToUpper()), HttpUtility.UrlEncode(customer.CCFirstName), HttpUtility.UrlEncode(customer.CCLastName), HttpUtility.UrlEncode(customer.CCZip)); string result = postRequest(urlBase, urlPath, postParams); XDocument newCustomerXML = XDocument.Parse(result); customers = getCustomerList(newCustomerXML); if (customers.CustomerList.Count > 0) { updatedCustomer = customers.CustomerList[0]; } } catch (Exception ex) { throw ex; } return(updatedCustomer); }
/// <summary> /// Update a customer /// </summary> /// <param name="customer">A CustomerPost object that represents the changes to be updated</param> /// <returns>An updated Customer object with the changes applied</returns> public static Customer UpdateCustomer(CustomerPost customer) { Customers customers = new Customers(); Customer updatedCustomer = new Customer(); try { // Create the web request string urlBase = "https://cheddargetter.com/xml"; string urlPath = string.Format("/customers/edit-customer/productCode/{0}/code/{1}", _ProductCode, customer.Code); string postParams = string.Format( "firstName={0}" + "&lastName={1}" + "&email={2}" + "&company={3}", "¬es={4}", HttpUtility.UrlEncode(customer.FirstName), HttpUtility.UrlEncode(customer.LastName), HttpUtility.UrlEncode(customer.Email), HttpUtility.UrlEncode(customer.Company), HttpUtility.UrlEncode(customer.Notes)); string result = postRequest(urlBase, urlPath, postParams); XDocument newCustomerXML = XDocument.Parse(result); customers = getCustomerList(newCustomerXML); if (customers.CustomerList.Count > 0) { updatedCustomer = customers.CustomerList[0]; } } catch (Exception ex) { throw ex; } return(updatedCustomer); }
/// <summary> /// Update a customer's subscription with only partial subscription information /// </summary> /// <param name="customer">A CustomerPost object with the changes that are to be updated</param> /// <returns>A Customer object with the applied changes</returns> public static Customer UpdateSubscriptionPartial(CustomerPost customer) { Customers customers = new Customers(); Customer updatedCustomer = new Customer(); try { // Create the web request string urlBase = "https://cheddargetter.com/xml"; string urlPath = string.Format("/customers/edit-subscription/productCode/{0}/code/{1}", _ProductCode, customer.Code); //note: expiration date must be in MM/YYYY format string postParams = string.Format( "planCode={0}" + "&ccFirstName={1}" + "&ccLastName={2}" + "&ccZip={3}", HttpUtility.UrlEncode(customer.PlanCode.ToString().ToUpper()), HttpUtility.UrlEncode(customer.CCFirstName), HttpUtility.UrlEncode(customer.CCLastName), HttpUtility.UrlEncode(customer.CCZip)); string result = postRequest(urlBase, urlPath, postParams); XDocument newCustomerXML = XDocument.Parse(result); customers = getCustomerList(newCustomerXML); if (customers.CustomerList.Count > 0) { updatedCustomer = customers.CustomerList[0]; } } catch (Exception ex) { throw ex; } return updatedCustomer; }
/// <summary> /// Update a customer's subscription /// </summary> /// <param name="customer">A CustomerPost object with the subscription details to update</param> /// <returns>A Customer object with the applied changes</returns> public static Customer UpdateSubscription(CustomerPost customer) { Customers customers = new Customers(); Customer updatedCustomer = new Customer(); try { // Create the web request string urlBase = "https://cheddargetter.com/xml"; string urlPath = string.Format("/customers/edit-subscription/productCode/{0}/code/{1}", _ProductCode, customer.Code); //note: expiration date must be in MM/YYYY format StringBuilder postParamsSB = new StringBuilder(); postParamsSB.Append(string.Format("planCode={0}", HttpUtility.UrlEncode(customer.PlanCode.ToString().ToUpper()))); postParamsSB.Append(string.Format("&ccFirstName={0}", HttpUtility.UrlEncode(customer.CCFirstName))); postParamsSB.Append(string.Format("&ccLastName={0}", HttpUtility.UrlEncode(customer.CCLastName))); if (!string.IsNullOrEmpty(customer.CCNumber)) { postParamsSB.Append(string.Format("&ccNumber={0}", HttpUtility.UrlEncode(customer.CCNumber))); } postParamsSB.Append(string.Format("&ccExpiration={0}", HttpUtility.UrlEncode(string.Format("{0}/{1}", formatMonth(customer.CCExpMonth), customer.CCExpYear)))); if (!string.IsNullOrEmpty(customer.CCCardCode)) { postParamsSB.Append(string.Format("&ccCardCode={0}", HttpUtility.UrlEncode(customer.CCCardCode))); } postParamsSB.Append(string.Format("&ccZip={0}", HttpUtility.UrlEncode(customer.CCZip))); string result = postRequest(urlBase, urlPath, postParamsSB.ToString()); XDocument newCustomerXML = XDocument.Parse(result); customers = getCustomerList(newCustomerXML); if (customers.CustomerList.Count > 0) { updatedCustomer = customers.CustomerList[0]; } } catch (Exception ex) { throw ex; } return updatedCustomer; }
/// <summary> /// Update a customer and their subscription /// </summary> /// <param name="customer">A CustomerPost object that represents the changes to be updated</param> /// <returns>An updated Customer object with the changes applied</returns> public static Customer UpdateCustomerAndSubscription(CustomerPost customer) { Customers customers = new Customers(); Customer updatedCustomer = new Customer(); try { // Create the web request string urlBase = "https://cheddargetter.com/xml"; string urlPath = string.Format("/customers/edit/productCode/{0}/code/{1}", _ProductCode, customer.Code); string postParams = string.Format( "firstName={0}" + "&lastName={1}" + "&email={2}" + "&company={3}" + "¬es={4}" + "&subscription[planCode]={5}" + "&subscription[ccFirstName]={6}" + "&subscription[ccLastName]={7}" + "&subscription[ccNumber]={8}" + "&subscription[ccExpiration]={9}" + "&subscription[ccCardCode]={10}" + "&subscription[ccZip]={11}", HttpUtility.UrlEncode(customer.FirstName), HttpUtility.UrlEncode(customer.LastName), HttpUtility.UrlEncode(customer.Email), HttpUtility.UrlEncode(customer.Company), HttpUtility.UrlEncode(customer.Notes), HttpUtility.UrlEncode(customer.PlanCode.ToString().ToUpper()), HttpUtility.UrlEncode(customer.CCFirstName), HttpUtility.UrlEncode(customer.CCLastName), HttpUtility.UrlEncode(customer.CCNumber), HttpUtility.UrlEncode(string.Format("{0}/{1}", formatMonth(customer.CCExpMonth), customer.CCExpYear)), HttpUtility.UrlEncode(customer.CCCardCode), HttpUtility.UrlEncode(customer.CCZip)); string result = postRequest(urlBase, urlPath, postParams); XDocument newCustomerXML = XDocument.Parse(result); customers = getCustomerList(newCustomerXML); if (customers.CustomerList.Count > 0) { updatedCustomer = customers.CustomerList[0]; } } catch (Exception ex) { throw ex; } return updatedCustomer; }
/// <summary> /// Update a customer /// </summary> /// <param name="customer">A CustomerPost object that represents the changes to be updated</param> /// <returns>An updated Customer object with the changes applied</returns> public static Customer UpdateCustomer(CustomerPost customer) { Customers customers = new Customers(); Customer updatedCustomer = new Customer(); try { // Create the web request string urlBase = "https://cheddargetter.com/xml"; string urlPath = string.Format("/customers/edit-customer/productCode/{0}/code/{1}", _ProductCode, customer.Code); string postParams = string.Format( "firstName={0}" + "&lastName={1}" + "&email={2}" + "&company={3}", "¬es={4}", HttpUtility.UrlEncode(customer.FirstName), HttpUtility.UrlEncode(customer.LastName), HttpUtility.UrlEncode(customer.Email), HttpUtility.UrlEncode(customer.Company), HttpUtility.UrlEncode(customer.Notes)); string result = postRequest(urlBase, urlPath, postParams); XDocument newCustomerXML = XDocument.Parse(result); customers = getCustomerList(newCustomerXML); if (customers.CustomerList.Count > 0) { updatedCustomer = customers.CustomerList[0]; } } catch (Exception ex) { throw ex; } return updatedCustomer; }