private async Task <Sale> CreateNewSaleAsync(CheckoutInputModel inputModel, string userId) { var newSale = new Sale { FirstName = inputModel.FirstName, LastName = inputModel.LastName, AdditionalInformation = inputModel.AdditionalInformation, Address = inputModel.Address, City = inputModel.City, CompanyName = inputModel.CompanyName, EmailAddress = inputModel.Email, PaymentMethodId = inputModel.PaymentMethodId, PhoneNumber = inputModel.PhoneNumber, Postcode = inputModel.Postcode, PurchasedOn = DateTime.UtcNow, UserId = userId, Country = this.countryService.GetCountryByCode(inputModel.CountryCode) }; await this.context.AddAsync(newSale); await this.context.SaveChangesAsync(); return(newSale); }
//Adds shippin info in the additional check out phase. public void AddOrderFinalized(CheckoutInputModel model, string userID) { var userOrder = (from o in _db.Orders where o.UserID == userID && o.IsCurrentOrder == true select o).FirstOrDefault(); var shippingAddress = new AddressModel() { StreetName = model.StreetName, HouseNumber = (int)model.HouseNumber, City = model.City, Zip = model.Zip, Country = model.Country, }; var paymentInfo = new PaymentInfoModel() { CardType = model.CardType, CardHolder = model.CardHolder, CardNumber = model.CardNumber, Month = model.Month, Year = model.Year, CVC = model.CVC, }; userOrder.ShippingAddress = shippingAddress; userOrder.PaymentInfo = paymentInfo; userOrder.IsWrapped = model.IsWrapped; _db.Orders.Update(userOrder); _db.SaveChanges(); }
private async Task <Sale> CreateNewSaleAsync(CheckoutInputModel inputModel, string userId) { var newSale = new Sale { FirstName = inputModel.FirstName, LastName = inputModel.LastName, AdditionalInformation = inputModel.AdditionalInformation, Address = inputModel.Address, City = inputModel.City, CompanyName = inputModel.CompanyName, EmailAddress = inputModel.Email, PaymentMethodId = inputModel.PaymentMethodId, PhoneNumber = inputModel.PhoneNumber, Postcode = inputModel.Postcode, PurchasedOn = DateTime.UtcNow, UserId = userId, Country = this.countryService.GetCountryByCode(inputModel.CountryCode), SaleStatus = this.GetSaleStatus(GlobalConstants.PendingSaleStatus), Municipality = inputModel.Municipality }; if (this.paymentMethodService.GetPaymentMethod(inputModel.PaymentMethodId) == GlobalConstants.PaymentMethodDebitOrCreditCard && inputModel.PaymentIntentId != null) { newSale.PaymentIntentId = inputModel.PaymentIntentId; } await this.context.AddAsync(newSale); await this.context.SaveChangesAsync(); return(newSale); }
public async Task <IActionResult> Checkout(CheckoutInputModel inputModel) { var name = inputModel.FirstName + " " + inputModel.LastName; var address = inputModel.Neighbourhood + ", " + inputModel.Street + ", " + inputModel.Zip + ", " + inputModel.Appartment; var user = await this.userManager.GetUserAsync(this.User); var userId = user.Id; var cartId = user.CartId; var price = this.cartsService.GetCart(cartId).TotalCost; var orderId = await this.ordersService.CreateOrderAsync(name, address, price, inputModel.Phone, userId); var cartItems = this.cartItemsService.GetAllCartItems(cartId); foreach (var cartItem in cartItems) { await this.orderItemsService.CreateOrderItemAsync(orderId, cartItem.ItemId, cartItem.Amount); await this.itemsService.DecreaseAvailabilityAsync(cartItem.ItemId, cartItem.Amount); } await this.cartItemsService.EmptyCartAsync(cartId); await this.cartsService.RemoveDiscountAsync(cartId); return(this.RedirectToAction("ThankYou")); }
private string SetTempDataForSale(CheckoutInputModel saleInfo, List <CheckoutProductViewModel> products) { this.TempData[GlobalConstants.SaleInfo] = JsonSerializer.Serialize(saleInfo); var confirmSaleToken = Guid.NewGuid().ToString(); this.TempData[GlobalConstants.ConfirmSaleToken] = confirmSaleToken; return(confirmSaleToken); }
public async Task CheckoutAsync(CheckoutInputModel inputModel, string userId, List <CheckoutProductViewModel> purchasedProducts) { var newSale = await this.CreateNewSaleAsync(inputModel, userId); await this.AddProductsToSaleAsync(newSale, purchasedProducts); await this.cartService.ClearCartAsync(userId); await this.context.SaveChangesAsync(); }
public void ProcessCart(CheckoutInputModel cart) { if (string.IsNullOrEmpty(cart.Email)) { throw new Exception("Email is missing"); } if (string.IsNullOrEmpty(cart.FullName)) { throw new Exception("Full name is missing"); } if (string.IsNullOrEmpty(cart.ShippingAddress)) { throw new Exception("Address is missing"); } if (string.IsNullOrEmpty(cart.City)) { throw new Exception("City is missing"); } if (string.IsNullOrEmpty(cart.PostCode)) { throw new Exception("Postcode is missing"); } if (string.IsNullOrEmpty(cart.Country)) { throw new Exception("Country is missing"); } if (string.IsNullOrEmpty(cart.CardNumber)) { throw new Exception("Card number is missing"); } if (string.IsNullOrEmpty(cart.ExpMonth)) { throw new Exception("Expire month is missing"); } if (string.IsNullOrEmpty(cart.ExpYear)) { throw new Exception("Expire year is missing"); } if (string.IsNullOrEmpty(cart.SecurityCode)) { throw new Exception("Security code is missing"); } }
public async Task CheckoutAsync(CheckoutInputModel inputModel, string userId, List <CheckoutProductViewModel> purchasedProducts) { //Do this first to avoid concurrency failures and clashes await this.SubtractQuantityInStockWithPurchaseQuantity(purchasedProducts); var newSale = await this.CreateNewSaleAsync(inputModel, userId); await this.AddProductsToSaleAsync(newSale, purchasedProducts); await this.cartService.ClearCartAsync(userId); await this.context.SaveChangesAsync(); }
//The review view where user can confirm their order. public IActionResult Review(CheckoutInputModel model) { //Finalizes order. _orderService.AddOrderFinalized(model, model.UserID); //Gets current order. var order = _orderService.GetCurrentOrder(model.UserID); //Gets the books for the current order. var listOrderBooks = _obcService.GetBooks(order.OrderID); //Adds the books to the model. order.Books = listOrderBooks; //And returns the model so user can go over the books in the review phase. return(View(order)); }
public ActionResult Checkout(CheckoutInputModel checkout) { // Pre-payment steps var cart = RetrieveCurrentShoppingCart(); var response = _service.ProcessOrderBeforePayment(cart, checkout); if (!response.Denied) { return(Redirect(Url.Content("~/fake_payment.aspx?"))); } TempData["ibuy-stuff:denied"] = response; return(RedirectToAction("Denied")); }
public async Task <IActionResult> Checkout() { var userId = this.userManager.GetUserId(this.User); var orderId = await this.ordersService.GetOrderIdByUserAsync(userId); var model = new CheckoutInputModel() { User = await this.usersService.GetUserDataAsync <UserCheckoutViewModel>(userId), Desserts = await this.dessertOrdersService.GetDessertsInBasketAsync <DessertBaseViewModel>(userId), TotalPrice = await this.ordersService.GetTotalPriceCurrentOrderByUserAsync(userId), Quantities = await this.dessertOrdersService.GetTotalQuantitiesCurrentOrderAsync(orderId), }; return(this.View(model)); }
public ActionResult Checkout(CheckoutInputModel checkout) { // Pre-payment steps var cart = RetrieveCurrentShoppingCart(); var command = new ProcessOrderBeforePaymentCommand(cart, checkout); var response = CommandProcessor.Send <ProcessOrderBeforePaymentCommand, OrderProcessingViewModel>(command); if (!response.Denied) { return(Redirect(Url.Content("~/fake_payment.aspx?"))); } TempData["ibuy-stuff:denied"] = response; return(RedirectToAction("Denied")); }
private Checkout Mapearcheckout(CheckoutInputModel checkoutInput) { var checkout = new Checkout { Idcheckout = checkoutInput.Idcheckout, Idhabitacion = checkoutInput.Idhabitacion, Idcliente = checkoutInput.Idcliente, Numeroinvitados = checkoutInput.Numeroinvitados, Fechaentrada = checkoutInput.Fechaentrada, Fechasalida = checkoutInput.Fechasalida, DiasHospedaje = checkoutInput.DiasHospedaje, TotalHospedaje = checkoutInput.TotalHospedaje }; return(checkout); }
public ActionResult <CheckoutViewModel> post(CheckoutInputModel checkoutInput) { Checkout checkout = Mapearcheckout(checkoutInput); var response = _checkoutservice.Guardar(checkout); if (response.Error) { ModelState.AddModelError("Guardar Check-Out", response.Mensaje); var problemDetails = new ValidationProblemDetails(ModelState) { Status = StatusCodes.Status400BadRequest, }; return(BadRequest(problemDetails)); } return(Ok(response.Checkout)); }
public IActionResult BuyingCart(CheckoutInputModel info) { if (!ModelState.IsValid) { ViewData["ErrorMessage"] = "Error"; return(RedirectToAction("CheckoutInformation", "Cart", new { error = true })); } _cartServiceError.ProcessCart(info); //Error handling var buyingcartinfo = new BuyCartViewModel { TheCart = _cartService.GetCart(info.UserId), Info = info }; return(View(buyingcartinfo)); }
public async Task <IActionResult> OrderCheckOutToVerify(CheckoutInputModel model) { //Checks if input boxes were filled in. if (!ModelState.IsValid) { //Redirects back return(RedirectToAction("CheckOut", "Order")); } //Gets Current user. var user = await _userManager.GetUserAsync(User); var userID = user.Id; //Updates the Order Input model to have the user ID model.UserID = userID; //Returns to user that they can Review Order. return(RedirectToAction("Review", "Order", model)); }
public async Task <IActionResult> CheckoutInformation(bool error) { if (error == true) { ViewData["ErrorMessage"] = "Error"; } var user = await _userManager.GetUserAsync(User); var userId = user.Id; var info = new CheckoutInputModel { UserId = user.Id, Email = user.Email, FullName = user.FullName, ShippingAddress = user.ShippingAddress, City = user.City, State = user.State, PostCode = user.Postcode, Country = user.Country, }; return(View(info)); }
public async Task <IActionResult> Buy(CheckoutInputModel input) { var userId = this.userManager.GetUserId(this.User); var orderId = await this.ordersService.GetOrderIdByUserAsync(userId); var totalPrice = await this.ordersService.GetTotalPriceCurrentOrderByUserAsync(userId); if (!this.ModelState.IsValid) { input.User = await this.usersService.GetUserDataAsync <UserCheckoutViewModel>(userId); input.Desserts = await this.dessertOrdersService.GetDessertsInBasketAsync <DessertBaseViewModel>(userId); input.TotalPrice = totalPrice; input.Quantities = await this.dessertOrdersService.GetTotalQuantitiesCurrentOrderAsync(orderId); return(this.View(input)); } await this.ordersService.AddDetailsToCurrentOrderAsync(orderId, input.DeliveryAddress, input.Notes); return(this.Redirect($"/Paypal/CreatePayment?totalPrice={totalPrice}")); }
public void AddOrderFinalized(CheckoutInputModel model, string userID) { _orderRepo.AddOrderFinalized(model, userID); }
public OrderProcessingViewModel ProcessOrderBeforePayment(ShoppingCartViewModel cart, CheckoutInputModel checkout) { var response = new OrderProcessingViewModel(); // 1. Save checkout data as part of the customer record (shipping & payment). // This is a bit simplistic as shipping address and payment details should be both on Customer // (to set default options) and Order (to be part of the history). var address = Address.Create(checkout.Address, "", checkout.City, "", checkout.Country); var payment = CreditCard.Create(checkout.CardType, checkout.CardNumber, "", new ExpiryDate(checkout.Month, checkout.Year)); _requestService.SaveCheckoutInformation(cart.OrderRequest, address, payment); // 2. Goods in store (precheck to give users a chance not to place an order that may take a while to // be completed and served. Most sites just make you pay and place an order for missing items while // giving you a chance to cancel the order at any time. var stock = _requestService.CheckStockLevelForOrderedItems(cart.OrderRequest); if (stock.Insufficient.Any()) { response.Denied = true; response.AddMessage("It seems that we don't have available all the items you ordered. What would you like to do? Buying a bit less or trying later?"); return(response); } // 3. Payment history for the customer // Probably not really an appropriate scenario for this simple store: if the online store accept // payment cash-on-delivery, however, you might want to enable it only for customers with a // positive payment history. if (!_requestService.CheckCustomerPaymentHistory(cart.OrderRequest.Buyer.CustomerId)) { response.Denied = true; response.AddMessage("We've found something incorrect in your record that prevents our system from processing your order. Please, contact our customer care."); return(response); } // 4. Refill stock var productsToOrder = new List <Product>(); productsToOrder.AddRange(stock.Low); productsToOrder.AddRange(stock.Insufficient); _requestService.RefillStoreForProduct(productsToOrder); return(response); }
public ProcessOrderBeforePaymentCommand(ShoppingCartViewModel cart, CheckoutInputModel checkout) { ShoppingCart = cart; CheckoutData = checkout; }