コード例 #1
0
        protected void Page_PreRender(object sender, EventArgs e)
        {
            //GET ANY MESSAGES FROM SESSION
            IList <string> sessionMessages = Session["BasketMessage"] as IList <string>;
            //GET THE BASKET AND RECALCULATE
            Basket         basket             = AbleContext.Current.User.Basket;
            IBasketService preCheckoutService = AbleContext.Resolve <IBasketService>();

            preCheckoutService.Recalculate(basket);
            foreach (var rec in basket.Items)
            {
                rec.Price = Math.Abs(rec.Price);
            }
            //VALIDATE THE BASKET
            ValidationResponse response = preCheckoutService.Validate(basket);

            //DISPLAY ANY WARNING MESSAGES
            if ((!response.Success) || (sessionMessages != null))
            {
                if (sessionMessages != null)
                {
                    Session.Remove("BasketMessage");
                    sessionMessages.AddRange(response.WarningMessages);
                    WarningMessageList.DataSource = sessionMessages;
                }
                else
                {
                    WarningMessageList.DataSource = response.WarningMessages;
                }
                WarningMessageList.DataBind();
            }
            BindBasketGrid();
        }
コード例 #2
0
        private bool PayOrder(Payment payment)
        {
            bool hasGateway = false;

            if (payment.PaymentMethod != null)
            {
                hasGateway = (payment.PaymentMethod.PaymentGateway != null);
            }
            else if (payment.PaymentProfile != null)
            {
                int            gatewayId = PaymentGatewayDataSource.GetPaymentGatewayIdByClassId(payment.PaymentProfile.GatewayIdentifier);
                PaymentGateway gateway   = PaymentGatewayDataSource.Load(gatewayId);
                hasGateway = (gateway != null);
            }

            if (hasGateway)
            {
                // PRESERVE ACCOUNT DATA FOR PROCESSING
                string accountData = payment.AccountData;
                payment.AccountData = string.Empty;

                // SAVE PAYMENT
                this.Order.Payments.Add(payment);
                this.Order.Save(true, true);

                // PROCESS PAYMENT WITH SAVED ACCOUNT DATA
                payment.AccountData = accountData;
                payment.Authorize(false);
                if (payment.PaymentStatus == PaymentStatus.AuthorizationFailed)
                {
                    // VOID PAYMENT AND SHOW ERRORS TO CUSTOMER
                    payment.Void();
                    List <string> errorList = new List <string>();
                    errorList.Add(payment.Transactions[0].ResponseMessage);
                    WarningMessageList.DataSource = errorList;
                    WarningMessageList.DataBind();
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                //SAVE PAYMENT
                this.Order.Payments.Add(payment);
                this.Order.Save(true, true);
                return(true);
            }
        }
コード例 #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // VALIDATE THE WISHLIST
            Wishlist      wishlist = AbleContext.Current.User.PrimaryWishlist;
            List <string> warnMessages;
            bool          isValid = wishlist.Validate(out warnMessages);

            // DISPLAY ANY WARNING MESSAGES
            if (!isValid)
            {
                WarningMessageList.DataSource = warnMessages;
                WarningMessageList.DataBind();
            }

            RegisterLink.NavigateUrl = NavigationHelper.GetMobileStoreUrl("~/Login.aspx");
        }
コード例 #4
0
        void CheckedOut(object sender, CheckedOutEventArgs e)
        {
            CheckoutResponse response = e.CheckoutResponse;

            if (response.Success)
            {
                // STOP TRACKING THE ANONYMOUS USER
                Session["CreateOrder_AnonUserId"] = null;

                // CREATE / LINK USER ACCOUNT IF NEEDED
                if (RegisterPanel.Visible && CreateAccount.Checked)
                {
                    if (_ExistingUser == null)
                    {
                        // THERE IS NO EXISTING ACCOUNT, SO CREATE A NEW USER
                        string email = _User.PrimaryAddress.Email;
                        _User.UserName   = email;
                        _User.Email      = email;
                        _User.IsApproved = true;
                        _User.Save();
                        _User.SetPassword(Password.Text);
                        _User.Passwords[0].ForceExpiration = ForceExpiration.Checked;
                        _User.Save();
                    }
                    else
                    {
                        // THERE IS AN EXISTING USER, SO MIGRATE THIS ORDER
                        OrderDataSource.UpdateUser(_UserId, _ExistingUser.Id);
                        AddressDataSource.UpdateUser(_UserId, _ExistingUser.Id);
                    }
                }

                // REDIRECT TO THE FINAL ORDER
                Response.Redirect("~/Admin/Orders/ViewOrder.aspx?OrderNumber=" + response.Order.OrderNumber);
            }
            else
            {
                // SHOW ERRORS TO CUSTOMER
                WarningMessageList.DataSource = e.CheckoutResponse.WarningMessages;
                WarningMessageList.DataBind();
            }
        }
