// GET: /Checkout/PlaceOrder public ActionResult Complete(Guid id) { var response = _orderService.GetOrder(new GetOrderRequest { Id = id }); var model = new CompleteCheckoutViewModel { OrderNumber = response.Order.OrderNumber }; return(View(model)); }
protected virtual async Task <CompleteCheckoutViewModel> MapOrderToCompleteCheckoutViewModel(Overture.ServiceModel.Orders.Order order, CompleteCheckoutParam param) { if (order == null) { return(null); } var orderStatuses = await LookupService.GetLookupDisplayNamesAsync(new GetLookupDisplayNamesParam { CultureInfo = param.CultureInfo, LookupType = LookupType.Order, LookupName = "OrderStatus", }).ConfigureAwait(false); var productImageInfo = new ProductImageInfo { ImageUrls = await ImageService.GetImageUrlsAsync(order.Cart.GetLineItems()).ConfigureAwait(false) }; var getVmOrderParam = new CreateOrderDetailViewModelParam { Order = order, CultureInfo = param.CultureInfo, OrderStatuses = orderStatuses, OrderDetailBaseUrl = OrderUrlProvider.GetOrderDetailsBaseUrl(param.CultureInfo), BaseUrl = param.BaseUrl, ProductImageInfo = productImageInfo, }; var orderViewModel = OrderDetailsViewModelFactory.CreateLightViewModel(getVmOrderParam); var completeCheckoutViewModel = new CompleteCheckoutViewModel { OrderNumber = order.OrderNumber, Order = orderViewModel, CustomerEmail = order.Cart.Customer.Email, CustomerFirstName = order.Cart.Customer.FirstName, CustomerLastName = order.Cart.Customer.LastName, Affiliation = order.Cart.OrderLocation?.Name, Revenu = order.Cart.Total, Tax = order.Cart.TaxTotal, Shipping = order.Cart.FulfillmentCost, ShippingOptions = order.Cart.Shipments?.FirstOrDefault()?.FulfillmentMethod.FulfillmentMethodType.ToString().ToLowerInvariant(), BillingCurrency = order.Cart.BillingCurrency, Coupons = MapCoupons(order, param.CultureInfo), LineItems = orderViewModel?.Shipments.FirstOrDefault()?.LineItems }; return(completeCheckoutViewModel); }
protected virtual CompleteCheckoutViewModel MapOrderToCompleteCheckoutViewModel(Overture.ServiceModel.Orders.Order order, CultureInfo cultureInfo) { if (order == null) { return(null); } var completeCheckoutViewModel = new CompleteCheckoutViewModel { OrderNumber = order.OrderNumber, CustomerEmail = order.Cart.Customer.Email, Affiliation = order.Cart.OrderLocation?.Name, Revenu = order.Cart.Total, Tax = order.Cart.TaxTotal, Shipping = order.Cart.FulfillmentCost, ShippingOptions = order.Cart.Shipments?.FirstOrDefault()?.FulfillmentMethod.FulfillmentMethodType.ToString().ToLowerInvariant(), BillingCurrency = order.Cart.BillingCurrency, Coupons = MapCoupons(order, cultureInfo), LineItems = MapCompleteCheckoutLineItems(order, cultureInfo) }; return(completeCheckoutViewModel); }
public ViewResult Thanks(Cart cart, CompleteCheckoutViewModel completeCheckoutViewModel, string stripeChargeID) { if (cart != null && completeCheckoutViewModel != null) { decimal subTotalTaxFree = 0.0M; decimal subTotalTaxable = 0.0M; var productAmounts = new Dictionary <DataTransferObjects.Product, int>(); var productsSold = new List <ProductVM>(); foreach (var line in cart.Lines) { productAmounts.Add(line.Product, line.Amount); productsSold.Add(new ProductVM { Name = line.Product.Name, ItemName = line.Product.Name, Active = line.Product.Active, Brand = line.Product.Brand, Category = line.Product.Category, Description = line.Product.Description, ItemDescription = line.Product.Description, ItemID = line.Product.ItemID, Quantity = line.Amount, ItemQuantity = line.Amount, Price = line.Product.Price, ProductID = line.Product.ProductID, Taxable = line.Product.Taxable, Type = line.Product.Type }); if (!line.Product.Taxable) { subTotalTaxFree += line.Product.Price * line.Amount; } else { subTotalTaxable += line.Product.Price * line.Amount; } } decimal subTotalWithTax = subTotalTaxable * (1 + completeCheckoutViewModel.OrderDetails.TaxRate); subTotalTaxable += subTotalTaxFree; var transaction = new Transaction { CustomerEmail = completeCheckoutViewModel.OrderDetails.Email, StripeChargeID = stripeChargeID, EmployeeID = 100000, // Admin account user id SubTotal = subTotalTaxFree, SubTotalTaxable = subTotalTaxable, TaxRate = completeCheckoutViewModel.OrderDetails.TaxRate, TransactionDateTime = DateTime.Now, TransactionStatusID = "Completed", TransactionTypeID = "Online Sale", Total = subTotalWithTax + subTotalTaxFree, ProductAmounts = productAmounts }; _transactionManager.AddTransaction(transaction); var lineProducts = new TransactionLineProducts { ProductsSold = productsSold }; _transactionManager.AddTransactionLineProducts(lineProducts); } cart.Clear(); _transactionManager = new TransactionManager(); return(View()); }
public ActionResult CompleteCheckout(Cart cart, OrderDetails orderDetails) { StripeConfiguration.ApiKey = StripeKey.SecretKey; var customer = new Stripe.Customer { Name = orderDetails.CustomerName, Email = orderDetails.Email, Address = new Address { Line1 = orderDetails.BillingAddressLine1, Line2 = orderDetails.BillingAddressLine2, City = orderDetails.BillingCity, State = orderDetails.BillingState, PostalCode = orderDetails.BillingPostalCode, Country = orderDetails.BillingCountry }, Phone = orderDetails.CustomerPhone }; if (orderDetails.ShippingAddressLine1 == null) { orderDetails.ShippingAddressLine1 = orderDetails.BillingAddressLine1; } if (orderDetails.ShippingAddressLine2 == null) { orderDetails.ShippingAddressLine2 = orderDetails.BillingAddressLine2; } if (orderDetails.ShippingCity == null) { orderDetails.ShippingCity = orderDetails.BillingCity; } if (orderDetails.ShippingState == null) { orderDetails.ShippingState = orderDetails.BillingState; } if (orderDetails.ShippingPostalCode == null) { orderDetails.ShippingPostalCode = orderDetails.BillingPostalCode; } if (orderDetails.ShippingCountry == null) { orderDetails.ShippingCountry = orderDetails.BillingCountry; } if (orderDetails.ShippingName == null) { orderDetails.ShippingName = orderDetails.CustomerName; } if (orderDetails.ShippingPhone == null) { orderDetails.ShippingPhone = orderDetails.CustomerPhone; } customer.Shipping = new Shipping { Address = new Address { Line1 = orderDetails.BillingAddressLine1, Line2 = orderDetails.BillingAddressLine2, City = orderDetails.BillingCity, State = orderDetails.BillingState, PostalCode = orderDetails.BillingPostalCode, Country = orderDetails.BillingCountry }, Name = orderDetails.ShippingName, Phone = orderDetails.ShippingPhone }; decimal taxRate = 0.0M; try { taxRate = _transactionManager.RetrieveTaxRateBySalesTaxDateAndZipCode( orderDetails.ShippingPostalCode.Substring(0, 5), _transactionManager.RetrieveLatestSalesTaxDateByZipCode( orderDetails.ShippingPostalCode.Substring(0, 5))); } catch (Exception) { taxRate = 0.0M; } orderDetails.TaxRate = taxRate; decimal subTotal = 0.0M; decimal total = 0.0M; foreach (var line in cart.Lines) { if (line.Product.Taxable) { subTotal += line.Product.Price * line.Amount; } else { total += line.Product.Price * line.Amount; } } decimal tax = subTotal * taxRate; total += subTotal + tax; var options = new PaymentIntentCreateOptions { Customer = customer.Id, Amount = (int)(total * 100), // stripe totals are in pennies Currency = "usd", PaymentMethodTypes = new List <string> { "card" } }; var service = new PaymentIntentService(); PaymentIntent intent = null; try { intent = service.Create(options); } catch (Exception) { return(RedirectToAction("Checkout")); } var ccvm = new CompleteCheckoutViewModel { Cart = cart, OrderDetails = orderDetails, Subtotal = subTotal, TaxAmount = tax, Total = total }; ViewData["ClientSecret"] = intent.ClientSecret; return(View(ccvm)); }