private void ContinueClick(object sender, RoutedEventArgs e) { try { _paymentSuccessfull = false; IsBusy = true; var customer = new CustomerPost(); customer.Code = Guid.NewGuid().ToString(); customer.Company = Company; customer.Email = Email; customer.CCFirstName = PayPalFirstName; customer.CCLastName = PayPalLastName; customer.FirstName = FirstName; customer.LastName = LastName; customer.PlanCode = SelectedPaymentPlan.Code; customer.CouponCode = CouponCode; _customerCode = customer.Code; CheddarGetter.CreateCustomer(customer); _timer.Start(); } catch (Exception ex) { IsBusy = false; _timer.Stop(); MessageBox.Show("Invalid Data: " + ex.Message); } }
/// <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.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 { //we don't want to send an empty cc number //if the customer isn't updating the card number if (customer.CCNumber != "") { // 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.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]; } } else { // 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[ccExpiration]={8}" + "&subscription[ccCardCode]={9}" + "&subscription[ccZip]={10}", HttpUtility.UrlEncode(customer.FirstName), HttpUtility.UrlEncode(customer.LastName), HttpUtility.UrlEncode(customer.Email), HttpUtility.UrlEncode(customer.Company), HttpUtility.UrlEncode(customer.Notes), HttpUtility.UrlEncode(customer.PlanCode.ToUpper()), HttpUtility.UrlEncode(customer.CCFirstName), HttpUtility.UrlEncode(customer.CCLastName), 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]; } } //if (result.IndexOf("Error") > -1) //{ //} //else //{ //} } 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> /// 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}" + "&subscription[planCode]={5}" + "&subscription[ccFirstName]={6}" + "&subscription[ccLastName]={7}" + "&subscription[method]={8}" + "&subscription[returnUrl]={9}" + "&subscription[cancelUrl]={10}" + "&subscription[couponCode]={11}", HttpUtility.UrlEncode(customer.Code), HttpUtility.UrlEncode(customer.FirstName), HttpUtility.UrlEncode(customer.LastName), HttpUtility.UrlEncode(customer.Email), HttpUtility.UrlEncode(customer.Company), HttpUtility.UrlEncode(customer.PlanCode), HttpUtility.UrlEncode(customer.CCFirstName), HttpUtility.UrlEncode(customer.CCLastName), HttpUtility.UrlEncode("paypal"), HttpUtility.UrlEncode("http://www.maxcut.co.za"), HttpUtility.UrlEncode("http://www.maxcut.co.za"), HttpUtility.UrlEncode(customer.CouponCode)); string result = postRequest(urlBase, urlPath, postParams); XDocument newCustomerXML = XDocument.Parse(result); customers = getCustomerList(newCustomerXML); OpenWebBrowserTo(customers.CustomerList.First().Subscriptions.First().RedirectURL); if (customers.CustomerList.Count > 0) { newCustomer = customers.CustomerList[0]; } } catch (Exception ex) { throw ex; } return newCustomer; }