コード例 #5
0
        private bool CreateAccount()
        {
            // NEED TO REGISTER USER
            if (AbleContext.Current.User.IsAnonymous)
            {
                // VALIDATE EMAIL, IF EMAIL IS ALREADY REGISTERED, ASK FOR LOGIN
                string newEmail = StringHelper.StripHtml(Email.Text);
                if (UserDataSource.IsEmailRegistered(newEmail))
                {
                    IList <string> warningMessages = new List <string>();
                    warningMessages.Add("The email address you have provided is already registered.Please sign in to access your account.");
                    WarningMessageList.DataSource = warningMessages;
                    WarningMessageList.DataBind();
                    return(false);
                }

                // ANONYMOUS USER SELECTING GUEST CHECKOUT, CREATE TEMPORARY ACCOUNT
                User   oldUser     = AbleContext.Current.User;
                string newUserName = "******" + Guid.NewGuid().ToString("N") + "@domain.xyz";
                string newPassword = Guid.NewGuid().ToString("N");
                MembershipCreateStatus createStatus;
                User newUser = UserDataSource.CreateUser(newUserName, newEmail, newPassword, string.Empty, string.Empty, true, 0, out createStatus);

                // IF THE CREATE FAILS, IGNORE AND CONTINUE CREATING THE ORDER
                if (createStatus == MembershipCreateStatus.Success)
                {
                    // CHANGE THE NAME AND EMAIL TO SOMETHING MORE FRIENDLY THAN GUID
                    newUser.UserName                   = "******" + newUser.Id.ToString() + "@domain.xyz";
                    newUser.PrimaryAddress.Email       = newEmail;
                    newUser.PrimaryAddress.CountryCode = AbleContext.Current.Store.DefaultWarehouse.CountryCode;
                    newUser.PrimaryAddress.IsBilling   = true;
                    newUser.PrimaryAddress.Residence   = true;
                    newUser.Save();
                    CommerceBuilder.Users.User.Migrate(oldUser, newUser, true, true);
                    AbleContext.Current.User = newUser;
                    FormsAuthentication.SetAuthCookie(newUser.UserName, false);
                }
            }

            return(true);
        }
コード例 #6
0
        private void HandleCheckoutResponse(object sender, CheckedOutEventArgs e)
        {
            if (!e.CheckoutResponse.Success)
            {
                // SHOW ERRORS TO CUSTOMER
                WarningMessageList.DataSource = e.CheckoutResponse.WarningMessages;
                WarningMessageList.DataBind();

                // protect against repeated failures
                IncreaseFailureCount();
                int failureCount = GetFailureCount();
                if (failureCount >= _MaxPaymentFailures)
                {
                    DisablePayments();
                }
            }

            if (CheckedOut != null)
            {
                CheckedOut(this, e);
            }
        }
コード例 #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // VALIDATE THE WISHLIST
            Wishlist      wishlist = AbleContext.Current.User.PrimaryWishlist;
            List <string> warnMessages;
            bool          isValid = wishlist.Validate(out warnMessages);

            // DISPLAY ANY WARNING MESSAGES
            if (!isValid)
            {
                WarningMessageList.DataSource = warnMessages;
                WarningMessageList.DataBind();
            }

            // INITIALIZE PASSWORD ON FIRST VISIT
            if (!Page.IsPostBack)
            {
                WishlistPasswordValue.Text = wishlist.ViewPassword;
            }

            //TOGGLE PRICE COLUMNS
            _ItemPrice         = WishlistGrid.Columns[2];
            _ItemPrice.Visible = !AnyWishlistItemsZero();
        }