public ActionResult Register(string ReturnUrl, AccountRegistrationViewModel model) { try { var orderConfiguration = Utilities.GetCurrentMarket().Configuration.Orders; // Save the customer var request = new CreateCustomerRequest(); //removed model.middlename because is not used in project JWJ 02July2015 request.FirstName = model.FirstName; request.LastName = model.LastName; request.Email = model.Username; request.Phone = model.PhoneNumber; request.CanLogin = true; request.LoginName = model.Username; request.LoginPassword = model.Password; request.CustomerType = CustomerTypes.RetailCustomer; request.CustomerStatus = CustomerStatuses.Active; request.InsertEnrollerTree = true; request.EnrollerID = (model.EnrollerID != 0) ? model.EnrollerID : Identity.Owner.CustomerID; request.SponsorID = Identity.Owner.CustomerID; request.InsertUnilevelTree = true; request.EntryDate = DateTime.Now; request.DefaultWarehouseID = orderConfiguration.WarehouseID; request.CurrencyCode = orderConfiguration.CurrencyCode; request.LanguageID = orderConfiguration.LanguageID; var response = Exigo.WebService().CreateCustomer(request); // Sign the customer into their backoffice var service = new IdentityService(); service.SignIn(model.Username, model.Password); if (ReturnUrl.IsNotEmpty()) return Redirect(ReturnUrl); else return RedirectToAction("index", "account", new { webalias = Identity.Owner.WebAlias }); } catch (Exception e) { ViewBag.Error = e.Message; if (ReturnUrl.IsNotEmpty()) return RedirectToAction("register", "account", new { success = false, ReturnUrl = ReturnUrl, webalias = Identity.Owner.WebAlias }); else return RedirectToAction("register", "account", new { success = false, webalias = Identity.Owner.WebAlias }); } }
public ActionResult SubmitEnrollment() { var isRedirectPayment = PropertyBag.IsRedirectPayment; try { // Start creating the API requests var apiRequests = new List<ApiRequest>(); // Create the customer var customerRequest = new CreateCustomerRequest(PropertyBag.Customer); customerRequest.InsertEnrollerTree = true; customerRequest.InsertUnilevelTree = true; customerRequest.CustomerType = CustomerTypes.BrandPartner; customerRequest.EnrollerID = Identity.Owner.CustomerID; customerRequest.SponsorID = Identity.Owner.CustomerID; customerRequest.EntryDate = DateTime.Now; customerRequest.CustomerStatus = CustomerStatuses.Active; customerRequest.CanLogin = true; customerRequest.LoginName = PropertyBag.Customer.LoginName; customerRequest.Company = PropertyBag.Customer.PublicName; customerRequest.CurrencyCode = OrderConfiguration.CurrencyCode; customerRequest.PayableType = PayableType.Check; customerRequest.LoginPassword = PropertyBag.Customer.Password; customerRequest.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.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 + ")."; 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; shippingAddress.FirstName = PropertyBag.Customer.FirstName; shippingAddress.LastName = PropertyBag.Customer.LastName; shippingAddress.Phone = PropertyBag.Customer.PrimaryPhone; shippingAddress.Email = PropertyBag.Customer.Email; var orderItems = ShoppingCart.Items.Where(i => i.Type == ShoppingCartItemType.EnrollmentPack).ToList(); // Create initial order var orderRequest = new CreateOrderRequest(OrderConfiguration, PropertyBag.ShipMethodID, orderItems, shippingAddress); if (isRedirectPayment) { orderRequest.OrderStatus = OrderStatusType.Pending; } // 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 we are dealing with a test credit card, then we set the order as accepted to simulate an 'Accepted' order if (!creditCard.IsTestCreditCard) { var chargeCCRequest = new ChargeCreditCardTokenRequest(creditCard); apiRequests.Add(chargeCCRequest); var saveCCRequest = new SetAccountCreditCardTokenRequest(creditCard); apiRequests.Add(saveCCRequest); } else { orderRequest.OrderStatus = OrderStatusType.Shipped; } } // Add order request now if we need to do any testing with the accepted functionality apiRequests.Add(orderRequest); // Process the transaction var transaction = new TransactionalRequest { TransactionRequests = apiRequests.ToArray() }; var response = Exigo.WebService().ProcessTransaction(transaction); var newcustomerid = 0; var neworderid = 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; } } // Update the customer web alias var propertyBagCustomer = PropertyBag.Customer; Task.Factory.StartNew(() => { var customerSiteRequest = new SetCustomerSiteRequest(propertyBagCustomer); customerSiteRequest.CustomerID = newcustomerid; customerSiteRequest.WebAlias = newcustomerid.ToString(); customerSiteRequest.FirstName = propertyBagCustomer.FirstName; customerSiteRequest.LastName = propertyBagCustomer.LastName; customerSiteRequest.Company = propertyBagCustomer.PublicName; SetCustomerSiteResponse res = Exigo.WebService().SetCustomerSite(customerSiteRequest); }); var token = Security.Encrypt(new { OrderID = neworderid, CustomerID = newcustomerid }); if (PropertyBag.Customer.IsOptedIn) { Exigo.SendEmailVerification(newcustomerid, propertyBagCustomer.Email); } var selectedCountry = PropertyBag.ShippingAddress.Country; // handle redirect payments if (isRedirectPayment) { var paymentProvider = PaymentService.GetPaymentProvider(selectedCountry); var order = Exigo.GetCustomerOrders(new GetCustomerOrdersRequest() { CustomerID = newcustomerid, OrderID = neworderid, IncludeOrderDetails = true }).FirstOrDefault(); if (paymentProvider.HandlerType == PaymentHandlerType.Remote) { paymentProvider.OrderConfiguration = OrderConfiguration; paymentProvider.Order = order; paymentProvider.Order.ShipMethodID = PropertyBag.ShipMethodID; } var billingAddress = new Address() { AddressType = AddressType.Other, Address1 = order.Recipient.Address1, Address2 = order.Recipient.Address2, City = order.Recipient.City, State = order.Recipient.State, Zip = order.Recipient.Zip, Country = order.Recipient.Country }; // Get the request data var paymentRequest = paymentProvider.GetPaymentRequest(new PaymentRequestArgs() { ReturnUrl = PaymentRedirectURL, BillingName = order.Recipient.FullName, BillingAddress = billingAddress, WebAlias = Identity.Owner.WebAlias }); // Handle the request var postPaymentRequest = paymentRequest as POSTPaymentRequest; if (postPaymentRequest != null) { return new JsonNetResult(new { success = true, redirectForm = postPaymentRequest.RequestForm }); } else { return new JsonNetResult(new { success = false, }); } //if (paymentProvider.HandlerType == PaymentHandlerType.Remote) //{ // //Exigo.PropertyBags.Delete(PropertyBag); // Exigo.PropertyBags.Delete(ShoppingCart); // paymentProvider.OrderConfiguration = OrderConfiguration; // paymentProvider.Order = order; // paymentProvider.Order.ShipMethodID = PropertyBag.ShipMethodID; // // Get the request data // var paymentRequest = paymentProvider.GetPaymentRequest(new PaymentRequestArgs() { ReturnUrl = PaymentRedirectURL, WebAlias = Identity.Owner.WebAlias, BillingAddress = PropertyBag.Customer.MainAddress }); // // Handle the request // var postPaymentRequest = paymentRequest as POSTPaymentRequest; // if (postPaymentRequest != null) // { // Exigo.PropertyBags.Delete(PropertyBag); // return new JsonNetResult(new // { // success = true, // redirectForm = postPaymentRequest.RequestForm // }); // } //} // return new JsonNetResult(new // { // success = false, // message = "redirect failed" //}); } // // Enrollment complete, now delete the Property Bag Exigo.PropertyBags.Delete(PropertyBag); Exigo.PropertyBags.Delete(ShoppingCart); return new JsonNetResult(new { token = token, success = true }); } catch (Exception ex) { return new JsonNetResult(new { message = ex.Message, success = false }); } }