public JsonNetResult AddAnnualMembershipAutoOrder() { try { var customer = Exigo.GetCustomer(Identity.Current.CustomerID); var newDate = new DateTime(DateTime.Now.Year, customer.CreatedDate.Month, customer.CreatedDate.Day) <= DateTime.Now ? new DateTime(DateTime.Now.AddYears(1).Year, customer.CreatedDate.Month, customer.CreatedDate.Day) : new DateTime(DateTime.Now.Year, customer.CreatedDate.Month, customer.CreatedDate.Day); CreateAutoOrderRequest autoOrderRequest = new CreateAutoOrderRequest() { Frequency = FrequencyType.Yearly, CustomerID = customer.CustomerID, StartDate = newDate, FirstName = customer.FirstName, LastName = customer.LastName, Address1 = customer.MainAddress.Address1, City = customer.MainAddress.City, State = customer.MainAddress.State, Country = customer.MainAddress.Country, Zip = customer.MainAddress.Zip, CurrencyCode = CurrencyCodes.DollarsUS, WarehouseID = Warehouses.Default, PriceType = PriceTypes.Wholesale, ShipMethodID = 8 }; OrderDetailRequest det = null; List <OrderDetailRequest> details = new List <OrderDetailRequest>(); det = new OrderDetailRequest() { ItemCode = "IAANNUALRENEWAL", Quantity = 1, }; details.Add(det); autoOrderRequest.Details = details.ToArray(); Exigo.WebService().CreateAutoOrder(autoOrderRequest); return(new JsonNetResult(new { success = true, action = "AddAnnualMembershipAutoOrder" })); } catch (Exception ex) { return(new JsonNetResult(new { success = false, message = ex.Message })); } }
public ActionResult ManageAutoOrder(int id, ManageAutoOrderViewModel viewModel) { var customerID = Identity.Customer.CustomerID; var apiRequests = new List <ApiRequest>(); var customer = Exigo.GetCustomer(customerID); var market = GlobalSettings.Markets.AvailableMarkets.Where(c => c.Countries.Contains(Identity.Customer.Country)).FirstOrDefault(); var configuration = market.GetConfiguration().AutoOrders; var warehouseID = configuration.WarehouseID; var isExistingAutoOrder = id != 0; var paymentMethods = Exigo.GetCustomerPaymentMethods(new GetCustomerPaymentMethodsRequest() { CustomerID = Identity.Customer.CustomerID, ExcludeIncompleteMethods = true }); // Remove all items that have no quantity. viewModel.AutoOrder.Details = viewModel.AutoOrder.Details.Where(d => d.Quantity > 0).ToList(); if (!viewModel.AutoOrder.Details.Any()) { ModelState.AddModelError("Result", "Please select at least one product for your Auto Order."); } if (ModelState.Keys.Contains("Result")) { InflateManageAutoOrderViewModel(customerID, market, configuration, ref viewModel); return(View(viewModel)); } // Save New Credit Card var isUsingNewCard = viewModel.AutoOrder.AutoOrderPaymentTypeID == 0; var hasPrimaryCard = paymentMethods.Where(v => v.IsComplete).Count() > 0; if (isUsingNewCard) { var saveCCRequest = new SetAccountCreditCardTokenRequest(viewModel.NewCreditCard); // If there is one or more available payment type, save the card in the secondary card slot if (hasPrimaryCard) { saveCCRequest.CreditCardAccountType = AccountCreditCardType.Secondary; viewModel.AutoOrder.AutoOrderPaymentTypeID = AutoOrderPaymentTypes.SecondaryCreditCardOnFile; } else { viewModel.AutoOrder.AutoOrderPaymentTypeID = AutoOrderPaymentTypes.PrimaryCreditCardOnFile; } saveCCRequest.CustomerID = customerID; apiRequests.Add(saveCCRequest); } // Prepare the auto order var autoOrder = viewModel.AutoOrder; var createAutoOrderRequest = new CreateAutoOrderRequest(autoOrder) { PriceType = configuration.PriceTypeID, WarehouseID = warehouseID, Notes = !string.IsNullOrEmpty(autoOrder.Notes) ? autoOrder.Notes : string.Format("Created with the API Auto-Delivery manager at \"{0}\" on {1:u} at IP {2} using {3} {4} ({5}).", Request.Url.AbsoluteUri, DateTime.Now.ToUniversalTime(), GlobalUtilities.GetClientIP(), HttpContext.Request.Browser.Browser, HttpContext.Request.Browser.Version, HttpContext.Request.Browser.Platform), CustomerID = customerID }; apiRequests.Add(createAutoOrderRequest); try { // Process the transaction var transaction = new TransactionalRequest { TransactionRequests = apiRequests.ToArray() }; var response = Exigo.WebService().ProcessTransaction(transaction); return(RedirectToAction("AutoOrderList", new { success = "1" })); } catch (Exception ex) { ModelState.AddModelError("Result", "We were unable to save your Auto-Delivery: " + ex.Message); InflateManageAutoOrderViewModel(customerID, market, configuration, ref viewModel); return(View(viewModel)); } }
// Creating an order private CreateAutoOrderRequest Request_SaveAutoship() { CreateAutoOrderRequest request = new CreateAutoOrderRequest(); if (Autoship.PropertyBag.ExistingAutoshipID > 0) { request.ExistingAutoOrderID = Autoship.PropertyBag.ExistingAutoshipID; request.OverwriteExistingAutoOrder = true; } request.CustomerID = Identity.Current.CustomerID; request.CurrencyCode = Autoship.Configuration.CurrencyCode; request.WarehouseID = Autoship.Configuration.WarehouseID; request.PriceType = Autoship.Configuration.PriceTypeID; request.ShipMethodID = Autoship.PropertyBag.ShipMethodID; request.Frequency = Autoship.PropertyBag.Frequency; request.StartDate = Autoship.PropertyBag.StartDate; request.Description = Autoship.PropertyBag.AutoshipDescription; switch(Autoship.PropertyBag.PaymentType) { case AutoshipCartPropertyBag.PaymentMethodType.PrimaryCreditCard: request.PaymentType = Exigo.WebService.AutoOrderPaymentType.PrimaryCreditCard; break; case AutoshipCartPropertyBag.PaymentMethodType.SecondaryCreditCard: request.PaymentType = Exigo.WebService.AutoOrderPaymentType.SecondaryCreditCard; break; case AutoshipCartPropertyBag.PaymentMethodType.NewCreditCard: if (Autoship.PropertyBag.CreditCardType == AccountCreditCardType.Primary) request.PaymentType = Exigo.WebService.AutoOrderPaymentType.PrimaryCreditCard; if (Autoship.PropertyBag.CreditCardType == AccountCreditCardType.Secondary) request.PaymentType = Exigo.WebService.AutoOrderPaymentType.SecondaryCreditCard; break; case AutoshipCartPropertyBag.PaymentMethodType.BankAccountOnFile: case AutoshipCartPropertyBag.PaymentMethodType.NewBankAccount: request.PaymentType = Exigo.WebService.AutoOrderPaymentType.CheckingAccount; break; default: throw new Exception(Autoship.PropertyBag.PaymentType.ToString() + " is an unsupported payment type for autoships at this time."); } request.FirstName = Autoship.PropertyBag.ShippingFirstName; request.LastName = Autoship.PropertyBag.ShippingLastName; request.Address1 = Autoship.PropertyBag.ShippingAddress1; request.Address2 = Autoship.PropertyBag.ShippingAddress2; request.City = Autoship.PropertyBag.ShippingCity; request.State = Autoship.PropertyBag.ShippingState; request.Zip = Autoship.PropertyBag.ShippingZip; request.Country = Autoship.PropertyBag.ShippingCountry; request.Phone = Autoship.PropertyBag.Phone; request.Email = Autoship.PropertyBag.Email; request.Details = GetOrderDetails(); return request; }
/// <remarks/> public void CreateAutoOrderAsync(CreateAutoOrderRequest CreateAutoOrderRequest, object userState) { if ((this.CreateAutoOrderOperationCompleted == null)) { this.CreateAutoOrderOperationCompleted = new System.Threading.SendOrPostCallback(this.OnCreateAutoOrderOperationCompleted); } this.InvokeAsync("CreateAutoOrder", new object[] { CreateAutoOrderRequest}, this.CreateAutoOrderOperationCompleted, userState); }
/// <remarks/> public void CreateAutoOrderAsync(CreateAutoOrderRequest CreateAutoOrderRequest) { this.CreateAutoOrderAsync(CreateAutoOrderRequest, null); }
public ActionResult SubmitCheckout() { if (!PropertyBag.IsSubmitting) { PropertyBag.IsSubmitting = true; _propertyBag = ExigoDAL.PropertyBags.Update(PropertyBag); try { // Start creating the API requests var apiRequests = new List <ApiRequest>(); // Create the customer var customerRequest = new CreateCustomerRequest(PropertyBag.Customer) { InsertEnrollerTree = true, EnrollerID = PropertyBag.EnrollerID, CustomerType = CustomerTypes.Distributor, EntryDate = DateTime.Now.ToCST(), CustomerStatus = CustomerStatuses.Active, CanLogin = true, DefaultWarehouseID = OrderConfiguration.WarehouseID, Notes = "Distributor was entered by Distributor #{0}. Created by the API Enrollment at ".FormatWith(Identity.Owner.CustomerID) + HttpContext.Request.Url.Host + HttpContext.Request.Url.LocalPath + " on " + DateTime.Now.ToCST().ToString("dddd, MMMM d, yyyy h:mmtt") + " CST at IP " + Common.GlobalUtilities.GetClientIP() + " using " + HttpContext.Request.Browser.Browser + " " + HttpContext.Request.Browser.Version + " (" + HttpContext.Request.Browser.Platform + ")." }; ///IF Unilevel Place in Sponsor Tree Now, Binary will be placed post transactional envelope if (!GlobalSettings.Exigo.UseBinary) { customerRequest.InsertUnilevelTree = true; customerRequest.SponsorID = customerRequest.EnrollerID; } apiRequests.Add(customerRequest); // Set a few variables up for our shippping address, order/auto order items and the default auto order payment type var shippingAddress = PropertyBag.ShippingAddress; var orderItems = ShoppingCart.Items.Where(i => i.Type == ShoppingCartItemType.Order || i.Type == ShoppingCartItemType.EnrollmentPack).ToList(); var autoOrderItems = ShoppingCart.Items.Where(i => i.Type == ShoppingCartItemType.AutoOrder || i.Type == ShoppingCartItemType.EnrollmentAutoOrderPack).ToList(); var autoOrderPaymentType = AutoOrderPaymentType.PrimaryCreditCard; // Create initial order var orderRequest = new CreateOrderRequest(OrderConfiguration, PropertyBag.ShipMethodID, orderItems, shippingAddress); // Add order request now if we need to do any testing with the accepted functionality apiRequests.Add(orderRequest); if (PropertyBag.PaymentMethod.CanBeParsedAs <BankAccount>()) { var bankAccount = PropertyBag.PaymentMethod.As <BankAccount>(); if (bankAccount.Type == ExigoService.BankAccountType.New) { apiRequests.Add(new DebitBankAccountRequest(bankAccount)); } else { apiRequests.Add(new DebitBankAccountOnFileRequest(bankAccount)); } } // Create subscription autoorder if an autoorder has been chosen if (autoOrderItems != null && autoOrderItems.Count() > 0) { var autoOrderRequest = new CreateAutoOrderRequest(AutoOrderConfiguration, autoOrderPaymentType, DateTime.Now.AddMonths(1).ToCST(), PropertyBag.ShipMethodID, autoOrderItems, shippingAddress); autoOrderRequest.Frequency = FrequencyType.Monthly; apiRequests.Add(autoOrderRequest); } // Create customer site var customerSiteRequest = new SetCustomerSiteRequest(PropertyBag.Customer); apiRequests.Add(customerSiteRequest); // Add the new credit card to the customer's record and charge it for the current order if (PropertyBag.PaymentMethod.CanBeParsedAs <CreditCard>()) { var creditCard = PropertyBag.PaymentMethod.As <CreditCard>(); if (!creditCard.IsTestCreditCard && !Request.IsLocal) { var saveCCRequest = new SetAccountCreditCardTokenRequest(creditCard); apiRequests.Add(saveCCRequest); var chargeCCRequest = new ChargeCreditCardTokenRequest(creditCard); apiRequests.Add(chargeCCRequest); } else { orderRequest.OrderStatus = GlobalUtilities.GetDefaultOrderStatusType(); } } // Process the transaction var transaction = new TransactionalRequest { TransactionRequests = apiRequests.ToArray() }; var response = ExigoDAL.WebService().ProcessTransaction(transaction); var newcustomerid = 0; var neworderid = 0; var newautoorderid = 0; if (response.Result.Status == ResultStatus.Success) { foreach (var apiresponse in response.TransactionResponses) { if (apiresponse.CanBeParsedAs <CreateCustomerResponse>()) { newcustomerid = apiresponse.As <CreateCustomerResponse>().CustomerID; } if (apiresponse.CanBeParsedAs <CreateOrderResponse>()) { neworderid = apiresponse.As <CreateOrderResponse>().OrderID; } if (apiresponse.CanBeParsedAs <CreateAutoOrderResponse>()) { newautoorderid = apiresponse.As <CreateAutoOrderResponse>().AutoOrderID; } } } ///If Binary Place Node Now if (GlobalSettings.Exigo.UseBinary) { var placeNodeRequest = new PlaceBinaryNodeRequest { CustomerID = newcustomerid, ToParentID = PropertyBag.EnrollerID, PlacementType = BinaryPlacementType.EvenFill }; ExigoDAL.WebService().PlaceBinaryNode(placeNodeRequest); } PropertyBag.NewCustomerID = newcustomerid; PropertyBag.NewOrderID = neworderid; PropertyBag.NewAutoOrderID = newautoorderid; _propertyBag = ExigoDAL.PropertyBags.Update(PropertyBag); // If the transaction was successful, then send the customer an email that will allow them to confirm thier opt in choice if (PropertyBag.Customer.IsOptedIn) { ExigoDAL.SendEmailVerification(newcustomerid, PropertyBag.Customer.Email); } var token = Security.Encrypt(new { CustomerID = newcustomerid, OrderID = neworderid, AutoOrderID = newautoorderid }); // Enrollment complete, now delete the Property Bag ExigoDAL.PropertyBags.Delete(PropertyBag); ExigoDAL.PropertyBags.Delete(ShoppingCart); return(new JsonNetResult(new { success = true, token = token })); } catch (Exception exception) { PropertyBag.OrderException = exception.Message; PropertyBag.IsSubmitting = false; _propertyBag = ExigoDAL.PropertyBags.Update(PropertyBag); return(new JsonNetResult(new { success = false, message = exception.Message })); } } else { if (PropertyBag.NewCustomerID > 0) { var token = Security.Encrypt(new { CustomerID = PropertyBag.NewCustomerID, OrderID = PropertyBag.NewOrderID, AutoOrderID = PropertyBag.NewAutoOrderID }); return(new JsonNetResult(new { success = true, token = token })); } 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 })); } } }