private void PopulatePage(UserAccount u)
        {
            this.lblEmail.Text = u.Email;
            this.lblMemberSince.Text = u.DateCreated.ToLocalTime().ToShortDateString();

            LoadSubscriptionInformation();            
        }
 private void PopulatePage(UserAccount u)
 {
     SetCurrentStorePlan();
     if (MTApp.CurrentStore.StripeCustomerId.Trim().Length < 1)
     {
         this.pnlCreditCard.Visible = true;
     }
     else
     {
         this.pnlCreditCard.Visible = false;
     }
 }
 private void LoadBilling(UserAccount u)
 {
     MerchantTribe.Billing.Service svc = new MerchantTribe.Billing.Service(MerchantTribe.Commerce.WebAppSettings.ApplicationConnectionString);
     BillingAccount act = svc.Accounts.FindOrCreate(u.Email);
     if (act != null)
     {
         this.CreditCardInput1.LoadFromCardData(act.CreditCard);
         if (act.CreditCard.CardNumber == "4111111111111111")
         {
             this.CreditCardInput1.CardNumber = "";
         }
         this.txtZipCode.Text = act.BillingZipCode;
     }
 }
        public Accounts.UserAccount CurrentAdministrator(MerchantTribeApplication app)
        {
            if (!IsAdmin(app))
            {
                return(null);
            }
            Accounts.AccountService accountServices = Accounts.AccountService.InstantiateForDatabase(this);
            Accounts.UserAccount    admin           = accountServices.FindAdminUserByAuthTokenId(_adminAuthTokenId.Value);

            if (admin == null)
            {
                return(null);
            }
            if (admin.Id < 1)
            {
                return(null);
            }

            return(admin);
        }
