protected void btnUpdate_Click(object sender, EventArgs e) { try { byte memberLevel = byte.Parse(HiddenMemberLevel.Value); if (memberLevel == 1)//upgrade from Normal to Premium { //premium ScriptManager.RegisterStartupScript(this, this.GetType(), "js", "document.getElementById('" + divRowRegNormal.ClientID + "').style.display='none';" + "document.getElementById('" + divRowRegPremium.ClientID + "').style.display='inline';", true); } else { //normal ScriptManager.RegisterStartupScript(this, this.GetType(), "js", "document.getElementById('" + divRowRegNormal.ClientID + "').style.display='inline';" + "document.getElementById('" + divRowRegPremium.ClientID + "').style.display='none';", true); } //user MembershipUser usr = System.Web.Security.Membership.GetUser(UserID); var userDetail = GetUserDetail(); if (userDetail == null) userDetail = new UserDetail(); var polinatorInformation = GetPolinatorInformation(); if (polinatorInformation == null) polinatorInformation = new PolinatorInformation(); //status polinatorInformation.IsApproved = false;//reset IsApproved = 0 polinatorInformation.IsNew = false; polinatorInformation.LastUpdated = DateTime.Now; //get new values from form and set to object to update if (memberLevel == 1 && userDetail.MembershipLevel == 0)//upgrade from Normal to Premium { //add info into UserDetail table var tempUserPaymentOld = (from tempUP in mydb.TempUserPayments where tempUP.UserId == UserID select tempUP).FirstOrDefault(); if (tempUserPaymentOld != null) mydb.TempUserPayments.Remove(tempUserPaymentOld); TempUserPayment tempUserPayment = new TempUserPayment(); tempUserPayment.UserId = UserID; //membership(user) tempUserPayment.Email = txtPreEmail.Text; //userDetail.MembershipLevel(have 2 levels): 0 is free; 1 is premium tempUserPayment.MembershipLevel = 1;//Premium tempUserPayment.FirstName = txtPreFirstName.Text; tempUserPayment.LastName = txtPreLastName.Text; tempUserPayment.PhoneNumber = txtPrePhoneNumber.Text; //tempUserPayment.OrganizationName = txtPreOrganizationName.Text; //table2: UserDetail tempUserPayment.OrganizationName = txtPreOrganizationName.Text; tempUserPayment.PollinatorSize = Int32.Parse(ddlPrePollinatorSize.SelectedValue); tempUserPayment.PollinatorType = Int32.Parse(ddlPrePollinatorType.SelectedValue); tempUserPayment.LandscapeStreet = txtPreLandscapeStreet.Text; tempUserPayment.LandscapeCity = txtPreLandscapeCity.Text; tempUserPayment.LandscapeState = txtPreLandscapeState.Text; tempUserPayment.LandscapeZipcode = txtPreLandscapeZipcode.Text; tempUserPayment.LandscapeCountry = ddlPreCountry.SelectedValue; tempUserPayment.PhotoUrl = txtPrePhotoUrl.Text; tempUserPayment.YoutubeUrl = txtPreYoutubeUrl.Text; tempUserPayment.Website = txtPreWebsite.Text; tempUserPayment.Description = txtPreDescription.Text; tempUserPayment.BillingAddress = txtPreBillingAddress.Text; tempUserPayment.BillingCity = txtPreBillingCity.Text; tempUserPayment.BillingState = txtPreBillingState.Text; ; tempUserPayment.BillingZipcode = txtPreBillingZipcode.Text; //save lat, long tempUserPayment.Latitude = decimal.Parse(hdnLat.Value); tempUserPayment.Longitude = decimal.Parse(hdnLng.Value); //save userfolder //if (!string.IsNullOrEmpty(tempUserPayment.PhotoUrl)) //{ // string filePath = tempUserPayment.PhotoUrl.Split(';')[0]; // if (!string.IsNullOrEmpty(filePath)) // { // int index1 = filePath.LastIndexOf('/'); // if (index1 > 0) // { // filePath = filePath.Substring(0, index1).Trim(); // index1 = filePath.LastIndexOf('/'); // if (index1 > 0) // filePath = filePath.Substring(index1+1, filePath.Length-index1).Trim(); // tempUserPayment.UserFolder = HttpUtility.HtmlDecode(filePath); // } // } //} //createProcess //tempUserPayment.CreateProcess = 1; //tempUserPayment.CreateDate = DateTime.Now; //save to TempUserPayments table mydb.TempUserPayments.Add(tempUserPayment); mydb.SaveChanges();//submit temp table //Payment: send request to Paypal if (tempUserPayment != null) { // get business account email from config string PaypalEmail = ConfigurationManager.AppSettings["PaypalSeller"]; // get variable environment from config bool SandboxEnvi = bool.Parse(ConfigurationManager.AppSettings["SandboxEnvironment"]); // get price from config string PaypalPrice = ConfigurationManager.AppSettings["PaypalPrice"]; // Callback url to handle process when payement is successful string ReturnUrl = "http://" + HttpContext.Current.Request["HTTP_HOST"] + "/Members/Manage.aspx?payer=" + UserID; // Callback url to handle process when IPN Paypal service notify string NotifyUrl = "http://" + HttpContext.Current.Request["HTTP_HOST"] + "/HandlerIPN.ashx"; // Callback url to handle process when payment is cancel string CancelUrl = "http://" + HttpContext.Current.Request["HTTP_HOST"] + "/Members/Manage.aspx?payc=" + UserID; //name of product string PaypalItemName = ConfigurationManager.AppSettings["PaypalItemName"]; //custom parram contain temp information of New User string custom = UserID + ";password;change";//CreateUserWizard2.ContinueDestinationPageUrl; //end custom //Pollinator.Common.Logger.Information("Paypal Manage 2 ReturnUrl= " + ReturnUrl); // generate a html form paypal IPN string string PaypalFormHtmlStr = "<form target='_parent' name='_xclick' action='" + ((SandboxEnvi) ? "https://www.sandbox.paypal.com/cgi-bin/webscr" : "https://www.paypal.com/cgi-bin/webscr") + "' method='post'>" + "<input type='hidden' name='cmd' value='_xclick'>" + "<input type='hidden' name='business' value='" + PaypalEmail + "'>" + "<input type='hidden' name='payer_email' value='" + PaypalEmail + "'>" + "<input type='hidden' name='currency_code' value='USD'>" + "<input type='hidden' name='item_name' value='" + PaypalItemName + "'>" + "<input type='hidden' name='amount' value='" + PaypalPrice + "'>" + "<input type='hidden' name='custom' value='" + custom + "' />" + "<input type='hidden' name='return' value='" + ReturnUrl + "'>" + "<input type='hidden' name='notify_url' value='" + NotifyUrl + "'>" + "<input type='hidden' name='cancel_url' value='" + CancelUrl + "'>" + "<input type='image' id='paypal_btn' src='' border='0' name='submit' alt=''> </form>"; //Pollinator.Common.Logger.Information("Paypal Manage 3 PaypalFormHtmlStr= " + PaypalFormHtmlStr); //payment //string ExternalPaymemtlUrl = ConfigurationManager.AppSettings["ExternalPaymemtlUrl"]; //if (!String.IsNullOrEmpty(ExternalPaymemtlUrl))//external payment //{ // tempUserPayment.PaypalFormHtmlStr = PaypalFormHtmlStr; // mydb.SaveChanges(); // //redirect to external paymemt page // ScriptManager.RegisterStartupScript(this, this.GetType(), "popupWaitxxxx", "document.getElementById('MainContent_HyperLink123').click();", true); // //string urlRedirect = string.Format("{0}?userID={1}", ExternalPaymemtlUrl, tempUserPayment.UserId); // //ScriptManager.RegisterStartupScript(this, this.GetType(), "redirect", " window.location.replace(\"" + urlRedirect + "\");", true); //} //else // ScriptManager.RegisterStartupScript(this, this.GetType(), "paypal", "document.getElementById('paypal_container').innerHTML = \"" + PaypalFormHtmlStr + "\" ; document.getElementById('paypal_btn').click() ;", true); ScriptManager.RegisterStartupScript(this, this.GetType(), "paypal", "document.getElementById('paypal_container').innerHTML = \"" + PaypalFormHtmlStr + "\" ; document.getElementById('paypal_btn').click() ;", true); } //show please wait... popup ScriptManager.RegisterStartupScript(this, this.GetType(), "popupWait", "document.getElementById('showProcessbar').click();", true); } else { if (memberLevel == 0) GetInfoFromFormNormal(usr, userDetail, polinatorInformation); else GetInfoFromFormPrenium(usr, userDetail, polinatorInformation); if (usr != null) System.Web.Security.Membership.UpdateUser(usr); mydb.SaveChanges();//submit changed to DB //Auto Approved AutoApproveSubmission(usr, userDetail, polinatorInformation); ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "document.getElementById('confirm_pop').click();", true); } //Response.Redirect("~/ShareMap.aspx"); } catch (Exception ex) { byte memberLevel = byte.Parse(HiddenMemberLevel.Value); if (memberLevel == 1)//upgrade from Normal to Premium { //premium ScriptManager.RegisterStartupScript(this, this.GetType(), "js", "document.getElementById('" + divRowRegNormal.ClientID + "').style.display='none';" + "document.getElementById('" + divRowRegPremium.ClientID + "').style.display='inline';", true); } else { //normal ScriptManager.RegisterStartupScript(this, this.GetType(), "js", "document.getElementById('" + divRowRegNormal.ClientID + "').style.display='inline';" + "document.getElementById('" + divRowRegPremium.ClientID + "').style.display='none';", true); } //Response.Write(ex.ToString()); Pollinator.Common.Logger.Error("Error occured at " + typeof(Members_Manage).Name + ".btnUpdate_Click()", ex); GoToAlertMessage(panelErrorMessage); } }
protected void btnPreUpdate_Click(object sender, EventArgs e) { int progress = 0; string userName = string.Empty; UserDetail userDetail = new UserDetail(); PolinatorInformation polinatorInformation = new PolinatorInformation(); Label lblPreErrorMessage = ((Label)LoginView1.FindControl("lblPreErrorMessage")); lblPreErrorMessage.Text = ""; try { //Create new User userName = ((TextBox)LoginView1.FindControl("txtPreUserName")).Text; string password = ((TextBox)LoginView1.FindControl("txtPrePassword")).Text; string email = ((TextBox)LoginView1.FindControl("txtPreEmail")).Text; string passwordQuestion = "Q?"; string passwordAnswer = "A"; bool isApproved = true; MembershipCreateStatus status; //auto gen UserName, Password if client not input UserName,Password if (string.IsNullOrEmpty(userName)) userName = Utility.CreateRandomUserName(0); if (string.IsNullOrEmpty(password)) password = Utility.CreateRandomPassword(10); //Exec create System.Web.Security.Membership.CreateUser(userName, password, email, passwordQuestion, passwordAnswer, isApproved, out status); //status if (status == MembershipCreateStatus.Success) progress = 1; else { lblPreErrorMessage.Text = GetErrorMessage(status); return; } // Get the UserId of the just-added user MembershipUser newUser = System.Web.Security.Membership.GetUser(userName); Guid newUserId = (Guid)newUser.ProviderUserKey; //add new Usser to Members role if (!Roles.RoleExists(roleMembersName)) Roles.CreateRole(roleMembersName); Roles.AddUserToRole(userName, roleMembersName); //add info into UserDetail table var tempUserPaymentOld = (from tempUP in mydb.TempUserPayments where tempUP.UserId == newUserId select tempUP).FirstOrDefault(); if (tempUserPaymentOld != null) mydb.TempUserPayments.Remove(tempUserPaymentOld); TempUserPayment tempUserPayment = new TempUserPayment(); tempUserPayment.UserId = newUserId; tempUserPayment.Email = newUser.Email; //userDetail.MembershipLevel(have 2 levels): 0 is free; 1 is premium tempUserPayment.MembershipLevel = 1;//Premium tempUserPayment.FirstName = ((TextBox)LoginView1.FindControl("txtPreFirstName")).Text; tempUserPayment.LastName = ((TextBox)LoginView1.FindControl("txtPreLastName")).Text; tempUserPayment.PhoneNumber = ((TextBox)LoginView1.FindControl("txtPrePhoneNumber")).Text; //table2: UserDetail //PolinatorInformation polinatorInformation = new PolinatorInformation(); //polinatorInformation.UserId = newUserId; tempUserPayment.OrganizationName = ((TextBox)LoginView1.FindControl("txtPreOrganizationName")).Text; tempUserPayment.LandscapeStreet = ((TextBox)LoginView1.FindControl("txtPreLandscapeStreet")).Text; tempUserPayment.LandscapeCity = ((TextBox)LoginView1.FindControl("txtPreLandscapeCity")).Text; tempUserPayment.LandscapeState = ((TextBox)LoginView1.FindControl("txtPreLandscapeState")).Text; tempUserPayment.LandscapeZipcode = ((TextBox)LoginView1.FindControl("txtPreLandscapeZipcode")).Text; //country tempUserPayment.LandscapeCountry = ((DropDownList)LoginView1.FindControl("ddlPreCountry")).SelectedValue; //size, type tempUserPayment.PollinatorSize = Int32.Parse(((DropDownList)LoginView1.FindControl("ddlPrePollinatorSize")).SelectedValue); tempUserPayment.PollinatorType = Int32.Parse(((DropDownList)LoginView1.FindControl("ddlPrePollinatorType")).SelectedValue); tempUserPayment.PhotoUrl = ((TextBox)LoginView1.FindControl("txtPrePhotoUrl")).Text; tempUserPayment.YoutubeUrl = ((TextBox)LoginView1.FindControl("txtPreYoutubeUrl")).Text; tempUserPayment.Website = ((TextBox)LoginView1.FindControl("txtPreWebsite")).Text; tempUserPayment.Description = ((TextBox)LoginView1.FindControl("txtPreDescription")).Text; tempUserPayment.BillingAddress = ((TextBox)LoginView1.FindControl("txtPreBillingAddress")).Text; tempUserPayment.BillingCity = ((TextBox)LoginView1.FindControl("txtPreBillingCity")).Text; tempUserPayment.BillingState = ((TextBox)LoginView1.FindControl("txtPreBillingState")).Text; tempUserPayment.BillingZipcode = ((TextBox)LoginView1.FindControl("txtPreBillingZipcode")).Text; //save lat, long tempUserPayment.Latitude = decimal.Parse(hdnLat.Value); tempUserPayment.Longitude = decimal.Parse(hdnLng.Value); //save to TempUserPayments table mydb.TempUserPayments.Add(tempUserPayment); mydb.SaveChanges(); progress = 2;//set progress to step 2 //Payment: send request to Paypal //CreateUserWizard2.Visible = false; if (tempUserPayment != null) { //create cookie password string cookieSubName = HttpUtility.HtmlEncode(newUserId.ToString()+"pw"); string cookieSubValue = HttpUtility.HtmlEncode(password); Response.Cookies[newUserId.ToString()][cookieSubName] = cookieSubValue; Response.Cookies[newUserId.ToString()].Expires = DateTime.Now.AddHours(1); // get business account email from config string PaypalEmail = ConfigurationManager.AppSettings["PaypalSeller"]; //get payer email that user's email string PayerEmail = tempUserPayment.Email; // get variable environment from config bool SandboxEnvi = bool.Parse(ConfigurationManager.AppSettings["SandboxEnvironment"]); // get price from config string PaypalPrice = ConfigurationManager.AppSettings["PaypalPrice"]; // Callback url to handle process when payement is successful string ReturnUrl = "http://" + HttpContext.Current.Request["HTTP_HOST"] + "/ShareMap?payer=" + newUserId; // Callback url to handle process when IPN Paypal service notify string NotifyUrl = "http://" + HttpContext.Current.Request["HTTP_HOST"] + "/HandlerIPN.ashx"; // Callback url to handle process when payment is cancel string CancelUrl = "http://" + HttpContext.Current.Request["HTTP_HOST"] + "/ShareMap?payc=" + newUserId; //name of product string PaypalItemName = ConfigurationManager.AppSettings["PaypalItemName"]; //custom parram contain temp information of New User string custom = newUserId + ";" + password + ";add";//CreateUserWizard2.ContinueDestinationPageUrl; //for case test demo link included in a frame of client's domain string backUrl = ConfigurationManager.AppSettings["BackUrl"]+"?Step=12"; if (!String.IsNullOrEmpty(backUrl)) ReturnUrl += "&backUrl=" + backUrl; // generate a html form paypal IPN string string PaypalFormHtmlStr = "<form target='_parent' name='_xclick' action='" + ((SandboxEnvi) ? "https://www.sandbox.paypal.com/cgi-bin/webscr" : "https://www.paypal.com/cgi-bin/webscr") + "' method='post'>" + "<input type='hidden' name='cmd' value='_xclick'>" + "<input type='hidden' name='business' value='" + PaypalEmail + "'>" + "<input type='hidden' name='payer_email' value='" + PayerEmail + "'>" + "<input type='hidden' name='currency_code' value='USD'>" + "<input type='hidden' name='item_name' value='" + PaypalItemName + "'>" + "<input type='hidden' name='amount' value='" + PaypalPrice + "'>" + "<input type='hidden' name='custom' value='" + custom + "' />" + "<input type='hidden' name='return' value='" + ReturnUrl + "'>" + "<input type='hidden' name='notify_url' value='" + NotifyUrl + "'>" + "<input type='hidden' name='cancel_url' value='" + CancelUrl + "'>" + "<input type='image' id='paypal_btn' src='' border='0' name='submit' alt=''> </form>"; ScriptManager.RegisterStartupScript(this, this.GetType(), "paypal", "document.getElementById('paypal_container').innerHTML = \"" + PaypalFormHtmlStr + "\" ; document.getElementById('paypal_btn').click() ;", true); } //show process bar ScriptManager.RegisterStartupScript(this, this.GetType(), "popupWait", "document.getElementById('showProcessbar').click();", true); } catch (Exception ex) { //rollback if (progress == 1)//have just created User System.Web.Security.Membership.DeleteUser(userName, true); //show error message lblPreErrorMessage.Text = ex.Message; //write log Pollinator.Common.Logger.Error("Occured in function: " + typeof(Account_Register).Name + ".CreateUserWizard2_CreatedUser()", ex); //Response.Redirect("~/Default"); } }
protected void btnPreUpdate_Click(object sender, EventArgs e) { int progress = 0; string userName = string.Empty; UserDetail userDetail = new UserDetail(); PolinatorInformation polinatorInformation = new PolinatorInformation(); Label lblPreErrorMessage = ((Label)LoginView1.FindControl("lblPreErrorMessage")); lblPreErrorMessage.Text = ""; try { //Create new User userName = ((TextBox)LoginView1.FindControl("txtPreUserName")).Text; string password = ((TextBox)LoginView1.FindControl("txtPrePassword")).Text; string email = ((TextBox)LoginView1.FindControl("txtPreEmail")).Text; string passwordQuestion = "Q?"; string passwordAnswer = "A"; bool isApproved = true; MembershipCreateStatus status; //auto gen UserName, Password if client not input UserName,Password if (string.IsNullOrEmpty(userName)) { userName = Utility.CreateRandomUserName(0); } if (string.IsNullOrEmpty(password)) { password = Utility.CreateRandomPassword(10); } //Exec create System.Web.Security.Membership.CreateUser(userName, password, email, passwordQuestion, passwordAnswer, isApproved, out status); //status if (status == MembershipCreateStatus.Success) { progress = 1; } else { lblPreErrorMessage.Text = GetErrorMessage(status); return; } // Get the UserId of the just-added user MembershipUser newUser = System.Web.Security.Membership.GetUser(userName); Guid newUserId = (Guid)newUser.ProviderUserKey; //add new Usser to Members role if (!Roles.RoleExists(roleMembersName)) { Roles.CreateRole(roleMembersName); } Roles.AddUserToRole(userName, roleMembersName); //add info into UserDetail table var tempUserPaymentOld = (from tempUP in mydb.TempUserPayments where tempUP.UserId == newUserId select tempUP).FirstOrDefault(); if (tempUserPaymentOld != null) { mydb.TempUserPayments.Remove(tempUserPaymentOld); } TempUserPayment tempUserPayment = new TempUserPayment(); tempUserPayment.UserId = newUserId; tempUserPayment.Email = newUser.Email; //userDetail.MembershipLevel(have 2 levels): 0 is free; 1 is premium tempUserPayment.MembershipLevel = 1;//Premium tempUserPayment.FirstName = ((TextBox)LoginView1.FindControl("txtPreFirstName")).Text; tempUserPayment.LastName = ((TextBox)LoginView1.FindControl("txtPreLastName")).Text; tempUserPayment.PhoneNumber = ((TextBox)LoginView1.FindControl("txtPrePhoneNumber")).Text; //table2: UserDetail //PolinatorInformation polinatorInformation = new PolinatorInformation(); //polinatorInformation.UserId = newUserId; tempUserPayment.OrganizationName = ((TextBox)LoginView1.FindControl("txtPreOrganizationName")).Text; tempUserPayment.LandscapeStreet = ((TextBox)LoginView1.FindControl("txtPreLandscapeStreet")).Text; tempUserPayment.LandscapeCity = ((TextBox)LoginView1.FindControl("txtPreLandscapeCity")).Text; tempUserPayment.LandscapeState = ((TextBox)LoginView1.FindControl("txtPreLandscapeState")).Text; tempUserPayment.LandscapeZipcode = ((TextBox)LoginView1.FindControl("txtPreLandscapeZipcode")).Text; //country tempUserPayment.LandscapeCountry = ((DropDownList)LoginView1.FindControl("ddlPreCountry")).SelectedValue; //size, type tempUserPayment.PollinatorSize = Int32.Parse(((DropDownList)LoginView1.FindControl("ddlPrePollinatorSize")).SelectedValue); tempUserPayment.PollinatorType = Int32.Parse(((DropDownList)LoginView1.FindControl("ddlPrePollinatorType")).SelectedValue); tempUserPayment.PhotoUrl = ((TextBox)LoginView1.FindControl("txtPrePhotoUrl")).Text; tempUserPayment.YoutubeUrl = ((TextBox)LoginView1.FindControl("txtPreYoutubeUrl")).Text; tempUserPayment.Website = ((TextBox)LoginView1.FindControl("txtPreWebsite")).Text; tempUserPayment.Description = ((TextBox)LoginView1.FindControl("txtPreDescription")).Text; tempUserPayment.BillingAddress = ((TextBox)LoginView1.FindControl("txtPreBillingAddress")).Text; tempUserPayment.BillingCity = ((TextBox)LoginView1.FindControl("txtPreBillingCity")).Text; tempUserPayment.BillingState = ((TextBox)LoginView1.FindControl("txtPreBillingState")).Text; tempUserPayment.BillingZipcode = ((TextBox)LoginView1.FindControl("txtPreBillingZipcode")).Text; //save lat, long tempUserPayment.Latitude = decimal.Parse(hdnLat.Value); tempUserPayment.Longitude = decimal.Parse(hdnLng.Value); //save to TempUserPayments table mydb.TempUserPayments.Add(tempUserPayment); mydb.SaveChanges(); progress = 2;//set progress to step 2 //Payment: send request to Paypal //CreateUserWizard2.Visible = false; if (tempUserPayment != null) { //create cookie password string cookieSubName = HttpUtility.HtmlEncode(newUserId.ToString() + "pw"); string cookieSubValue = HttpUtility.HtmlEncode(password); Response.Cookies[newUserId.ToString()][cookieSubName] = cookieSubValue; Response.Cookies[newUserId.ToString()].Expires = DateTime.Now.AddHours(1); // get business account email from config string PaypalEmail = ConfigurationManager.AppSettings["PaypalSeller"]; //get payer email that user's email string PayerEmail = tempUserPayment.Email; // get variable environment from config bool SandboxEnvi = bool.Parse(ConfigurationManager.AppSettings["SandboxEnvironment"]); // get price from config string PaypalPrice = ConfigurationManager.AppSettings["PaypalPrice"]; // Callback url to handle process when payement is successful string ReturnUrl = "http://" + HttpContext.Current.Request["HTTP_HOST"] + "/ShareMap?payer=" + newUserId; // Callback url to handle process when IPN Paypal service notify string NotifyUrl = "http://" + HttpContext.Current.Request["HTTP_HOST"] + "/HandlerIPN.ashx"; // Callback url to handle process when payment is cancel string CancelUrl = "http://" + HttpContext.Current.Request["HTTP_HOST"] + "/ShareMap?payc=" + newUserId; //name of product string PaypalItemName = ConfigurationManager.AppSettings["PaypalItemName"]; //custom parram contain temp information of New User string custom = newUserId + ";" + password + ";add";//CreateUserWizard2.ContinueDestinationPageUrl; //for case test demo link included in a frame of client's domain string backUrl = ConfigurationManager.AppSettings["BackUrl"] + "?Step=12"; if (!String.IsNullOrEmpty(backUrl)) { ReturnUrl += "&backUrl=" + backUrl; } // generate a html form paypal IPN string string PaypalFormHtmlStr = "<form target='_parent' name='_xclick' action='" + ((SandboxEnvi) ? "https://www.sandbox.paypal.com/cgi-bin/webscr" : "https://www.paypal.com/cgi-bin/webscr") + "' method='post'>" + "<input type='hidden' name='cmd' value='_xclick'>" + "<input type='hidden' name='business' value='" + PaypalEmail + "'>" + "<input type='hidden' name='payer_email' value='" + PayerEmail + "'>" + "<input type='hidden' name='currency_code' value='USD'>" + "<input type='hidden' name='item_name' value='" + PaypalItemName + "'>" + "<input type='hidden' name='amount' value='" + PaypalPrice + "'>" + "<input type='hidden' name='custom' value='" + custom + "' />" + "<input type='hidden' name='return' value='" + ReturnUrl + "'>" + "<input type='hidden' name='notify_url' value='" + NotifyUrl + "'>" + "<input type='hidden' name='cancel_url' value='" + CancelUrl + "'>" + "<input type='image' id='paypal_btn' src='' border='0' name='submit' alt=''> </form>"; ScriptManager.RegisterStartupScript(this, this.GetType(), "paypal", "document.getElementById('paypal_container').innerHTML = \"" + PaypalFormHtmlStr + "\" ; document.getElementById('paypal_btn').click() ;", true); } //show process bar ScriptManager.RegisterStartupScript(this, this.GetType(), "popupWait", "document.getElementById('showProcessbar').click();", true); } catch (Exception ex) { //rollback if (progress == 1)//have just created User { System.Web.Security.Membership.DeleteUser(userName, true); } //show error message lblPreErrorMessage.Text = ex.Message; //write log Pollinator.Common.Logger.Error("Occured in function: " + typeof(Account_Register).Name + ".CreateUserWizard2_CreatedUser()", ex); //Response.Redirect("~/Default"); } }
protected void btnUpdate_Click(object sender, EventArgs e) { try { byte memberLevel = byte.Parse(HiddenMemberLevel.Value); if (memberLevel == 1)//upgrade from Normal to Premium { //premium ScriptManager.RegisterStartupScript(this, this.GetType(), "js", "document.getElementById('" + divRowRegNormal.ClientID + "').style.display='none';" + "document.getElementById('" + divRowRegPremium.ClientID + "').style.display='inline';", true); } else //normal { ScriptManager.RegisterStartupScript(this, this.GetType(), "js", "document.getElementById('" + divRowRegNormal.ClientID + "').style.display='inline';" + "document.getElementById('" + divRowRegPremium.ClientID + "').style.display='none';", true); } //user MembershipUser usr = System.Web.Security.Membership.GetUser(UserID); var userDetail = GetUserDetail(); if (userDetail == null) { userDetail = new UserDetail(); } var polinatorInformation = GetPolinatorInformation(); if (polinatorInformation == null) { polinatorInformation = new PolinatorInformation(); } //status polinatorInformation.IsApproved = false;//reset IsApproved = 0 polinatorInformation.IsNew = false; polinatorInformation.LastUpdated = DateTime.Now; //get new values from form and set to object to update if (memberLevel == 1 && userDetail.MembershipLevel == 0)//upgrade from Normal to Premium { //add info into UserDetail table var tempUserPaymentOld = (from tempUP in mydb.TempUserPayments where tempUP.UserId == UserID select tempUP).FirstOrDefault(); if (tempUserPaymentOld != null) { mydb.TempUserPayments.Remove(tempUserPaymentOld); } TempUserPayment tempUserPayment = new TempUserPayment(); tempUserPayment.UserId = UserID; //membership(user) tempUserPayment.Email = txtPreEmail.Text; //userDetail.MembershipLevel(have 2 levels): 0 is free; 1 is premium tempUserPayment.MembershipLevel = 1;//Premium tempUserPayment.FirstName = txtPreFirstName.Text; tempUserPayment.LastName = txtPreLastName.Text; tempUserPayment.PhoneNumber = txtPrePhoneNumber.Text; //tempUserPayment.OrganizationName = txtPreOrganizationName.Text; //table2: UserDetail tempUserPayment.OrganizationName = txtPreOrganizationName.Text; tempUserPayment.PollinatorSize = Int32.Parse(ddlPrePollinatorSize.SelectedValue); tempUserPayment.PollinatorType = Int32.Parse(ddlPrePollinatorType.SelectedValue); tempUserPayment.LandscapeStreet = txtPreLandscapeStreet.Text; tempUserPayment.LandscapeCity = txtPreLandscapeCity.Text; tempUserPayment.LandscapeState = txtPreLandscapeState.Text; tempUserPayment.LandscapeZipcode = txtPreLandscapeZipcode.Text; tempUserPayment.LandscapeCountry = ddlPreCountry.SelectedValue; tempUserPayment.PhotoUrl = txtPrePhotoUrl.Text; tempUserPayment.YoutubeUrl = txtPreYoutubeUrl.Text; tempUserPayment.Website = txtPreWebsite.Text; tempUserPayment.Description = txtPreDescription.Text; tempUserPayment.BillingAddress = txtPreBillingAddress.Text; tempUserPayment.BillingCity = txtPreBillingCity.Text; tempUserPayment.BillingState = txtPreBillingState.Text;; tempUserPayment.BillingZipcode = txtPreBillingZipcode.Text; //save lat, long tempUserPayment.Latitude = decimal.Parse(hdnLat.Value); tempUserPayment.Longitude = decimal.Parse(hdnLng.Value); //save userfolder //if (!string.IsNullOrEmpty(tempUserPayment.PhotoUrl)) //{ // string filePath = tempUserPayment.PhotoUrl.Split(';')[0]; // if (!string.IsNullOrEmpty(filePath)) // { // int index1 = filePath.LastIndexOf('/'); // if (index1 > 0) // { // filePath = filePath.Substring(0, index1).Trim(); // index1 = filePath.LastIndexOf('/'); // if (index1 > 0) // filePath = filePath.Substring(index1+1, filePath.Length-index1).Trim(); // tempUserPayment.UserFolder = HttpUtility.HtmlDecode(filePath); // } // } //} //createProcess //tempUserPayment.CreateProcess = 1; //tempUserPayment.CreateDate = DateTime.Now; //save to TempUserPayments table mydb.TempUserPayments.Add(tempUserPayment); mydb.SaveChanges();//submit temp table //Payment: send request to Paypal if (tempUserPayment != null) { // get business account email from config string PaypalEmail = ConfigurationManager.AppSettings["PaypalSeller"]; // get variable environment from config bool SandboxEnvi = bool.Parse(ConfigurationManager.AppSettings["SandboxEnvironment"]); // get price from config string PaypalPrice = ConfigurationManager.AppSettings["PaypalPrice"]; // Callback url to handle process when payement is successful string ReturnUrl = "http://" + HttpContext.Current.Request["HTTP_HOST"] + "/Members/Manage.aspx?payer=" + UserID; // Callback url to handle process when IPN Paypal service notify string NotifyUrl = "http://" + HttpContext.Current.Request["HTTP_HOST"] + "/HandlerIPN.ashx"; // Callback url to handle process when payment is cancel string CancelUrl = "http://" + HttpContext.Current.Request["HTTP_HOST"] + "/Members/Manage.aspx?payc=" + UserID; //name of product string PaypalItemName = ConfigurationManager.AppSettings["PaypalItemName"]; //custom parram contain temp information of New User string custom = UserID + ";password;change";//CreateUserWizard2.ContinueDestinationPageUrl; //end custom //Pollinator.Common.Logger.Information("Paypal Manage 2 ReturnUrl= " + ReturnUrl); // generate a html form paypal IPN string string PaypalFormHtmlStr = "<form target='_parent' name='_xclick' action='" + ((SandboxEnvi) ? "https://www.sandbox.paypal.com/cgi-bin/webscr" : "https://www.paypal.com/cgi-bin/webscr") + "' method='post'>" + "<input type='hidden' name='cmd' value='_xclick'>" + "<input type='hidden' name='business' value='" + PaypalEmail + "'>" + "<input type='hidden' name='payer_email' value='" + PaypalEmail + "'>" + "<input type='hidden' name='currency_code' value='USD'>" + "<input type='hidden' name='item_name' value='" + PaypalItemName + "'>" + "<input type='hidden' name='amount' value='" + PaypalPrice + "'>" + "<input type='hidden' name='custom' value='" + custom + "' />" + "<input type='hidden' name='return' value='" + ReturnUrl + "'>" + "<input type='hidden' name='notify_url' value='" + NotifyUrl + "'>" + "<input type='hidden' name='cancel_url' value='" + CancelUrl + "'>" + "<input type='image' id='paypal_btn' src='' border='0' name='submit' alt=''> </form>"; //Pollinator.Common.Logger.Information("Paypal Manage 3 PaypalFormHtmlStr= " + PaypalFormHtmlStr); //payment //string ExternalPaymemtlUrl = ConfigurationManager.AppSettings["ExternalPaymemtlUrl"]; //if (!String.IsNullOrEmpty(ExternalPaymemtlUrl))//external payment //{ // tempUserPayment.PaypalFormHtmlStr = PaypalFormHtmlStr; // mydb.SaveChanges(); // //redirect to external paymemt page // ScriptManager.RegisterStartupScript(this, this.GetType(), "popupWaitxxxx", "document.getElementById('MainContent_HyperLink123').click();", true); // //string urlRedirect = string.Format("{0}?userID={1}", ExternalPaymemtlUrl, tempUserPayment.UserId); // //ScriptManager.RegisterStartupScript(this, this.GetType(), "redirect", " window.location.replace(\"" + urlRedirect + "\");", true); //} //else // ScriptManager.RegisterStartupScript(this, this.GetType(), "paypal", "document.getElementById('paypal_container').innerHTML = \"" + PaypalFormHtmlStr + "\" ; document.getElementById('paypal_btn').click() ;", true); ScriptManager.RegisterStartupScript(this, this.GetType(), "paypal", "document.getElementById('paypal_container').innerHTML = \"" + PaypalFormHtmlStr + "\" ; document.getElementById('paypal_btn').click() ;", true); } //show please wait... popup ScriptManager.RegisterStartupScript(this, this.GetType(), "popupWait", "document.getElementById('showProcessbar').click();", true); } else { if (memberLevel == 0) { GetInfoFromFormNormal(usr, userDetail, polinatorInformation); } else { GetInfoFromFormPrenium(usr, userDetail, polinatorInformation); } if (usr != null) { System.Web.Security.Membership.UpdateUser(usr); } mydb.SaveChanges();//submit changed to DB //Auto Approved AutoApproveSubmission(usr, userDetail, polinatorInformation); ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "document.getElementById('confirm_pop').click();", true); } //Response.Redirect("~/ShareMap.aspx"); } catch (Exception ex) { byte memberLevel = byte.Parse(HiddenMemberLevel.Value); if (memberLevel == 1)//upgrade from Normal to Premium { //premium ScriptManager.RegisterStartupScript(this, this.GetType(), "js", "document.getElementById('" + divRowRegNormal.ClientID + "').style.display='none';" + "document.getElementById('" + divRowRegPremium.ClientID + "').style.display='inline';", true); } else { //normal ScriptManager.RegisterStartupScript(this, this.GetType(), "js", "document.getElementById('" + divRowRegNormal.ClientID + "').style.display='inline';" + "document.getElementById('" + divRowRegPremium.ClientID + "').style.display='none';", true); } //Response.Write(ex.ToString()); Pollinator.Common.Logger.Error("Error occured at " + typeof(Members_Manage).Name + ".btnUpdate_Click()", ex); GoToAlertMessage(panelErrorMessage); } }