public Order UpdateBillingDetails(BillingDetails billingDetails)
        {
            var order          = FindOrder(billingDetails.OrderId, billingDetails.UserId);
            var billingAddress = order.BillingAddress ?? new Address();

            billingAddress.InjectFrom(billingDetails);
            order.BillingAddress      = billingAddress;
            order.SpecialInstructions = billingDetails.SpecialInstructions;

            if (billingDetails.GiftAmount != 0)
            {
                order.AdjustmentTotal = billingDetails.GiftAmount;
                order.Total           = order.Total - billingDetails.GiftAmount;
            }

            _orderRepository.Update(order);

            var user = order.User;

            if (string.IsNullOrEmpty(user.FirstName))
            {
                user.FirstName = billingDetails.FirstName;
            }
            if (string.IsNullOrEmpty(user.LastName))
            {
                user.LastName = billingDetails.LastName;
            }
            _userService.UpdateUser(user);

            return(order);
        }
 public void AddGiftCardSummaries(BillingDetails billingdetails)
 {
     var giftcardSummary = new GiftCardSummary
     {
         UsedAmount = billingdetails.GiftAmount,
         OrderId = billingdetails.OrderId,
         GiftOrderDetailId=billingdetails.GiftOrderDetailId
     };
     _giftcardsummaryRepository.Add(giftcardSummary);
 }
        public void AddGiftCardSummaries(BillingDetails billingdetails)
        {
            var giftcardSummary = new GiftCardSummary
            {
                UsedAmount        = billingdetails.GiftAmount,
                OrderId           = billingdetails.OrderId,
                GiftOrderDetailId = billingdetails.GiftOrderDetailId
            };

            _giftcardsummaryRepository.Add(giftcardSummary);
        }
        public ActionResult TestCheckout(BillingDetails billingDetails, decimal? x_amount)
        {
            if (!billingDetails.AcceptedTermsAndConditions)
            ModelState.AddModelError("AcceptedTermsAndConditions", "you must accept the terms and conditions to purchase a tour");

              if (ModelState.IsValid)
              {
            return Json(new { BillingDetails = billingDetails, Errors = new object[0] });
              }

              billingDetails.BillingOverview = new BillingOverview { States = _orderService.States() };
              billingDetails.PaymentRequest = new PaymentRequest((x_amount.HasValue ? x_amount.Value : 5.0M), AuthorizeNetConfig.ApiLogin, AuthorizeNetConfig.TransactionKey, AuthorizeNetConfig.TestMode);
              return Json(new { BillingDetails = billingDetails, Errors = ModelStateErrorsForJson() });
        }
        public ActionResult TestCheckout()
        {
            var billingDetails = new BillingDetails
            {
              UserId = UserContext.UserId,
              CountryId = 226,
              BillingOverview = new BillingOverview
            {
              States = _orderService.States()
            },
              PaymentRequest =
            new PaymentRequest(5.0M, AuthorizeNetConfig.ApiLogin, AuthorizeNetConfig.TransactionKey,
                               AuthorizeNetConfig.TestMode)
            };

              SetBillingAddressFromLastOrder(billingDetails, _userService.Find(UserContext.UserId));
              return View(billingDetails);
        }
        public BillingDetails BuildBillingDetails(Order order, User user = null)
        {
            var billingOverview = BuildBillingOverview(order);

            var billingDetails = new BillingDetails
            {
                OrderId         = order.Id,
                OrderNumber     = order.OrderNumber,
                DiscountCodes   = DiscountCodesForOrder(order).Select(d => d.LowerCode).ToArray(),
                UserId          = order.UserId,
                CountryId       = 226, // TODO: hardcoded country for now
                BillingOverview = billingOverview
            };

            if (user != null)
            {
                billingDetails.FirstName = user.FirstName;
                billingDetails.LastName  = user.LastName;
                billingDetails.Email     = user.Email;

                var lastOrder = LastOrderForUser(user);
                if (lastOrder != null)
                {
                    var billingAddress = lastOrder.BillingAddress;
                    if (billingAddress != null)
                    {
                        billingDetails.Address1        = billingAddress.Address1;
                        billingDetails.Address2        = billingAddress.Address2;
                        billingDetails.City            = billingAddress.City;
                        billingDetails.StateOrProvince = billingAddress.StateOrProvince;
                        billingDetails.ZipCode         = billingAddress.ZipCode;
                    }
                }
            }

            return(billingDetails);
        }
        private void SetBillingAddressFromLastOrder(BillingDetails billingDetails, User user)
        {
            billingDetails.FirstName = user.FirstName;
              billingDetails.LastName = user.LastName;
              billingDetails.Email = user.Email;

              var lastOrder = _orderService.LastOrderForUser(user);
              if (lastOrder != null)
              {
            var billingAddress = lastOrder.BillingAddress;
            if (billingAddress != null)
            {
              billingDetails.Address1 = billingAddress.Address1;
              billingDetails.Address2 = billingAddress.Address2;
              billingDetails.City = billingAddress.City;
              billingDetails.StateOrProvince = billingAddress.StateOrProvince;
              billingDetails.ZipCode = billingAddress.ZipCode;
            }
              }
        }