Exemple #5
0
        private void DoSignUp(RegisterViewModel model)
        {
            bool storeOkay = false;

            MerchantTribe.Commerce.Accounts.Store testStore = new MerchantTribe.Commerce.Accounts.Store();
            testStore.StoreName = model.RegistrationData.storename;
            if (!testStore.IsValid())
            {
                foreach (MerchantTribe.Web.Validation.RuleViolation v in testStore.GetRuleViolations())
                {
                    RenderError(v, model);
                }
            }
            else
            {
                if (MTApp.AccountServices.StoreNameExists(testStore.StoreName))
                {
                    RenderError("storename", "A store with that name already exists. Choose another name and try again.", model);
                }
                else
                {
                    storeOkay = true;
                }
            }

            UserAccount u = MTApp.AccountServices.AdminUsers.FindByEmail(model.RegistrationData.email);

            if (u == null)
            {
                u = new MerchantTribe.Commerce.Accounts.UserAccount();
            }

            bool userOk = false;

            if (u.IsValid() && (u.Email == model.RegistrationData.email))
            {
                if (u.DoesPasswordMatch(model.RegistrationData.password))
                {
                    userOk = true;
                }
                else
                {
                    RenderError("email", "A user account with that email address already exists. If it's your account make sure you enter the exact same password as you usually use.", model);
                }
            }
            else
            {
                u                = new MerchantTribe.Commerce.Accounts.UserAccount();
                u.Email          = model.RegistrationData.email;
                u.HashedPassword = model.RegistrationData.password;

                if (u.IsValid())
                {
                    u.Status      = MerchantTribe.Commerce.Accounts.UserAccountStatus.Active;
                    u.DateCreated = DateTime.UtcNow;
                    userOk        = MTApp.AccountServices.AdminUsers.Create(u);
                    u             = MTApp.AccountServices.AdminUsers.FindByEmail(u.Email);
                }
                else
                {
                    foreach (MerchantTribe.Web.Validation.RuleViolation v in u.GetRuleViolations())
                    {
                        RenderError(v.ControlName, v.ErrorMessage, model);
                    }
                }
            }

            if (userOk && storeOkay)
            {
                try
                {
                    bool isPayPalLead = false;
                    if (MerchantTribe.Commerce.SessionManager.GetCookieString("PayPalLead", MTApp.CurrentStore) != string.Empty)
                    {
                        isPayPalLead = true;
                    }

                    decimal    rate    = 0;
                    HostedPlan thePlan = HostedPlan.FindById(model.RegistrationData.plan);
                    if (thePlan != null)
                    {
                        rate = thePlan.Rate;
                        if (isPayPalLead)
                        {
                            rate = 49;
                        }
                    }

                    MerchantTribe.Commerce.Accounts.Store s = MTApp.AccountServices.CreateAndSetupStore(model.RegistrationData.storename,
                                                                                                        u.Id,
                                                                                                        model.RegistrationData.storename + " store for " + model.RegistrationData.email,
                                                                                                        model.RegistrationData.plan,
                                                                                                        rate);
                    if (s != null)
                    {
                        string e  = MerchantTribe.Web.Cryptography.Base64.ConvertStringToBase64(u.Email);
                        string st = MerchantTribe.Web.Cryptography.Base64.ConvertStringToBase64(s.StoreName);

                        Response.Redirect("~/signup/ProcessSignUp?e=" + e + "&s=" + st);
                    }
                }
                catch (MerchantTribe.Commerce.Accounts.CreateStoreException cex)
                {
                    RenderError("storename", cex.Message, model);
                }
            }
        }
        private bool DowngradePlan(Store s, UserAccount a, HostedPlan newPlan, MerchantTribeApplication app)
        {
            int currentProductCount = app.CatalogServices.Products.FindAllCount(s.Id);
            if (currentProductCount > newPlan.MaxProducts) return false;

            s.CurrentPlanRate = newPlan.Rate;
            s.CurrentPlanPercent = newPlan.PercentageOfSales;
            //s.CurrentPlanDayOfMonth = DateTime.Now.Day;
            //if (s.CurrentPlanDayOfMonth > 28) s.CurrentPlanDayOfMonth = 28;

            s.PlanId = newPlan.Id;
            bool result = Stores.Update(s);
            if (result)
            {
                // Charge Card
                // Notify Admin of Change
                Utilities.MailServices.SendPlanDowngradeAlert(a, s);
            }
            return result;
        }
        private bool UpgradePlan(Store s, UserAccount a, HostedPlan newPlan)
        {
            s.CurrentPlanRate = newPlan.Rate;
            s.CurrentPlanPercent = newPlan.PercentageOfSales;
            s.CurrentPlanDayOfMonth = DateTime.Now.Day;
            if (s.CurrentPlanDayOfMonth > 28) s.CurrentPlanDayOfMonth = 28;

            s.PlanId = newPlan.Id;
            bool result = Stores.Update(s);
            if (result)
            {
                // Charge Card
                // Notify Admin of Change
                Utilities.MailServices.SendPlanUpgradeAlert(a, s);
            }
            return result;
        }
        public bool AddUserToStoreByEmail(long storeId, string email, StoreAccessMode mode)
        {
            UserAccount u = AdminUsers.FindByEmail(email);
            if (u == null)
            {
                u = new UserAccount();
                u.Email = email;
                string password = Utilities.PasswordGenerator.GeneratePassword();
                u.HashedPassword = password;
                AdminUsers.Create(u);
            }

            if (AddUserToStore(storeId, u.Id, mode))
            {
                Store s = Stores.FindById(storeId);
                Utilities.MailServices.SendAccountInformation(u, s);
                return true;
            }

            return false;
        }
        private Store CreateIndividualStore()
        {
            Store s = null;

            string storeName = "www";

            s = new Store();
            s.StoreName = Text.ForceAlphaNumericOnly(storeName).ToLower();
            s.Status = StoreStatus.Active;
            s.DateCreated = DateTime.UtcNow;
            s.PlanId = 99;
            s.CustomUrl = string.Empty;

            if (!Stores.Create(s))
            {
                throw new CreateStoreException("Unable to create store. Unknown error. Please contact an administrator for assistance.");
            }

            s = Stores.FindByStoreName(s.StoreName);
            if (s != null)
            {
                UserAccount mainAccount = new UserAccount();
                mainAccount.Email = "*****@*****.**";
                mainAccount.HashedPassword = "******";
                mainAccount.Status = UserAccountStatus.Active;
                AdminUsers.Create(mainAccount);
                mainAccount = AdminUsers.FindByEmail(mainAccount.Email);

                AddUserToStore(s.Id, mainAccount.Id, StoreAccessMode.Owner);

                s.Settings.FriendlyName = "My MerchantTribe Store";
                s.Settings.MailServer.FromEmail = "*****@*****.**";
                s.Settings.LastOrderNumber = 0;
                s.Settings.LogoImage = "[[default]]";
                s.Settings.LogoRevision = 0;
                s.Settings.UseLogoImage = false;
                s.Settings.LogoText = s.StoreName;
                s.Settings.MinumumOrderAmount = 0;
                s.Settings.MailServer.EmailForGeneral = mainAccount.Email;
                s.Settings.MailServer.EmailForNewOrder = mainAccount.Email;
                s.Settings.MailServer.UseCustomMailServer = false;
                s.Settings.ProductReviewCount = 3;
                s.Settings.ProductReviewModerate = true;
                s.Settings.ProductReviewShowRating = true;
                s.Settings.PayPal.FastSignupEmail = mainAccount.Email;
                s.Settings.PayPal.Currency = "USD";
                s.Settings.MaxItemsPerOrder = 999;
                s.CurrentPlanRate = 0;
                s.CurrentPlanDayOfMonth = DateTime.Now.Day;
                s.CurrentPlanPercent = 0;

                // Save data to store
                Stores.Update(s);

                // No longer need to redirect because home controller handles this
                //System.Web.HttpContext.Current.Response.Redirect("~/adminaccount/login?wizard=1");

                // Force this store into the request context so
                // non-repository datalayer will read in the correct
                // store id
                //RequestContext demoContext = new RequestContext();
                //demoContext.CurrentStore = s;
                //RequestContext.ForceCurrentRequestContext(demoContext);

                //// Add Sample Data
                //AddSampleProductsToStore(demoContext);

                //// Set a default theme
                //Content.ThemeManager m = new Content.ThemeManager(demoContext);
                //m.InstallTheme("cf09d318-3792-47b8-a207-a9502f96f0f9");
            }

            return s;
        }
        private void DoSignUp(RegisterViewModel model)
        {                                                
            bool storeOkay = false;

            MerchantTribe.Commerce.Accounts.Store testStore = new MerchantTribe.Commerce.Accounts.Store();
            testStore.StoreName = model.RegistrationData.storename;
            if (!testStore.IsValid())
            {
                foreach (MerchantTribe.Web.Validation.RuleViolation v in testStore.GetRuleViolations())
                {
                    RenderError(v, model);
                }
            }
            else
            {
                if (MTApp.AccountServices.StoreNameExists(testStore.StoreName))
                {
                    RenderError("storename", "A store with that name already exists. Choose another name and try again.", model);
                }
                else
                {
                    storeOkay = true;
                }
            }                        

            UserAccount u = MTApp.AccountServices.AdminUsers.FindByEmail(model.RegistrationData.email);

            if (u == null)
            {
                u = new MerchantTribe.Commerce.Accounts.UserAccount();
            }

            bool userOk = false;
            if (u.IsValid() && (u.Email == model.RegistrationData.email))
            {
                if (u.DoesPasswordMatch(model.RegistrationData.password))
                {
                    userOk = true;
                }
                else
                {
                    RenderError("email", "A user account with that email address already exists. If it's your account make sure you enter the exact same password as you usually use.", model);
                }
            }
            else
            {
                u = new MerchantTribe.Commerce.Accounts.UserAccount();
                u.Email = model.RegistrationData.email;
                u.HashedPassword = model.RegistrationData.password;

                if (u.IsValid())
                {
                    u.Status = MerchantTribe.Commerce.Accounts.UserAccountStatus.Active;
                    u.DateCreated = DateTime.UtcNow;
                    userOk = MTApp.AccountServices.AdminUsers.Create(u);
                    u = MTApp.AccountServices.AdminUsers.FindByEmail(u.Email);
                }
                else
                {
                    foreach (MerchantTribe.Web.Validation.RuleViolation v in u.GetRuleViolations())
                    {
                        RenderError(v.ControlName, v.ErrorMessage, model);
                    }
                }
            }

            if (userOk && storeOkay)
            {
                try
                {                    
                    bool isPayPalLead = false;
                    if (MerchantTribe.Commerce.SessionManager.GetCookieString("PayPalLead", MTApp.CurrentStore) != string.Empty)
                    {
                        isPayPalLead = true;
                    }

                    decimal rate = 0;
                    HostedPlan thePlan = HostedPlan.FindById(model.RegistrationData.plan);
                    if (thePlan != null)
                    {
                        rate = thePlan.Rate;
                        if (isPayPalLead)
                        {
                            rate = 49;
                        }
                    }

                    MerchantTribe.Commerce.Accounts.Store s = MTApp.AccountServices.CreateAndSetupStore(model.RegistrationData.storename,
                                                                u.Id,
                                                                model.RegistrationData.storename + " store for " + model.RegistrationData.email,
                                                                model.RegistrationData.plan,
                                                                rate);
                    if (s != null)
                    {                        

                        string e = MerchantTribe.Web.Cryptography.Base64.ConvertStringToBase64(u.Email);
                        string st = MerchantTribe.Web.Cryptography.Base64.ConvertStringToBase64(s.StoreName);

                        Response.Redirect("~/signup/ProcessSignUp?e=" + e + "&s=" + st);                        
                    }
                }
                catch (MerchantTribe.Commerce.Accounts.CreateStoreException cex)
                {
                    RenderError("storename", cex.Message, model);
                }
            }
        }
