public CheckoutViewModel(ShoppingCartCheckoutPropertyBag propertyBag) { ShippingAddress = propertyBag.ShippingAddress; CreditCardPayment = propertyBag.PaymentMethod as CreditCard; ShipMethodID = propertyBag.ShipMethodID; BillingAddressSameAsShipping = propertyBag.BillingAddressSameAsShipping; }
/// <summary> /// Creates a view model for shopping carts with the base class' properties populated. /// This is used to avoid having to populate the party and other common data for each shopping view model. /// </summary> /// <typeparam name="T">The type of view model needed.</typeparam> /// <param name="propertyBag">The cart's property bag.</param> /// <returns>Your pre-populated view model, ready for further population.</returns> public static T Create <T>(ShoppingCartCheckoutPropertyBag propertyBag) where T : IShoppingViewModel { var viewModel = Activator.CreateInstance <T>(); viewModel.PropertyBag = propertyBag; return(viewModel); }
public ShoppingCartLogicProvider(Controller controller, ShoppingCartItemsPropertyBag cart, ShoppingCartCheckoutPropertyBag propertyBag) { Controller = controller; Cart = cart; PropertyBag = propertyBag; }
public ActionResult SubmitCheckout() { if (!PropertyBag.IsSubmitting) { PropertyBag.IsSubmitting = true; _propertyBag = Exigo.PropertyBags.Update(PropertyBag); try { // Start creating the API requests var details = new List <ApiRequest>(); var orderRequest = new CreateOrderRequest(OrderConfiguration, PropertyBag.ShipMethodID, ShoppingCart.Items, PropertyBag.ShippingAddress) { CustomerID = Identity.Current.CustomerID }; details.Add(orderRequest); // Create the payment request if (PropertyBag.PaymentMethod is CreditCard) { var card = PropertyBag.PaymentMethod as CreditCard; if (card.Type == CreditCardType.New) { if (!card.IsTestCreditCard && !Request.IsLocal) { details.Add(new ChargeCreditCardTokenRequest(card)); } else { // Test Credit Card, so no need to charge card ((CreateOrderRequest)details.Where(c => c is CreateOrderRequest).FirstOrDefault()).OrderStatus = GlobalUtilities.GetDefaultOrderStatusType(); } } else { details.Add(new ChargeCreditCardTokenOnFileRequest(card)); } } if (PropertyBag.PaymentMethod is BankAccount) { var account = PropertyBag.PaymentMethod as BankAccount; if (account.Type == ExigoService.BankAccountType.New) { details.Add(new DebitBankAccountRequest(account)); } else { details.Add(new DebitBankAccountOnFileRequest(account)); } } // Process the transaction var transactionRequest = new TransactionalRequest(); transactionRequest.TransactionRequests = details.ToArray(); var transactionResponse = Exigo.WebService().ProcessTransaction(transactionRequest); var newOrderID = 0; if (transactionResponse.Result.Status == ResultStatus.Success) { foreach (var response in transactionResponse.TransactionResponses) { if (response is CreateOrderResponse) { var orderResponse = (CreateOrderResponse)response; newOrderID = orderResponse.OrderID; // Create a cookie to store our newest Order ID to ensure it shows on the Order History page var orderIDCookie = new System.Web.HttpCookie("NewOrder_{0}".FormatWith(Identity.Current.CustomerID), newOrderID.ToString()); orderIDCookie.Expires = DateTime.UtcNow.AddMinutes(5); Response.Cookies.Add(orderIDCookie); } } } PropertyBag.NewOrderID = newOrderID; _propertyBag = Exigo.PropertyBags.Update(PropertyBag); return(new JsonNetResult(new { success = true })); } catch (Exception exception) { PropertyBag.OrderException = exception.Message; PropertyBag.IsSubmitting = false; _propertyBag = Exigo.PropertyBags.Update(PropertyBag); return(new JsonNetResult(new { success = false, message = exception.Message })); } } else { if (PropertyBag.NewOrderID > 0) { return(new JsonNetResult(new { success = true })); } else { return(new JsonNetResult(new { success = false, message = Resources.Common.YourOrderIsSubmitting })); } } }
public ActionResult SubmitCheckout() { if (!PropertyBag.IsSubmitting) { PropertyBag.IsSubmitting = true; _propertyBag = Exigo.PropertyBags.Update(PropertyBag); try { // Start creating the API requests var details = new List <ApiRequest>(); // Create the order request, if applicable var orderItems = ShoppingCart.Items.Where(c => c.Type == ShoppingCartItemType.Order); var hasOrder = orderItems.Count() > 0; if (hasOrder) { var orderRequest = new CreateOrderRequest(OrderConfiguration, PropertyBag.ShipMethodID, orderItems, PropertyBag.ShippingAddress) { CustomerID = Identity.Current.CustomerID }; details.Add(orderRequest); } // Create the autoorder request, if applicable var autoOrderItems = ShoppingCart.Items.Where(c => c.Type == ShoppingCartItemType.AutoOrder); var hasAutoOrder = autoOrderItems.Count() > 0; if (hasAutoOrder) { var autoOrderRequest = new CreateAutoOrderRequest(AutoOrderConfiguration, Exigo.GetAutoOrderPaymentType(PropertyBag.PaymentMethod), PropertyBag.AutoOrderStartDate, PropertyBag.ShipMethodID, autoOrderItems, PropertyBag.ShippingAddress) { CustomerID = Identity.Current.CustomerID, Frequency = PropertyBag.AutoOrderFrequencyType }; details.Add(autoOrderRequest); } // Create the payment request if (PropertyBag.PaymentMethod is CreditCard) { var card = PropertyBag.PaymentMethod as CreditCard; if (card.Type == CreditCardType.New) { if (hasAutoOrder) { card = Exigo.SaveNewCustomerCreditCard(Identity.Current.CustomerID, card); ((CreateAutoOrderRequest)details.Where(c => c is CreateAutoOrderRequest).FirstOrDefault()).PaymentType = Exigo.GetAutoOrderPaymentType(card); } if (hasOrder) { if (!card.IsTestCreditCard && !Request.IsLocal) { details.Add(new ChargeCreditCardTokenRequest(card)); } else { // Test Credit Card, so no need to charge card ((CreateOrderRequest)details.Where(c => c is CreateOrderRequest).FirstOrDefault()).OrderStatus = GlobalUtilities.GetDefaultOrderStatusType(); } } } else { if (hasOrder && !Request.IsLocal) { details.Add(new ChargeCreditCardTokenOnFileRequest(card)); } } } if (PropertyBag.PaymentMethod is BankAccount) { var account = PropertyBag.PaymentMethod as BankAccount; if (account.Type == ExigoService.BankAccountType.New) { if (hasAutoOrder) { account = Exigo.SaveNewCustomerBankAccount(Identity.Current.CustomerID, account); ((CreateAutoOrderRequest)details.Where(c => c is CreateAutoOrderRequest).FirstOrDefault()).PaymentType = Exigo.GetAutoOrderPaymentType(account); } if (hasOrder) { details.Add(new DebitBankAccountRequest(account)); } } else { if (hasOrder) { details.Add(new DebitBankAccountOnFileRequest(account)); } } } // Process the transaction var transactionRequest = new TransactionalRequest(); transactionRequest.TransactionRequests = details.ToArray(); var transactionResponse = Exigo.WebService().ProcessTransaction(transactionRequest); var newOrderID = 0; var newAutoOrderID = 0; if (transactionResponse.Result.Status == ResultStatus.Success) { foreach (var response in transactionResponse.TransactionResponses) { if (response is CreateOrderResponse) { newOrderID = ((CreateOrderResponse)response).OrderID; } if (response is CreateAutoOrderResponse) { newAutoOrderID = ((CreateAutoOrderResponse)response).AutoOrderID; } } } PropertyBag.NewOrderID = newOrderID; PropertyBag.NewAutoOrderID = newAutoOrderID; _propertyBag = Exigo.PropertyBags.Update(PropertyBag); return(new JsonNetResult(new { success = true })); } catch (Exception exception) { PropertyBag.OrderException = exception.Message; PropertyBag.IsSubmitting = false; _propertyBag = Exigo.PropertyBags.Update(PropertyBag); return(new JsonNetResult(new { success = false, message = exception.Message })); } } else { if (PropertyBag.NewOrderID > 0 || PropertyBag.NewAutoOrderID > 0) { return(new JsonNetResult(new { success = true })); } else { return(new JsonNetResult(new { success = false, message = Resources.Common.OrderSubmittingMessage })); } } }
public ShoppingCartLogicProvider(Controller controller, ShoppingCartItemsPropertyBag cart, ShoppingCartCheckoutPropertyBag propertyBag) { Controller = controller; Cart = cart; PropertyBag = propertyBag; }