示例#8
0
        //[ProductionRequireHttps]
        public ActionResult Billing(Britespokes.Services.Orders.BillingDetails billingDetails)
        {
            //decimal GiftAmount = 0;
            //int OrderDetailId = 0;

            var order = _orderService.FindOrder(billingDetails.OrderId, UserContext.UserId);

            if (!billingDetails.AcceptedTermsAndConditions)
            {
                ModelState.AddModelError("AcceptedTermsAndConditions", "you must accept the terms and conditions to purchase a tour");
            }
            if (order.OrderStatus != _orderService.StatusPending())
            {
                ModelState.AddModelError("", "This order is no longer pending");
            }
            if (UserContext.IsGuest && string.IsNullOrEmpty(billingDetails.Password))
            {
                ModelState.AddModelError("Password", "required");
            }

            if (string.CompareOrdinal(billingDetails.Password, billingDetails.ConfirmPassword) != 0)
            {
                ModelState.AddModelError("ConfirmPassword", "doesn't match");
            }

            //Gift Code Validation and also it returns the amount of gift
            if (!string.IsNullOrWhiteSpace(billingDetails.GiftCode) && !_orderService.ValidateGiftCode(billingDetails.GiftCode, billingDetails.Email, ref billingDetails.GiftAmount, ref billingDetails.GiftOrderDetailId))
            {
                ModelState.AddModelError("GiftCode", "gift code either used or doesn't exists");
            }

            if (ModelState.IsValid)
            {
                if (UserContext.IsGuest)
                {
                    var user = _userService.Find(UserContext.UserId);
                    _registrationService.PromoteGuest(user, billingDetails.Email, billingDetails.Password);
                    _userMailer.SendWelcomeEmail(UserContext.Organization, user);
                }

                //Saving detail of gift card used
                if (billingDetails.GiftOrderDetailId != 0)
                {
                    _orderService.AddGiftCardSummaries(billingDetails);
                }
                _orderService.UpdateBillingDetails(billingDetails);

                //For gift code
                billingDetails.PaymentRequest = new PaymentRequest(order.Total, AuthorizeNetConfig.ApiLogin, AuthorizeNetConfig.TransactionKey, AuthorizeNetConfig.TestMode);

                //To be remove only for testing
                // _orderConfirmationMailer.SendOrderConfirmationEmail(order);


                return(Json(new { BillingDetails = billingDetails, Errors = new object[0] }));
            }

            billingDetails.BillingOverview = _orderService.BuildBillingOverview(order);
            billingDetails.PaymentRequest  = new PaymentRequest(order.Total, AuthorizeNetConfig.ApiLogin, AuthorizeNetConfig.TransactionKey, AuthorizeNetConfig.TestMode);
            return(Json(new { BillingDetails = billingDetails, Errors = ModelStateErrorsForJson() }));
        }
        public BillingDetails BuildBillingDetails(Order order, User user = null)
        {
            var billingOverview = BuildBillingOverview(order);

            var billingDetails = new BillingDetails
              {
                  OrderId = order.Id,
                  OrderNumber = order.OrderNumber,
                  DiscountCodes = DiscountCodesForOrder(order).Select(d => d.LowerCode).ToArray(),
                  UserId = order.UserId,
                  CountryId = 226, // TODO: hardcoded country for now
                  BillingOverview = billingOverview
              };

            if (user != null)
            {
                billingDetails.FirstName = user.FirstName;
                billingDetails.LastName = user.LastName;
                billingDetails.Email = user.Email;

                var lastOrder = LastOrderForUser(user);
                if (lastOrder != null)
                {
                    var billingAddress = lastOrder.BillingAddress;
                    if (billingAddress != null)
                    {
                        billingDetails.Address1 = billingAddress.Address1;
                        billingDetails.Address2 = billingAddress.Address2;
                        billingDetails.City = billingAddress.City;
                        billingDetails.StateOrProvince = billingAddress.StateOrProvince;
                        billingDetails.ZipCode = billingAddress.ZipCode;
                    }
                }
            }

            return billingDetails;
        }
        public Order UpdateBillingDetails(BillingDetails billingDetails)
        {
            var order = FindOrder(billingDetails.OrderId, billingDetails.UserId);
            var billingAddress = order.BillingAddress ?? new Address();
            billingAddress.InjectFrom(billingDetails);
            order.BillingAddress = billingAddress;
            order.SpecialInstructions = billingDetails.SpecialInstructions;

            if (billingDetails.GiftAmount != 0)
            {
                order.AdjustmentTotal = billingDetails.GiftAmount;
                order.Total = order.Total - billingDetails.GiftAmount;
            }

            _orderRepository.Update(order);

            var user = order.User;
            if (string.IsNullOrEmpty(user.FirstName))
                user.FirstName = billingDetails.FirstName;
            if (string.IsNullOrEmpty(user.LastName))
                user.LastName = billingDetails.LastName;
            _userService.UpdateUser(user);

            return order;
        }