Exemple #11
0
        private void DoSignUp(RegisterViewModel model)
        {
            bool storeOkay = false;

            if (model.RegistrationData.plan == 0)
            {
                // Fake CC information so that signup is easier
                model.RegistrationData.cardholder     = model.RegistrationData.email;
                model.RegistrationData.cardnumber     = "4111111111111111";
                model.RegistrationData.billingzipcode = "00000";
                model.RegistrationData.expyear        = DateTime.Now.AddYears(1).Year;
                model.RegistrationData.expmonth       = DateTime.Now.Month;
            }

            MerchantTribe.Commerce.Accounts.Store testStore = new MerchantTribe.Commerce.Accounts.Store();
            testStore.StoreName = model.RegistrationData.storename;
            if (!testStore.IsValid())
            {
                foreach (MerchantTribe.Web.Validation.RuleViolation v in testStore.GetRuleViolations())
                {
                    RenderError(v, model);
                }
            }
            else
            {
                if (MTApp.AccountServices.StoreNameExists(testStore.StoreName))
                {
                    RenderError("storename", "A store with that name already exists. Choose another name and try again.", model);
                }
                else
                {
                    storeOkay = true;
                }
            }

            // Check credit card number
            bool cardOkay = true;

            if (!MerchantTribe.Payment.CardValidator.IsCardNumberValid(model.RegistrationData.cardnumber))
            {
                cardOkay = false;
                RenderError("cardnumber", "Please enter a valid credit card number", model);
            }
            if (model.RegistrationData.cardholder.Trim().Length < 1)
            {
                cardOkay = false;
                RenderError("cardholder", "Please enter the name on your credit card.", model);
            }
            if (model.RegistrationData.billingzipcode.Trim().Length < 5)
            {
                cardOkay = false;
                RenderError("billingzipcode", "Please enter the billing zip code for your credit card.", model);
            }

            UserAccount u = MTApp.AccountServices.AdminUsers.FindByEmail(model.RegistrationData.email);

            if (u == null)
            {
                u = new MerchantTribe.Commerce.Accounts.UserAccount();
            }

            bool userOk = false;

            if (u.IsValid() && (u.Email == model.RegistrationData.email))
            {
                if (u.DoesPasswordMatch(model.RegistrationData.password))
                {
                    userOk = true;
                }
                else
                {
                    RenderError("email", "A user account with that email address already exists. If it's your account make sure you enter the exact same password as you usually use.", model);
                }
            }
            else
            {
                u                = new MerchantTribe.Commerce.Accounts.UserAccount();
                u.Email          = model.RegistrationData.email;
                u.HashedPassword = model.RegistrationData.password;

                if (u.IsValid())
                {
                    u.Status      = MerchantTribe.Commerce.Accounts.UserAccountStatus.Active;
                    u.DateCreated = DateTime.UtcNow;
                    userOk        = MTApp.AccountServices.AdminUsers.Create(u);
                    u             = MTApp.AccountServices.AdminUsers.FindByEmail(u.Email);
                }
                else
                {
                    foreach (MerchantTribe.Web.Validation.RuleViolation v in u.GetRuleViolations())
                    {
                        RenderError(v.ControlName, v.ErrorMessage, model);
                    }
                }
            }

            if (userOk && storeOkay && cardOkay)
            {
                try
                {
                    MerchantTribe.Billing.BillingAccount billingAccount = new MerchantTribe.Billing.BillingAccount();
                    billingAccount.Email                      = u.Email;
                    billingAccount.BillingZipCode             = model.RegistrationData.billingzipcode;
                    billingAccount.CreditCard.CardNumber      = model.RegistrationData.cardnumber;
                    billingAccount.CreditCard.ExpirationMonth = model.RegistrationData.expmonth;
                    billingAccount.CreditCard.ExpirationYear  = model.RegistrationData.expyear;
                    billingAccount.CreditCard.CardHolderName  = model.RegistrationData.cardholder;

                    bool isPayPalLead = false;
                    if (MerchantTribe.Commerce.SessionManager.GetCookieString("PayPalLead", MTApp.CurrentStore) != string.Empty)
                    {
                        isPayPalLead = true;
                    }

                    decimal    rate    = 0;
                    HostedPlan thePlan = HostedPlan.FindById(model.RegistrationData.plan);
                    if (thePlan != null)
                    {
                        rate = thePlan.Rate;
                        if (isPayPalLead)
                        {
                            rate = 49;
                        }
                    }

                    MerchantTribe.Commerce.Accounts.Store s = MTApp.AccountServices.CreateAndSetupStore(model.RegistrationData.storename,
                                                                                                        u.Id,
                                                                                                        model.RegistrationData.storename + " store for " + model.RegistrationData.email,
                                                                                                        model.RegistrationData.plan,
                                                                                                        rate,
                                                                                                        billingAccount);
                    if (s != null)
                    {
                        string e  = MerchantTribe.Web.Cryptography.Base64.ConvertStringToBase64(u.Email);
                        string st = MerchantTribe.Web.Cryptography.Base64.ConvertStringToBase64(s.StoreName);

                        Response.Redirect("~/signup/ProcessSignUp?e=" + e + "&s=" + st);

                        //this.completeemail.Text = u.Email;
                        //this.completestorelink.Text = "<a href=\"" + s.RootUrl() + "\">" + s.RootUrl() + "</a>";
                        //this.completestorelinkadmin.Text = "<a href=\"" + s.RootUrlSecure() + "bvadmin\">" + s.RootUrlSecure() + "bvadmin</a>";
                        //this.completebiglogin.Text = "<a href=\"" + s.RootUrlSecure() + "adminaccount/login?wizard=1&username="******"\">Next Step &raquo; Choose a Theme</a>";
                        //this.pnlComplete.Visible = true;
                        //this.pnlMain.Visible = false;
                    }
                }
                catch (MerchantTribe.Commerce.Accounts.CreateStoreException cex)
                {
                    RenderError("storename", cex.Message, model);
                }
            }
        }
 private Store FindValidStoreForUser(UserAccount u, long storeId)
 {
     return MTApp.AccountServices.FindStoreByIdForUser(storeId, u.Id);
 }
 private void PopulatePage(UserAccount u)
 {
     this.litCurrentEmail.Text = u.Email;            
 }
 private void PopulatePage(UserAccount u)
 {
     SetCurrentStore();
     LoadBilling(u);
 }
        private Store CreateIndividualStore()
        {
            Store s = null;

            string storeName = "www";

            s             = new Store();
            s.StoreName   = Text.ForceAlphaNumericOnly(storeName).ToLower();
            s.Status      = StoreStatus.Active;
            s.DateCreated = DateTime.UtcNow;
            s.PlanId      = 99;
            s.CustomUrl   = string.Empty;

            if (!Stores.Create(s))
            {
                throw new CreateStoreException("Unable to create store. Unknown error. Please contact an administrator for assistance.");
            }

            s = Stores.FindByStoreName(s.StoreName);
            if (s != null)
            {
                UserAccount mainAccount = new UserAccount();
                mainAccount.Email          = "*****@*****.**";
                mainAccount.HashedPassword = "******";
                mainAccount.Status         = UserAccountStatus.Active;
                AdminUsers.Create(mainAccount);
                mainAccount = AdminUsers.FindByEmail(mainAccount.Email);

                AddUserToStore(s.Id, mainAccount.Id, StoreAccessMode.Owner);

                s.Settings.FriendlyName                   = "My MerchantTribe Store";
                s.Settings.MailServer.FromEmail           = "*****@*****.**";
                s.Settings.LastOrderNumber                = 0;
                s.Settings.LogoImage                      = "[[default]]";
                s.Settings.LogoRevision                   = 0;
                s.Settings.UseLogoImage                   = false;
                s.Settings.LogoText                       = s.StoreName;
                s.Settings.MinumumOrderAmount             = 0;
                s.Settings.MailServer.EmailForGeneral     = mainAccount.Email;
                s.Settings.MailServer.EmailForNewOrder    = mainAccount.Email;
                s.Settings.MailServer.UseCustomMailServer = false;
                s.Settings.ProductReviewCount             = 3;
                s.Settings.ProductReviewModerate          = true;
                s.Settings.ProductReviewShowRating        = true;
                s.Settings.PayPal.FastSignupEmail         = mainAccount.Email;
                s.Settings.PayPal.Currency                = "USD";
                s.Settings.MaxItemsPerOrder               = 999;
                s.CurrentPlanRate       = 0;
                s.CurrentPlanDayOfMonth = DateTime.Now.Day;
                s.CurrentPlanPercent    = 0;

                // Save data to store
                Stores.Update(s);

                // No longer need to redirect because home controller handles this
                //System.Web.HttpContext.Current.Response.Redirect("~/adminaccount/login?wizard=1");

                // Force this store into the request context so
                // non-repository datalayer will read in the correct
                // store id
                //RequestContext demoContext = new RequestContext();
                //demoContext.CurrentStore = s;
                //RequestContext.ForceCurrentRequestContext(demoContext);

                //// Add Sample Data
                //AddSampleProductsToStore(demoContext);

                //// Set a default theme
                //Content.ThemeManager m = new Content.ThemeManager(demoContext);
                //m.InstallTheme("cf09d318-3792-47b8-a207-a9502f96f0f9");
            }

            return(s);
        }
        private void LoadBilling(UserAccount u)
        {
            MerchantTribe.Billing.Service svc = new MerchantTribe.Billing.Service(MerchantTribe.Commerce.WebAppSettings.ApplicationConnectionString);
            BillingAccount act = svc.Accounts.FindOrCreate(u.Email);
            if (act != null)
            {

                this.lblCardOnFile.Text = act.CreditCard.CardTypeName + "-" + act.CreditCard.CardNumberLast4Digits + "<br />";
                this.lblCardOnFile.Text += "Expires: " + act.CreditCard.ExpirationMonth + "/" + act.CreditCard.ExpirationYear + "<br />";
                this.lblCardOnFile.Text += "Billing Zip: " + act.BillingZipCode;

                if (act.CreditCard.CardNumber == "4111111111111111") this.lblCardOnFile.Text = "&nbsp;<br /><b>No Card On File.</b> Add One before choosing a plan!<br />&nbsp;";
            }
        }
        private void DoSignUp(RegisterViewModel model)
        {
            bool storeOkay = false;

            if (model.RegistrationData.plan == 0)
            {
                // Fake CC information so that signup is easier
                model.RegistrationData.cardholder = model.RegistrationData.email;
                model.RegistrationData.cardnumber = "4111111111111111";
                model.RegistrationData.billingzipcode = "00000";
                model.RegistrationData.expyear = DateTime.Now.AddYears(1).Year;
                model.RegistrationData.expmonth = DateTime.Now.Month;
            }

            MerchantTribe.Commerce.Accounts.Store testStore = new MerchantTribe.Commerce.Accounts.Store();
            testStore.StoreName = model.RegistrationData.storename;
            if (!testStore.IsValid())
            {
                foreach (MerchantTribe.Web.Validation.RuleViolation v in testStore.GetRuleViolations())
                {
                    RenderError(v, model);
                }
            }
            else
            {
                if (MTApp.AccountServices.StoreNameExists(testStore.StoreName))
                {
                    RenderError("storename", "A store with that name already exists. Choose another name and try again.", model);
                }
                else
                {
                    storeOkay = true;
                }
            }

            // Check credit card number
            bool cardOkay = true;
            if (!MerchantTribe.Payment.CardValidator.IsCardNumberValid(model.RegistrationData.cardnumber))
            {
                cardOkay = false;
                RenderError("cardnumber", "Please enter a valid credit card number", model);
            }
            if (model.RegistrationData.cardholder.Trim().Length < 1)
            {
                cardOkay = false;
                RenderError("cardholder", "Please enter the name on your credit card.", model);
            }
            if (model.RegistrationData.billingzipcode.Trim().Length < 5)
            {
                cardOkay = false;
                RenderError("billingzipcode", "Please enter the billing zip code for your credit card.", model);
            }

            UserAccount u = MTApp.AccountServices.AdminUsers.FindByEmail(model.RegistrationData.email);

            if (u == null)
            {
                u = new MerchantTribe.Commerce.Accounts.UserAccount();
            }

            bool userOk = false;
            if (u.IsValid() && (u.Email == model.RegistrationData.email))
            {
                if (u.DoesPasswordMatch(model.RegistrationData.password))
                {
                    userOk = true;
                }
                else
                {
                    RenderError("email", "A user account with that email address already exists. If it's your account make sure you enter the exact same password as you usually use.", model);
                }
            }
            else
            {
                u = new MerchantTribe.Commerce.Accounts.UserAccount();
                u.Email = model.RegistrationData.email;
                u.HashedPassword = model.RegistrationData.password;

                if (u.IsValid())
                {
                    u.Status = MerchantTribe.Commerce.Accounts.UserAccountStatus.Active;
                    u.DateCreated = DateTime.UtcNow;
                    userOk = MTApp.AccountServices.AdminUsers.Create(u);
                    u = MTApp.AccountServices.AdminUsers.FindByEmail(u.Email);
                }
                else
                {
                    foreach (MerchantTribe.Web.Validation.RuleViolation v in u.GetRuleViolations())
                    {
                        RenderError(v.ControlName, v.ErrorMessage, model);
                    }
                }
            }

            if (userOk && storeOkay && cardOkay)
            {
                try
                {
                    MerchantTribe.Billing.BillingAccount billingAccount = new MerchantTribe.Billing.BillingAccount();
                    billingAccount.Email = u.Email;
                    billingAccount.BillingZipCode = model.RegistrationData.billingzipcode;
                    billingAccount.CreditCard.CardNumber = model.RegistrationData.cardnumber;
                    billingAccount.CreditCard.ExpirationMonth = model.RegistrationData.expmonth;
                    billingAccount.CreditCard.ExpirationYear = model.RegistrationData.expyear;
                    billingAccount.CreditCard.CardHolderName = model.RegistrationData.cardholder;

                    bool isPayPalLead = false;
                    if (MerchantTribe.Commerce.SessionManager.GetCookieString("PayPalLead", MTApp.CurrentStore) != string.Empty)
                    {
                        isPayPalLead = true;
                    }

                    decimal rate = 0;
                    HostedPlan thePlan = HostedPlan.FindById(model.RegistrationData.plan);
                    if (thePlan != null)
                    {
                        rate = thePlan.Rate;
                        if (isPayPalLead)
                        {
                            rate = 49;
                        }
                    }

                    MerchantTribe.Commerce.Accounts.Store s = MTApp.AccountServices.CreateAndSetupStore(model.RegistrationData.storename,
                                                                u.Id,
                                                                model.RegistrationData.storename + " store for " + model.RegistrationData.email,
                                                                model.RegistrationData.plan,
                                                                rate,
                                                                billingAccount);
                    if (s != null)
                    {

                        string e = MerchantTribe.Web.Cryptography.Base64.ConvertStringToBase64(u.Email);
                        string st = MerchantTribe.Web.Cryptography.Base64.ConvertStringToBase64(s.StoreName);

                        Response.Redirect("~/signup/ProcessSignUp?e=" + e + "&s=" + st);

                        //this.completeemail.Text = u.Email;
                        //this.completestorelink.Text = "<a href=\"" + s.RootUrl() + "\">" + s.RootUrl() + "</a>";
                        //this.completestorelinkadmin.Text = "<a href=\"" + s.RootUrlSecure() + "bvadmin\">" + s.RootUrlSecure() + "bvadmin</a>";
                        //this.completebiglogin.Text = "<a href=\"" + s.RootUrlSecure() + "adminaccount/login?wizard=1&username="******"\">Next Step &raquo; Choose a Theme</a>";
                        //this.pnlComplete.Visible = true;
                        //this.pnlMain.Visible = false;
                    }
                }
                catch (MerchantTribe.Commerce.Accounts.CreateStoreException cex)
                {
                    RenderError("storename", cex.Message, model);
                }
            }
        }
        // working with local dates and times
        public static void GenerateInvoiceForStore(Store s, DateTime invoiceDateLocal, MerchantTribeApplication app)
        {
            // Create an Order
            Orders.Order o = new Orders.Order();
            o.StoreId = WebAppSettings.BillingStoreId;
            app.OrderServices.Orders.Create(o);

            o.Notes.Add(new Orders.OrderNote()
            {
                IsPublic = false, Note = "Auto Generated By Invoicing System"
            });

            // Base Rate
            Orders.LineItem li = new Orders.LineItem();
            li.BasePricePerItem = s.CurrentPlanRate;
            li.ProductName      = "BV Commerce Hosted: " + s.PlanName;
            li.ProductSku       = "BVH" + s.PlanId;
            li.Quantity         = 1;
            li.QuantityShipped  = 1;
            li.ShippingSchedule = -1;
            o.Items.Add(li);

            // need to add Percent of sales
            decimal lastMonthSales = 0;
            // End date should be immediately before bill not, not on the bill date
            DateTime localEnd = Dates.MaxOutTime(invoiceDateLocal);

            localEnd = localEnd.AddDays(-1);
            DateTime localStart = Dates.ZeroOutTime(invoiceDateLocal).AddMonths(-1);

            lastMonthSales = app.OrderServices.Transactions.FindBillableTransactionTotal(localStart.ToUniversalTime(),
                                                                                         localEnd.ToUniversalTime(),
                                                                                         s.Id);
            Orders.LineItem li2        = new Orders.LineItem();
            Decimal         multiplier = s.CurrentPlanPercent / 100;
            Decimal         transFees  = Math.Round(multiplier * lastMonthSales, 2);

            li2.BasePricePerItem         = transFees;
            li2.ProductName              = "Transaction Fees:";
            li2.ProductShortDescription  = s.CurrentPlanPercent + "% of " + lastMonthSales.ToString("c");
            li2.ProductShortDescription += " " + localStart.ToShortDateString() + " to " + localEnd.ToShortDateString();
            li2.ProductSku       = "BVHTF";
            li2.Quantity         = 1;
            li2.QuantityShipped  = 1;
            li2.ShippingSchedule = -1;
            o.Items.Add(li2);

            List <UserAccount> users = app.AccountServices.FindAdminUsersByStoreId(s.Id);

            if (users != null)
            {
                if (users.Count > 0)
                {
                    UserAccount u = users[0];
                    o.UserEmail = u.Email;

                    Service        svc = new Service(WebAppSettings.ApplicationConnectionString);
                    BillingAccount act = svc.Accounts.FindOrCreate(u.Email);
                    if (act != null)
                    {
                        o.BillingAddress.RegionData.Abbreviation = string.Empty;
                        o.BillingAddress.RegionName = string.Empty;
                        o.BillingAddress.PostalCode = act.BillingZipCode;
                        o.BillingAddress.FirstName  = act.CreditCard.CardHolderName;
                        o.BillingAddress.Company    = s.StoreName;

                        app.CalculateOrder(o);

                        Orders.OrderPaymentManager payManager = new Orders.OrderPaymentManager(o, app);
                        payManager.CreditCardAddInfo(act.CreditCard, o.TotalGrand);

                        o.OrderNumber    = app.OrderServices.GenerateNewOrderNumber(WebAppSettings.BillingStoreId).ToString();
                        o.StatusCode     = Orders.OrderStatusCode.Received;
                        o.IsPlaced       = true;
                        o.TimeOfOrderUtc = DateTime.UtcNow;
                        o.EvaluateCurrentShippingStatus();

                        app.OrderServices.Orders.Update(o);
                    }
                }
            }
        }
        private void LoadStores(UserAccount u)
        {
            List<Store> stores = MTApp.AccountServices.FindStoresForUserId(u.Id);

            StringBuilder sb = new StringBuilder();

            foreach (Store s in stores)
            {
                RenderStore(s, sb);
            }

            this.litStores.Text = sb.ToString();
        }
        private void PopulatePage(UserAccount u)
        {
            this.lblEmail.Text = u.Email;
            this.lblMemberSince.Text = u.DateCreated.ToLocalTime().ToShortDateString();

            LoadStores(u);
            LoadBilling(u);
        }