예제 #1
0
        public static void DeleteCustomerAddress(int customerID, AddressType type)
        {
            var deleteAddress = false;
            var request = new UpdateCustomerRequest();
            request.CustomerID = customerID;

            // Main address
            if (type == AddressType.Main)
            {
                deleteAddress        = true;
                request.MainAddress1 = string.Empty;
                request.MainAddress2 = string.Empty;
                request.MainCity     = string.Empty;
                request.MainState    = string.Empty;
                request.MainZip      = string.Empty;
                request.MainCountry  = string.Empty;
            }

            // Mailing address
            else if (type == AddressType.Mailing)
            {
                deleteAddress        = true;
                request.MailAddress1 = string.Empty;
                request.MailAddress2 = string.Empty;
                request.MailCity     = string.Empty;
                request.MailState    = string.Empty;
                request.MailZip      = string.Empty;
                request.MailCountry  = string.Empty;
            }

            // Other address
            else if (type == AddressType.Other)
            {
                deleteAddress         = true;
                request.OtherAddress1 = string.Empty;
                request.OtherAddress2 = string.Empty;
                request.OtherCity     = string.Empty;
                request.OtherState    = string.Empty;
                request.OtherZip      = string.Empty;
                request.OtherCountry  = string.Empty;
            }

            if (deleteAddress)
            {
                Exigo.WebService().UpdateCustomer(request);
            }
        }
        public void SendEmail(string url, int customerID, string emailAddress, string hashPassword)
        {
            try
            {
                //Send Email with Reset instructions
                MailMessage email = new MailMessage();

                email.From = new MailAddress(GlobalSettings.Emails.NoReplyEmail);
                email.To.Add(emailAddress);
                email.Subject = "Win Password Reset";

                email.Body = url;

                SmtpClient SmtpServer = new SmtpClient();
                SmtpServer.Host = GlobalSettings.Emails.SMTPConfigurations.Default.Server;
                SmtpServer.Port = GlobalSettings.Emails.SMTPConfigurations.Default.Port;
                SmtpServer.Credentials = new System.Net.NetworkCredential(GlobalSettings.Emails.SMTPConfigurations.Default.Username, GlobalSettings.Emails.SMTPConfigurations.Default.Password);
                SmtpServer.EnableSsl = GlobalSettings.Emails.SMTPConfigurations.Default.EnableSSL;

                Task.Factory.StartNew(() =>
                {
                    SmtpServer.Send(email);
                });

                UpdateCustomerRequest request = new UpdateCustomerRequest();
                request.CustomerID = customerID;
                request.Field3 = hashPassword;
                Exigo.WebService().UpdateCustomer(request);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public ActionResult ResetPassword(ResetPasswordViewModel model)
        {
            UpdateCustomerRequest updRequest = new UpdateCustomerRequest();
            updRequest.CustomerID = model.CustomerID;
            updRequest.LoginPassword = model.Password;
            updRequest.Field3 = string.Empty;
            var response = Exigo.WebService().UpdateCustomer(updRequest);

            return new JsonNetResult(new
            {
                success = true
            });
        }
예제 #4
0
        public static Address SetCustomerAddressOnFile(int customerID, Address address, AddressType type)
        {
            var saveAddress = false;
            var request = new UpdateCustomerRequest();
            request.CustomerID = customerID;

            // New Addresses
            if (type == AddressType.New)
            {
                return Exigo.SaveNewCustomerAddress(customerID, address);
            }

            // Main address
            if (type == AddressType.Main)
            {
                saveAddress          = true;
                request.MainAddress1 = address.Address1;
                request.MainAddress2 = address.Address2 ?? string.Empty;
                request.MainCity     = address.City;
                request.MainState    = address.State;
                request.MainZip      = address.Zip;
                request.MainCountry  = address.Country;
            }

            // Mailing address
            if (type == AddressType.Mailing)
            {
                saveAddress          = true;
                request.MailAddress1 = address.Address1;
                request.MailAddress2 = address.Address2 ?? string.Empty;
                request.MailCity     = address.City;
                request.MailState    = address.State;
                request.MailZip      = address.Zip;
                request.MailCountry  = address.Country;
            }

            // Other address
            if (type == AddressType.Other)
            {
                saveAddress           = true;
                request.OtherAddress1 = address.Address1;
                request.OtherAddress2 = address.Address2 ?? string.Empty;
                request.OtherCity     = address.City;
                request.OtherState    = address.State;
                request.OtherZip      = address.Zip;
                request.OtherCountry  = address.Country;
            }

            if (saveAddress)
            {
                Exigo.WebService().UpdateCustomer(request);
            }

            return address;
        }
예제 #5
0
        public static Address SaveNewCustomerAddress(int customerID, Address address)
        {
            var addressesOnFile = Exigo.GetCustomerAddresses(customerID).Where(c => c.IsComplete);

            // Do any of the addresses on file match the one we are using?
            // If not, save this address to the next available slot
            if (!addressesOnFile.Any(c => c.Equals(address)))
            {
                var saveAddress = false;
                var request = new UpdateCustomerRequest();
                request.CustomerID = customerID;

                // Main address
                if (!addressesOnFile.Any(c => c.AddressType == AddressType.Main))
                {
                    saveAddress          = true;
                    address.AddressType  = AddressType.Main;
                    request.MainAddress1 = address.Address1;
                    request.MainAddress2 = address.Address2;
                    request.MainCity     = address.City;
                    request.MainState    = address.State;
                    request.MainZip      = address.Zip;
                    request.MainCountry  = address.Country;
                }

                // Mailing address
                else if (!addressesOnFile.Any(c => c.AddressType == AddressType.Mailing))
                {
                    saveAddress          = true;
                    address.AddressType  = AddressType.Mailing;
                    request.MailAddress1 = address.Address1;
                    request.MailAddress2 = address.Address2;
                    request.MailCity     = address.City;
                    request.MailState    = address.State;
                    request.MailZip      = address.Zip;
                    request.MailCountry  = address.Country;
                }

                // Other address
                else
                {
                    saveAddress           = true;
                    address.AddressType   = AddressType.Other;
                    request.OtherAddress1 = address.Address1;
                    request.OtherAddress2 = address.Address2;
                    request.OtherCity     = address.City;
                    request.OtherState    = address.State;
                    request.OtherZip      = address.Zip;
                    request.OtherCountry  = address.Country;
                }

                if (saveAddress)
                {
                    Exigo.WebService().UpdateCustomer(request);
                }
            }

            return address;
        }
        public ActionResult SubmitCheckout()
        {
            // Do one final check to ensure that our logic points are met before attempting to submit
            var logicResult = LogicProvider.CheckLogic();
            if (!logicResult.IsValid)
            {
                return logicResult.NextAction;
            }

            // Set up our guest customer & testing variables
            var isGuestCheckout = Identity.Customer == null;
            var isLocal = Request.IsLocal;

            var isRedirectPayment = PropertyBag.IsRedirectPayment;

            try
            {
                // Start creating the API requests
                var details = new List<ApiRequest>();

                // Update our Retail Customer to Smart Shopper, if applicable
                if (PropertyBag.GetSmartShopperPrice)
                {
                    var address = PropertyBag.ShippingAddress;

                    var updateCustomerRequest = new UpdateCustomerRequest
                    {
                        CustomerID = Identity.Customer.CustomerID,
                        MainAddress1 = address.Address1,
                        MainAddress2 = address.Address2,
                        MainCity = address.City,
                        MainState = address.State,
                        MainZip = address.Zip,
                        MainCountry = address.Country,
                        CustomerType = CustomerTypes.SmartShopper
                    };

                    details.Add(updateCustomerRequest);

                    // Create the Replicated Site for our Smart Shopper
                    var newSite = new SetCustomerSiteRequest
                    {
                        CustomerID = Identity.Customer.CustomerID,
                        WebAlias = Identity.Customer.CustomerID.ToString(),
                        FirstName = Identity.Customer.FirstName,
                        LastName = Identity.Customer.LastName,
                        Address1 = address.Address1,
                        Address2 = address.Address2,
                        City = address.City,
                        State = address.State,
                        Zip = address.Zip,
                        Country = address.Country,
                        Email = address.Email,
                        Company = Identity.Customer.PublicName,
                        Phone = address.Phone
                    };

                    details.Add(newSite);
                }

                var orderItems = ShoppingCart.Items.Where(c => c.Type == ShoppingCartItemType.Order);
                var hasOrder = orderItems.Count() > 0;

                var autoOrderItems = ShoppingCart.Items.Where(c => c.Type == ShoppingCartItemType.AutoOrder);
                var hasAutoOrder = autoOrderItems.Count() > 0;

                // Create the order request, if applicable
                if (hasOrder)
                {
                    var orderRequest = new CreateOrderRequest(OrderConfiguration, PropertyBag.ShipMethodID, orderItems, PropertyBag.ShippingAddress);

                    if (!isGuestCheckout)
                    {
                        orderRequest.CustomerID = Identity.Customer.CustomerID;
                    }

                    if (isRedirectPayment)
                    {
                        orderRequest.OrderStatus = OrderStatusType.Pending;
                    }

                    if (Identity.Customer.CustomerTypeID == CustomerTypes.SmartShopper)
                    {
                        orderRequest.PriceType = PriceTypes.Wholesale;
                    }

                    if (hasAutoOrder)
                    {
                        orderRequest.PriceType = PriceTypes.Autoship;
                    }

                    details.Add(orderRequest);
                }

                // Create the autoorder request, if applicable
                if (hasAutoOrder)
                {
                    var autoOrderRequest = new CreateAutoOrderRequest(AutoOrderConfiguration, Exigo.GetAutoOrderPaymentType(PropertyBag.PaymentMethod), PropertyBag.AutoOrderStartDate, AutoOrderConfiguration.DefaultShipMethodID, autoOrderItems, PropertyBag.ShippingAddress);

                    autoOrderRequest.Frequency = FrequencyType.Monthly;

                    if (!isGuestCheckout)
                    {
                        autoOrderRequest.CustomerID = Identity.Customer.CustomerID;
                    }

                    details.Add(autoOrderRequest);
                }

                // Create the payment request
                if (PropertyBag.PaymentMethod is CreditCard)
                {
                    var card = PropertyBag.PaymentMethod as CreditCard;
                    if (card.Type == CreditCardType.New)
                    {
                        card = Exigo.SaveNewCustomerCreditCard(Identity.Customer.CustomerID, card);

                        if (hasAutoOrder)
                        {
                            if (!isGuestCheckout)
                            {
                                card = Exigo.SaveNewCustomerCreditCard(Identity.Customer.CustomerID, card);
                                ((CreateAutoOrderRequest)details.Where(c => c is CreateAutoOrderRequest).FirstOrDefault()).PaymentType = Exigo.GetAutoOrderPaymentType(card);
                            }
                            else
                            {
                                // Add logic if guest checkout is allowed : constructor for SetAccountCreditCardTokenRequest

                            }
                        }
                        if (hasOrder)
                        {
                            if (card.IsTestCreditCard)
                            {
                                // no need to charge card
                                ((CreateOrderRequest)details.Where(c => c is CreateOrderRequest).FirstOrDefault()).OrderStatus = OrderStatusType.Shipped;
                            }
                            else
                            {
                                if (!isLocal)
                                {
                                    details.Add(new ChargeCreditCardTokenRequest(card));
                                }
                            }
                        }
                    }
                    else
                    {
                        if (hasOrder)
                        {
                            if (card.IsTestCreditCard)
                            {
                                // no need to charge card
                            }
                            else
                            {
                                if (!isLocal)
                                {
                                    var cctype = (card.Type == CreditCardType.Primary) ? AccountCreditCardType.Primary : AccountCreditCardType.Secondary;
                                    details.Add(new ChargeCreditCardOnFileRequest { CreditCardAccountType = cctype });
                                }
                            }
                        }
                    }
                }

                // Process the transaction
                var transactionRequest = new TransactionalRequest();
                transactionRequest.TransactionRequests = details.ToArray();
                var transactionResponse = Exigo.WebService().ProcessTransaction(transactionRequest);

                var newOrderID = 1;
                var customerID = 0;
                if (transactionResponse.Result.Status == ResultStatus.Success)
                {
                    foreach (var response in transactionResponse.TransactionResponses)
                    {
                        if (response is CreateOrderResponse) newOrderID = ((CreateOrderResponse)response).OrderID;
                        if (response is CreateCustomerResponse) customerID = ((CreateCustomerResponse)response).CustomerID;
                    }
                }

                if (PropertyBag.GetSmartShopperPrice)
                {

                    Identity.Customer.Refresh();
                }

                customerID = Identity.Customer.CustomerID;
                var token = Security.Encrypt(new { OrderID = newOrderID, CustomerID = Identity.Customer.CustomerID });

                // handle redirect payments
                var selectedCountry = PropertyBag.ShippingAddress.Country;

                if (isRedirectPayment && hasOrder)
                {
                    var paymentProvider = PaymentService.GetPaymentProvider(selectedCountry);
                    var order = Exigo.GetCustomerOrders(new GetCustomerOrdersRequest()
                    {
                        CustomerID = customerID,
                        OrderID = newOrderID,
                        IncludeOrderDetails = true
                    }).FirstOrDefault();

                    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, BillingName = order.Recipient.FullName, BillingAddress = PropertyBag.BillingAddress, WebAlias = Identity.Owner.WebAlias });

                    // Handle the request
                    var postPaymentRequest = paymentRequest as POSTPaymentRequest;
                    if (postPaymentRequest != null)
                    {

                        Exigo.PropertyBags.Delete(PropertyBag);

                        return new JsonNetResult(new
                        {
                            success = true,
                            redirectForm = postPaymentRequest.RequestForm
                        });
                    }
                    else
                    {
                        //var urlHelper = new UrlHelper(Request.RequestContext);
                        //var completeUrl = urlHelper.Action("OrderComplete", new { token = token });

                        return new JsonNetResult(new
                        {
                            success = false,
                        });
                    }
                }

                return new JsonNetResult(new
                {
                    success = true,
                    token = token
                });

            }
            catch (Exception exception)
            {
                return new JsonNetResult(new
                {
                    success = false,
                    message = exception.Message
                });
            }
        }