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; }
private void CG_CreateCustomer() { try { //Create a new customer CustomerPost newCustomer = new CustomerPost(); newCustomer.Company = CompanyTextBox.Text; newCustomer.FirstName = FirstNameTextBox.Text; newCustomer.LastName = LastNameTextBox.Text; newCustomer.Email = EmailTextBox.Text; //Extra fields required for nonFREE plans newCustomer.CCFirstName = CCFirstNameTextbox.Text; newCustomer.CCLastName = CCLastNameTextBox.Text; newCustomer.CCNumber = CCNumberTextBox.Text; newCustomer.CCExpiration = CCExpirationTextBox.Text; newCustomer.CCZip = CCZipTextBox.Text; newCustomer.CCCardCode = CCCardCodeTextBox.Text; if (SelectedPlanCode != 0) { newCustomer.PlanCode = SelectedPlanCode; newCustomer.Code = AppID; //Send it to the server CGError servererror = new CGError(); Customer returnCustomer = CheddarGetter.CreateCustomer(newCustomer, servererror); //FAILURE if (String.IsNullOrEmpty(servererror.Code) == false) { //CG.InnerHtml += "<li>ERROR:" + servererror.Message; RadNotification1.Title = "WARNING"; RadNotification1.Text = servererror.Message; RadNotification1.Visible = true; RadNotification1.Show(); string clickHandler = "this.disabled = false; this.value=\'Submit\'; "; SubmitButton.Attributes.Add("onclick", clickHandler); return; } //SUCCESS if (String.IsNullOrEmpty(returnCustomer.Code) == false) { AppCGCustomerCode = returnCustomer.Code; CGResponseFlag.Text = AppCGCustomerCode; Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID]; //If the App was submitted to a store [native & hybrid] then just update the paid_services table entry with status to paid. //If not [web apps] create a new entry in paid_services and update status to paid. String app_name = State["SelectedApp"].ToString(); BillingUtil billingutil = new BillingUtil(); if (billingutil.IsAppStoreSubmissionPaid(State, app_name)) { string confirm = returnCustomer.Subscriptions[0].Invoices[1].PaidTransactionId.ToString(); string sku = returnCustomer.Subscriptions[0].SubscriptionsPlans[0].Code.ToString(); billingutil.UpdatePaidServicesDB(confirm,sku, State); } else { string confirm = returnCustomer.Subscriptions[0].Invoices[1].PaidTransactionId.ToString(); string sku = returnCustomer.Subscriptions[0].SubscriptionsPlans[0].Code.ToString(); billingutil.StorePaidServicesDB(confirm, sku, State, true); } } } }//end try catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message.ToString()); throw; } }