/// <summary> /// Add a customer charge for a customer /// </summary> /// <param name="customCharge">A CustomerChargePost object with the customer charge and customer code</param> /// <returns>A Customer object with the reflected custom charge</returns> public async Task <Customer> AddCustomCharge(CustomChargePost customCharge) { Customers customers = new Customers(); Customer editCustomer = new Customer(); try { string urlPath = $"/customers/set-item-quantity/productCode/{_config.productCode}/code/{customCharge.CustomerCode}/itemCode/{customCharge.ItemCode}"; string postParams = FormatFunctions.addParam("chargeCode", customCharge.ChargeCode) + FormatFunctions.addParam("quantity", customCharge.Quantity.ToString()) + FormatFunctions.addParam("eachAmount", customCharge.EachAmount.ToString()) + FormatFunctions.addParam("description", customCharge.Description); string result = await _httpService.postRequest(urlPath, postParams); XDocument newCustomerXML = XDocument.Parse(result); customers = getCustomerList(newCustomerXML); if (customers.CustomerList.Count > 0) { editCustomer = customers.CustomerList[0]; } } catch (Exception ex) { throw ex; } return(editCustomer); }
private Boolean CG_CreateFreeCustomerAndInvoices() { try { Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID]; //Create a new customer CustomerPost newCustomer = new CustomerPost(); newCustomer.Company = CompanyTextBox.Text; newCustomer.FirstName = FirstNameTextBox.Text; newCustomer.LastName = LastNameTextBox.Text; newCustomer.Email = EmailTextBox.Text; newCustomer.CCFirstName = CCFirstNameTextbox.Text; newCustomer.CCLastName = CCLastNameTextBox.Text; newCustomer.CCNumber = CCNumberTextBox.Text; newCustomer.CCExpiration = CCExpirationTextBox.Text; newCustomer.CCZip = CCZipTextBox.Text; newCustomer.CCCardCode = CCCardCodeTextBox.Text; newCustomer.Code = State["application_id"].ToString(); //For Branding purposes create appropriate branding code. if (State["SelectedDeviceType"].ToString() == Constants.ANDROID_PHONE) { newCustomer.PlanCode = PlanCodeEnum.ANDROID_BRANDING; } else { if (State["SelectedDeviceType"].ToString() == Constants.IPHONE) { newCustomer.PlanCode = PlanCodeEnum.IOS_BRANDING; } else { RadNotification1.Title = "WARNING"; RadNotification1.Text = "This application has no device type."; RadNotification1.Visible = true; RadNotification1.Show(); return false; } } //Send it to the server CGError servererror = new CGError(); Customer returnCustomer = CheddarGetter.CreateCustomer(newCustomer, servererror); //FAILURE if (String.IsNullOrEmpty(servererror.Code) == false) { //string clickHandler = "this.disabled = false; this.value=\'Submit\'; "; // SubmitButton.Attributes.Add("onclick", clickHandler); SubmitButton.Enabled = true; SubmitButton.Text = "Submit"; //CG.InnerHtml += "<li>ERROR:" + servererror.Message; RadNotification1.Title = "WARNING"; RadNotification1.Text = servererror.Message; RadNotification1.Visible = true; RadNotification1.Show(); return false; } //SUCCESS if (String.IsNullOrEmpty(returnCustomer.Code) == false) { AppCGCustomerCode = returnCustomer.Code; } // IF SUCCESSFULLY ABLE TO CREATE THE FREE NATIVE CUSTOMER THEN KICK OFF A ONE TIME INVOICE FOR BRANDING OneTimeInvoicePost myonetimeinvoice = new OneTimeInvoicePost(); myonetimeinvoice.InvoiceCharges = new CustomChargePost[1]; int number_of_charges = 0; CustomChargePost mycustom1 = new CustomChargePost(); mycustom1.CustomerCode = AppCGCustomerCode; mycustom1.Description = "Branding"; mycustom1.ChargeCode = "BRANDING "; mycustom1.EachAmount = 0; mycustom1.Quantity = 0; if ((State["SelectedDeviceType"].ToString() == Constants.ANDROID_PHONE || State["SelectedDeviceType"].ToString() == Constants.ANDROID_TABLET) && (String.IsNullOrEmpty(AppCGCustomerCode) == false)) { mycustom1.ChargeCode += "- ANRDOID"; mycustom1.CustomerCode = AppCGCustomerCode; mycustom1.Quantity = 1; mycustom1.EachAmount += 99; mycustom1.Description += "- Android"; } if ((State["SelectedDeviceType"].ToString() == Constants.IPHONE || State["SelectedDeviceType"].ToString() == Constants.IPAD) && (String.IsNullOrEmpty(AppCGCustomerCode) == false)) { mycustom1.ChargeCode += "- iOS"; mycustom1.Quantity = 1; mycustom1.EachAmount += 99; mycustom1.Description += "- iOS"; } myonetimeinvoice.InvoiceCharges[number_of_charges] = new CustomChargePost(); myonetimeinvoice.InvoiceCharges[number_of_charges] = mycustom1; CGError servererror2 = new CGError(); //SERVER CALL TO THE ONE TIME INVOICE for both charges at once. Customer returnCustomer2 = CheddarGetter.CreateOneTimeInvoice(myonetimeinvoice, servererror2); if (String.IsNullOrEmpty(servererror2.Code) == false) { //CG.InnerHtml += "<li>ERROR:" + servererror2.Message; SubmitButton.Enabled = true; SubmitButton.Text = "Submit"; //string clickHandler = "this.disabled = false; this.value=\'Submit\'; "; //SubmitButton.Attributes.Add("onclick", clickHandler); RadNotification1.Title = "WARNING"; RadNotification1.Text = servererror2.Message; RadNotification1.Visible = true; RadNotification1.Show(); return false; } //Store in the PaidServicesDB BillingUtil billingutil = new BillingUtil(); //Record the new SKU but do not turn on the 'paid' field as yet. string confirm = returnCustomer2.Subscriptions[0].Invoices[1].PaidTransactionId.ToString(); string sku = returnCustomer2.Subscriptions[0].SubscriptionsPlans[0].Code.ToString(); billingutil.StorePaidServicesDB(confirm,sku,State,false); //Enable 10 day grace for App store Approval. Util util = new Util(); util.SetFreeProductionExpiration(State, DateTime.Now.ToUniversalTime().AddDays(10.0D)); //Send Email to Support. System.Text.StringBuilder body = new System.Text.StringBuilder("Customer Username: "******"Username"].ToString() + "\n"); body.Append("App Name: " + State["SelectedApp"].ToString() + "\n"); body.Append("\n-- ViziApps Support"); Email email = new Email(); string status = email.SendEmail(State, HttpRuntime.Cache["TechSupportEmail"].ToString(), HttpRuntime.Cache["TechSupportEmail"].ToString(),"", "", "Customer submitted App for App Store Preparation", body.ToString(), "", false); return true; }//end try catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message.ToString() + ex.StackTrace.ToString()); } return false; }
/// <summary> /// Add a customer charge for a customer /// </summary> /// <param name="customCharge">A CustomerChargePost object with the customer charge and customer code</param> /// <returns>A Customer object with the reflected custom charge</returns> public static Customer AddCustomCharge(CustomChargePost customCharge, CGError error) { Customers customers = new Customers(); Customer editCustomer = new Customer(); try { string urlBase = "https://cheddargetter.com/xml"; //string urlPath = string.Format("/customers/set-item-quantity/productCode/{0}/code/{1}/itemCode/{2}", _ProductCode, customCharge.CustomerCode, customCharge.ItemCode); string urlPath = string.Format("/customers/add-charge/productCode/{0}/code/{1}", _ProductCode, customCharge.CustomerCode); string postParams = string.Format( "chargeCode={0}" + "&quantity={1}" + "&eachAmount={2}" + "&description={3}", HttpUtility.UrlEncode(customCharge.ChargeCode), HttpUtility.UrlEncode(customCharge.Quantity.ToString()), HttpUtility.UrlEncode(customCharge.EachAmount.ToString()), HttpUtility.UrlEncode(customCharge.Description)); string result = postRequest(urlBase, urlPath, postParams); XDocument newCustomerXML = XDocument.Parse(result); customers = getCustomerList(newCustomerXML); if (customers.CustomerList.Count > 0) { editCustomer = customers.CustomerList[0]; } } //shyam catch (System.Net.WebException ex) { processWebException(ex, error); } //shyam catch (Exception ex) { new Exception(ex.Message + ": " + ex.StackTrace); } return editCustomer; }