コード例 #1
0
        public ActionResult Select(SubmitForm SubmitForm)
        {
            bool useSeparateUsernameAndEmail = Atomia.Common.Configuration.AtomiaCommon.Instance.SeparateUsernameAndEmail;
            List<Country> countryList = new List<Country>();

            bool paymentMethodCc = false; // finish payment method CC
            ViewData["WasAnError"] = 0;

            PaymentMethod defaultPaymentMethod;
            IList<PaymentMethod> resellerPaymentMethods = ResellerHelper.GetResellerPaymentMethods(out defaultPaymentMethod);

            bool paymentEnabled = resellerPaymentMethods.Any(m => m.GuiPluginName == "CCPayment");
            bool orderByPostEnabled = resellerPaymentMethods.Any(m => m.GuiPluginName == "InvoiceByPost");
            bool orderByEmailEnabled = resellerPaymentMethods.Any(m => m.GuiPluginName == "InvoiceByEmail");
            bool payPalEnabled = resellerPaymentMethods.Any(m => m.GuiPluginName == "PayPal");
            bool payExRedirectEnabled = resellerPaymentMethods.Any(m => m.GuiPluginName == "PayexRedirect");
            bool worldPayRedirectEnabled = resellerPaymentMethods.Any(m => m.GuiPluginName == "WorldPayRedirect");
            bool dibsFlexwinEnabled = resellerPaymentMethods.Any(m => m.GuiPluginName == "DibsFlexwin");
            bool worldPayXmlRedirectEnabled = resellerPaymentMethods.Any(m => m.GuiPluginName == "WorldPayXmlRedirect");
            bool adyenHppEnabled = resellerPaymentMethods.Any(m => m.GuiPluginName == "AdyenHpp");

            ViewData["PayexRedirectEnabled"] = payExRedirectEnabled;
            ViewData["WorldPayRedirectEnabled"] = worldPayRedirectEnabled;
            ViewData["DibsFlexwinEnabled"] = dibsFlexwinEnabled;
            ViewData["WorldPayXmlRedirectEnabled"] = worldPayXmlRedirectEnabled;
            ViewData["AdyenHppEnabled"] = adyenHppEnabled;

            ViewData["AddingSubdomain"] = false;
            if (this.Session["subdomain"] != null)
            {
                ViewData["AddingSubdomain"] = (bool)this.Session["subdomain"];
            }

            ViewData["DefaultPaymentPlugin"] = ControllerContext.HttpContext.Application["DefaultPaymentPlugin"];

            string orderByPostId = string.Empty;
            IList<RadioRow> list;
            List<ProductDescription> currentCart;

            var resellerId = ResellerHelper.GetResellerId();
            ViewData["ResellerId"] = resellerId;
            var currencyCode = ResellerHelper.GetResellerCurrencyCode();
            var countryCode = ResellerHelper.GetResellerCountryCode();

            ViewData["PaymentEnabled"] = paymentEnabled;
            ViewData["PayPalEnabled"] = payPalEnabled;

            var service = GeneralHelper.GetPublicOrderService(this.HttpContext.ApplicationInstance.Context);

            if (orderByPostEnabled)
            {
                orderByPostId = OrderModel.FetchPostOrderId(resellerId, null, Guid.Empty, currencyCode, countryCode);
                ViewData["OrderByPostId"] = orderByPostId;
                ViewData["OrderByPostEnabled"] = true;
            }
            else
            {
                ViewData["OrderByPostId"] = string.Empty;
                ViewData["OrderByPostEnabled"] = false;
            }

            if (orderByEmailEnabled)
            {
                ViewData["OrderByEmailEnabled"] = true;
            }
            else
            {
                ViewData["OrderByEmailEnabled"] = false;
            }

            AtomiaCultureInfo atomiaCultureInfo = null;
            if (this.HttpContext.Session["SessionAccountLanguages"] != null)
            {
                atomiaCultureInfo = (AtomiaCultureInfo)this.HttpContext.Session["SessionAccountLanguages"];
            }

            string languageCode = atomiaCultureInfo != null ? atomiaCultureInfo.Language : null;
            list = OrderModel.FetchPackagesData(this, resellerId, null, Guid.Empty, currencyCode, countryCode, languageCode);

            currentCart = SubmitForm.CurrentCart;

            if (ModelState.IsValid)
            {
                // Save form to session to be able to refill, e.g. on canceled payment.
                Session["SavedSubmitForm"] = SubmitForm;

                // call Billing to Submit form
                try
                {
                    OrderServiceReferences.AtomiaBillingPublicService.PublicOrder newOrder;
                    OrderServiceReferences.AtomiaBillingPublicService.PublicOrder myOrder = new OrderServiceReferences.AtomiaBillingPublicService.PublicOrder();
                    countryList = CountriesHelper.GetAllCountries(this.HttpContext, service);

                    List<PublicOrderCustomData> orderCustomData = new List<PublicOrderCustomData>();

                    myOrder.Address = GeneralHelper.PrepareForSubmit(SubmitForm.Address);
                    myOrder.Address2 = GeneralHelper.PrepareForSubmit(SubmitForm.Address2);

                    myOrder.BillingFirstName = GeneralHelper.PrepareForSubmit(SubmitForm.InvoiceContactName);
                    myOrder.BillingLastName = GeneralHelper.PrepareForSubmit(SubmitForm.InvoiceContactLastName);
                    myOrder.BillingCompany = GeneralHelper.PrepareForSubmit(SubmitForm.InvoiceCompany);

                    myOrder.BillingAddress = GeneralHelper.PrepareForSubmit(SubmitForm.InvoiceAddress);
                    myOrder.BillingAddress2 = GeneralHelper.PrepareForSubmit(SubmitForm.InvoiceAddress2);
                    myOrder.BillingCity = GeneralHelper.PrepareForSubmit(SubmitForm.InvoiceCity);
                    myOrder.BillingCountry = GeneralHelper.PrepareForSubmit(string.IsNullOrEmpty(SubmitForm.InvoiceCountryCode) ? SubmitForm.CountryCode : SubmitForm.InvoiceCountryCode);
                    if (SubmitForm.InvoicePostNumber != null)
                    {
                        myOrder.BillingZip = GeneralHelper.PrepareForSubmit(SubmitForm.InvoicePostNumber.Trim());
                    }

                    myOrder.BillingEmail = GeneralHelper.PrepareForSubmit(SubmitForm.InvoiceEmail);

                    myOrder.BillingPhone = GeneralHelper.PrepareForSubmit(Atomia.Common.FormattingHelper.FormatPhoneNumber(SubmitForm.InvoiceTelephone, SubmitForm.InvoiceCountryCode));
                    myOrder.BillingFax = GeneralHelper.PrepareForSubmit(Atomia.Common.FormattingHelper.FormatPhoneNumber(SubmitForm.InvoiceFax, SubmitForm.InvoiceCountryCode));
                    myOrder.BillingMobile = GeneralHelper.PrepareForSubmit(Atomia.Common.FormattingHelper.FormatPhoneNumber(SubmitForm.InvoiceMobile, SubmitForm.InvoiceCountryCode));

                    myOrder.City = GeneralHelper.PrepareForSubmit(SubmitForm.City);
                    myOrder.Company = GeneralHelper.PrepareForSubmit(SubmitForm.Company);
                    if (!string.IsNullOrEmpty(SubmitForm.OrgNumber))
                    {
                        string tmpString = GeneralHelper.PrepareForSubmit(SubmitForm.OrgNumber);
                        myOrder.CompanyNumber = tmpString;
                    }

                    myOrder.Country = GeneralHelper.PrepareForSubmit(SubmitForm.CountryCode);

                    myOrder.Currency = "SEK";
                    if (this.Session["OrderCurrencyCode"] != null && !string.IsNullOrEmpty((string)this.Session["OrderCurrencyCode"]))
                    {
                        myOrder.Currency = this.Session["OrderCurrencyCode"].ToString();
                    }

                    myOrder.Email = GeneralHelper.PrepareForSubmit(SubmitForm.Email);

                    myOrder.Fax = GeneralHelper.PrepareForSubmit(FormattingHelper.FormatPhoneNumber(SubmitForm.Fax, SubmitForm.CountryCode));
                    myOrder.Mobile = GeneralHelper.PrepareForSubmit(FormattingHelper.FormatPhoneNumber(SubmitForm.Mobile, SubmitForm.CountryCode));

                    myOrder.FirstName = GeneralHelper.PrepareForSubmit(SubmitForm.ContactName);
                    myOrder.LastName = GeneralHelper.PrepareForSubmit(SubmitForm.ContactLastName);
                    myOrder.LegalNumber = GeneralHelper.PrepareForSubmit(SubmitForm.VATNumber);

                    List<string> allPackagesIds = OrderModel.FetchAllPackagesIds(resellerId, null, Guid.Empty, currencyCode, countryCode);
                    IList<Product> products = GeneralHelper.GetProductProvider().GetShopProducts(resellerId, null, Guid.Empty, countryCode);
                    ProductDescription selectedPackage = currentCart.Find(p => allPackagesIds.Any(x => x == p.productID));
                    IList<Product> freePackages = OrderModel.FetchFreePackages(resellerId, null, Guid.Empty, currencyCode, countryCode);
                    IList<string> setupFeeIds = OrderModel.FetchSetupFeeIds(resellerId, null, Guid.Empty, countryCode, countryCode);

                    Session["PreselectedPackage"] = selectedPackage != null ? selectedPackage.productID : null;
                    Session["SavedPaymentPlugin"] = SubmitForm.RadioPaymentMethod;

                    List<PublicOrderItem> myOrderItems = new List<PublicOrderItem>();

                    string jsonDomainRegContact = string.Empty;
                    JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
                    if (SubmitForm.WhoisContact)
                    {
                        SubmitForm.DomainRegCity = GeneralHelper.PrepareForSubmit(SubmitForm.DomainRegCity);
                        SubmitForm.DomainRegCountryCode = GeneralHelper.PrepareForSubmit(SubmitForm.DomainRegCountryCode);
                        SubmitForm.DomainRegEmail = GeneralHelper.PrepareForSubmit(SubmitForm.DomainRegEmail);
                        SubmitForm.DomainRegFax = FormattingHelper.FormatPhoneNumber(SubmitForm.DomainRegFax, SubmitForm.DomainRegCountryCode);
                        SubmitForm.DomainRegContactName = GeneralHelper.PrepareForSubmit(SubmitForm.DomainRegContactName);
                        SubmitForm.DomainRegContactLastName = GeneralHelper.PrepareForSubmit(SubmitForm.DomainRegContactLastName);
                        SubmitForm.DomainRegCompany = GeneralHelper.PrepareForSubmit(SubmitForm.DomainRegCompany);
                        SubmitForm.DomainRegOrgNumber = GeneralHelper.PrepareForSubmit(SubmitForm.DomainRegOrgNumber);
                        SubmitForm.DomainRegAddress = GeneralHelper.PrepareForSubmit(SubmitForm.DomainRegAddress);
                        SubmitForm.DomainRegAddress2 = GeneralHelper.PrepareForSubmit(SubmitForm.DomainRegAddress2);
                        SubmitForm.DomainRegVATNumber = GeneralHelper.PrepareForSubmit(SubmitForm.DomainRegVATNumber);
                        SubmitForm.DomainRegTelephone = FormattingHelper.FormatPhoneNumber(SubmitForm.DomainRegTelephone, SubmitForm.DomainRegCountryCode);
                        SubmitForm.DomainRegPostNumber = GeneralHelper.PrepareForSubmit(SubmitForm.DomainRegPostNumber);
                        jsonDomainRegContact = javaScriptSerializer.Serialize(new DomainRegContact
                            {
                                City = SubmitForm.DomainRegCity,
                                Country = SubmitForm.DomainRegCountryCode,
                                Email = SubmitForm.DomainRegEmail,
                                Fax = SubmitForm.DomainRegFax,
                                Name = SubmitForm.DomainRegContactName + " " + SubmitForm.DomainRegContactLastName,
                                Org = SubmitForm.DomainRegCompany,
                                OrgNo = SubmitForm.DomainRegOrgNumber,
                                Street1 = SubmitForm.DomainRegAddress,
                                Street2 = SubmitForm.DomainRegAddress2,
                                VatNo = SubmitForm.DomainRegVATNumber,
                                Voice = SubmitForm.DomainRegTelephone,
                                Zip = SubmitForm.DomainRegPostNumber.Trim(),
                                CustomFields = javaScriptSerializer.Serialize(SubmitForm.CustomFields)
                            });
                    }

                    foreach (ProductDescription tmpProduct in currentCart)
                    {
                        // If post invoice is selected do not add it to orderItems since that product is added via orderCustomAttributes
                        if (SubmitForm.RadioPaymentMethod == "InvoiceByPost")
                        {
                            if (tmpProduct.productID == orderByPostId)
                            {
                                continue;
                            }
                        }

                        // Get renewal period id for current cart product
                        Guid renewalPeriodId = Guid.Empty;
                        if (!string.IsNullOrEmpty(tmpProduct.RenewalPeriodId))
                        {
                            try
                            {
                                renewalPeriodId = new Guid(tmpProduct.RenewalPeriodId);
                            }
                            catch (Exception)
                            {
                            }
                        }

                        if (setupFeeIds.Any(id => id == tmpProduct.productID))
                        {
                            PublicOrderItem tmpItem = new PublicOrderItem
                            {
                                ItemId = Guid.Empty,
                                ItemNumber = tmpProduct.productID,
                                RenewalPeriodId = renewalPeriodId,
                                Quantity = 1
                            };

                            myOrderItems.Add(tmpItem);
                        }
                        else if (tmpProduct.productID != selectedPackage.productID)
                        {
                            // it's domain
                            List<PublicOrderItemProperty> arrayOfCustoms = new List<PublicOrderItemProperty>();
                            if (freePackages.Any(f => f.ArticleNumber == selectedPackage.productID))
                            {
                                // if the selected package in the cart is free
                                string domainValue = SubmitForm.FirstOption ? tmpProduct.productDesc : (SubmitForm.OwnDomain.StartsWith("www") ? SubmitForm.OwnDomain.Remove(0, 4) : SubmitForm.OwnDomain);

                                arrayOfCustoms.Add(new PublicOrderItemProperty { Name = "DomainName", Value = domainValue });

                                arrayOfCustoms.Add(new PublicOrderItemProperty { Name = "AtomiaService", Value = "CsDomainParking" });
                                Product package = products.FirstOrDefault(p => p.ArticleNumber == selectedPackage.productID);
                                if (SubmitForm.FirstOption == false)
                                {
                                    arrayOfCustoms.Add(new PublicOrderItemProperty { Name = "MainDomain", Value = "true" });
                                    if (package != null && package.Properties != null && package.Properties.ContainsKey("atomiaserviceextraproperties"))
                                    {
                                        arrayOfCustoms.Add(new PublicOrderItemProperty
                                        {
                                            Name = "AtomiaServiceExtraProperties",
                                            Value = package.Properties["atomiaserviceextraproperties"].
                                                ToString()
                                        });
                                    }
                                }

                                if (SubmitForm.WhoisContact)
                                {
                                    arrayOfCustoms.Add(new PublicOrderItemProperty
                                    {
                                        Name = "DomainRegContact",
                                        Value = jsonDomainRegContact
                                    });
                                }

                                PublicOrderItem tmpItem = new PublicOrderItem
                                {
                                    ItemId = Guid.Empty,
                                    ItemNumber = tmpProduct.productID,
                                    Quantity = 1,
                                    RenewalPeriodId = renewalPeriodId,
                                    CustomData = arrayOfCustoms.ToArray()
                                };

                                myOrderItems.Add(tmpItem);
                            }
                            else
                            {
                                bool websitesAllowed = true;
                                Product package = products.FirstOrDefault(p => p.ArticleNumber == selectedPackage.productID);
                                if (package != null && package.Properties != null && package.Properties.ContainsKey("nowebsites") && package.Properties["nowebsites"].ToLowerInvariant() == "true")
                                {
                                    websitesAllowed = false;
                                }

                                // if the selected package in the cart is not free)
                                if (SubmitForm.FirstOption)
                                {
                                    string websiteType = websitesAllowed
                                                                ? (tmpProduct.productDesc == SubmitForm.MainDomainSelect
                                                                    ? "CsLinuxWebsite"
                                                                    : "CsDomainParking")
                                                                : "CsDomainParking";

                                    // check if the current product is main domain
                                    arrayOfCustoms.Add(new PublicOrderItemProperty { Name = "DomainName", Value = tmpProduct.productDesc });
                                    arrayOfCustoms.Add(new PublicOrderItemProperty { Name = "AtomiaService", Value = websiteType });
                                    if (tmpProduct.productDesc == SubmitForm.MainDomainSelect)
                                    {
                                        arrayOfCustoms.Add(new PublicOrderItemProperty { Name = "MainDomain", Value = "true" });
                                        if (package != null && package.Properties != null && package.Properties.ContainsKey("atomiaserviceextraproperties"))
                                        {
                                            arrayOfCustoms.Add(new PublicOrderItemProperty
                                            {
                                                Name = "AtomiaServiceExtraProperties",
                                                Value = package.Properties["atomiaserviceextraproperties"].
                                                    ToString()
                                            });
                                        }
                                    }
                                    if (SubmitForm.WhoisContact)
                                    {
                                        arrayOfCustoms.Add(new PublicOrderItemProperty { Name = "DomainRegContact", Value = jsonDomainRegContact });
                                    }
                                }
                                else
                                {
                                    string websiteType = websitesAllowed ? "CsLinuxWebsite" : "CsDomainParking";
                                    arrayOfCustoms.Add(new PublicOrderItemProperty { Name = "MainDomain", Value = "true" });
                                    if (package != null && package.Properties != null && package.Properties.ContainsKey("atomiaserviceextraproperties"))
                                    {
                                        arrayOfCustoms.Add(new PublicOrderItemProperty
                                        {
                                            Name = "AtomiaServiceExtraProperties",
                                            Value = package.Properties["atomiaserviceextraproperties"]
                                        });
                                    }

                                    arrayOfCustoms.Add(new PublicOrderItemProperty { Name = "DomainName", Value = SubmitForm.OwnDomain.StartsWith("www") ? SubmitForm.OwnDomain.Remove(0, 4) : SubmitForm.OwnDomain });
                                    arrayOfCustoms.Add(new PublicOrderItemProperty { Name = "AtomiaService", Value = websiteType });
                                }

                                PublicOrderItem tmpItem = new PublicOrderItem
                                {
                                    ItemId = Guid.Empty,
                                    ItemNumber = tmpProduct.productID,
                                    Quantity = 1,
                                    RenewalPeriodId = renewalPeriodId,
                                    CustomData = arrayOfCustoms.ToArray()
                                };

                                myOrderItems.Add(tmpItem);
                            }
                        }
                        else
                        {
                            // it's package
                            if (freePackages.Any(f => f.ArticleNumber == selectedPackage.productID))
                            {
                                // if it's free package, just add it
                                PublicOrderItem tmpItem = new PublicOrderItem
                                                                {
                                                                    ItemId = Guid.Empty,
                                                                    ItemNumber = tmpProduct.productID,
                                                                    RenewalPeriodId = renewalPeriodId,
                                                                    Quantity = 1
                                                                };

                                myOrderItems.Add(tmpItem);
                            }
                            else
                            {
                                // if it's not a free package
                                PublicOrderItem tmpItem = new PublicOrderItem
                                {
                                    ItemId = Guid.Empty,
                                    ItemNumber = tmpProduct.productID,
                                    RenewalPeriodId = renewalPeriodId,
                                    Quantity = 1
                                };

                                myOrderItems.Add(tmpItem);
                            }
                        }
                    }

                    PublicOrderConfigurationSection opcss = Helpers.LocalConfigurationHelper.GetLocalConfigurationSection();
                    Dictionary<string, string> emailProps = new Dictionary<string, string>();
                    JavaScriptSerializer jsemail = javaScriptSerializer;
                    bool addApplication = false;

                    foreach (PublicOrderItem myOrderItem in myOrderItems)
                    {
                        emailProps = new Dictionary<string, string>();
                        if (opcss.DomainRegistrySpecificProducts.GetItemByKey(myOrderItem.ItemNumber) != null)
                        {
                            List<PublicOrderItemProperty> arrayOfCustoms = myOrderItem.CustomData.ToList();
                            if (SubmitForm.DomainSpeciffic == null)
                            {
                                throw new Exception("Order could not be created. DomainRegistrySpecificAttributes missing for " + myOrderItem.ItemNumber + " domain");
                            }

                            string emailType = opcss.DomainRegistrySpecificProducts.GetItemByKey(myOrderItem.ItemNumber).Email;
                            if (!string.IsNullOrEmpty(emailType))
                            {
                                string cccEmail =
                                opcss.DomainRegistrySpecificProducts.GetItemByKey(myOrderItem.ItemNumber).CccEmail;
                                emailProps.Add("Type", emailType);
                                if (myOrderItem.CustomData.Any(v => v.Name == "DomainName"))
                                {
                                    emailProps.Add("Domain", myOrderItem.CustomData.FirstOrDefault(v => v.Name == "DomainName").Value ?? string.Empty);
                                }

                                Dictionary<string, string> domainSpecific = new Dictionary<string, string>();
                                domainSpecific = jsemail.Deserialize<Dictionary<string, string>>(SubmitForm.DomainSpeciffic);
                                emailProps.Add("Name", domainSpecific.FirstOrDefault(v => v.Key == "AcceptName").Value ?? string.Empty);
                                emailProps.Add("Time", domainSpecific.FirstOrDefault(v => v.Key == "AcceptDate").Value ?? string.Empty);
                                emailProps.Add("Orgnum", myOrder.CompanyNumber);
                                emailProps.Add("Company", myOrder.Company);
                                emailProps.Add("Version", domainSpecific.FirstOrDefault(v => v.Key == "AcceptVersion").Value ?? string.Empty);
                                emailProps.Add("Ccc", cccEmail);
                                arrayOfCustoms.Add(new PublicOrderItemProperty { Name = "MailOnOrder", Value = jsemail.Serialize(emailProps) });
                            }

                            arrayOfCustoms.Add(new PublicOrderItemProperty { Name = "DomainRegistrySpecificAttributes", Value = SubmitForm.DomainSpeciffic });
                            myOrderItem.CustomData = arrayOfCustoms.ToArray();
                        }

                        if (myOrderItem.ItemNumber == "HST-APPY")
                        {
                            addApplication = true;
                        }
                    }

                    if (addApplication)
                    {
                        PublicOrderItem tmpItem = myOrderItems.Where(i => i.CustomData != null && i.CustomData.Any(c => c.Name == "MainDomain")).FirstOrDefault();

                        if (tmpItem == null)
                        {
                            throw new Exception("Unable to find MainDomain order item");
                        }

                        PublicOrderItemProperty tmpProperty = tmpItem.CustomData.Where(c => c.Name == "DomainName").FirstOrDefault();

                        myOrderItems.Add(new PublicOrderItem
                        {
                            ItemId = Guid.Empty,
                            ItemNumber = "XSV-APP",
                            Quantity = 1,
                            CustomData = new[]
                                {
                                    new PublicOrderItemProperty
                                    {
                                        Name = "DomainName",
                                        Value = tmpProperty.Value
                                    },
                                    new PublicOrderItemProperty
                                    {
                                        Name = "ApplicationName",
                                        Value = "wordpress"
                                    }
                                }
                        });
                    }

                    if (SubmitForm.RadioPaymentMethod == "InvoiceByEmail")
                    {
                        orderCustomData.Add(new PublicOrderCustomData { Name = "PayByInvoice", Value = "true" });
                    }

                    if (SubmitForm.RadioPaymentMethod == "InvoiceByPost")
                    {
                        orderCustomData.Add(new PublicOrderCustomData { Name = "SendInvoiceByPost", Value = "true" });
                        orderCustomData.Add(new PublicOrderCustomData { Name = "PayByInvoice", Value = "true" });
                    }

                    string paymentMethod = SubmitForm.RadioPaymentMethod;
                    if (paymentMethod == "InvoiceByEmail" || paymentMethod == "InvoiceByPost") {
                        paymentMethod = "PayWithInvoice";
                    }
                    orderCustomData.Add(new PublicOrderCustomData { Name = "PaymentMethod", Value = paymentMethod });

                    if (!string.IsNullOrEmpty((string)Session["SpecialPID"]))
                    {
                        orderCustomData.Add(new PublicOrderCustomData { Name = "SpecialPID", Value = (string)Session["SpecialPID"] });
                    }

                    if (!string.IsNullOrEmpty(SubmitForm.VATValidationMessage))
                    {
                        orderCustomData.Add(new PublicOrderCustomData { Name = "VATValidationMessage", Value = SubmitForm.VATValidationMessage });
                    }

                    if (!string.IsNullOrEmpty(SubmitForm.RadioBillingContact))
                    {
                        orderCustomData.Add(new PublicOrderCustomData { Name = "BillingContact", Value = SubmitForm.RadioBillingContact });
                    }

                    if (!string.IsNullOrEmpty(SubmitForm.RadioTechContact))
                    {
                        orderCustomData.Add(new PublicOrderCustomData { Name = "TechContact", Value = SubmitForm.RadioTechContact });
                    }

                    if (SubmitForm.CustomFields != null && SubmitForm.CustomFields.Keys.Count > 0)
                    {
                        orderCustomData.Add(
                            new PublicOrderCustomData
                                {
                                    Name = "DomainContactCustomFields",
                                    Value = javaScriptSerializer.Serialize(SubmitForm.CustomFields)
                                });
                    }

                    // Add CustommData posted with submit, client added
                    if (!string.IsNullOrEmpty(SubmitForm.OrderCustomData))
                    {
                        try
                        {
                            JavaScriptSerializer js = javaScriptSerializer;
                            orderCustomData.AddRange(js.Deserialize<PublicOrderCustomData[]>(SubmitForm.OrderCustomData));
                        }
                        catch (Exception ex)
                        {
                            OrderPageLogger.LogOrderPageException(ex);
                            throw;
                        }
                    }

                    // Add IP address of the customer as the custom order attribute
                    string ip = this.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                    if (!string.IsNullOrEmpty(ip))
                    {
                        string[] ipRange = ip.Split(',');
                        string trueIp = ipRange[0];

                        orderCustomData.Add(new PublicOrderCustomData { Name = "IpAddress", Value = trueIp });
                    }
                    else
                    {
                        ip = this.Request.ServerVariables["REMOTE_ADDR"];
                        orderCustomData.Add(new PublicOrderCustomData { Name = "IpAddress", Value = ip });
                    }

                    if (atomiaCultureInfo != null)
                    {
                        orderCustomData.Add(new PublicOrderCustomData { Name = "Language", Value = string.Format("{0}-{1}", atomiaCultureInfo.Language, atomiaCultureInfo.Culture) });
                    }

                    if (this.HttpContext.Application.AllKeys.Contains("ImmediateProvisioning") &&
                        this.HttpContext.Application["ImmediateProvisioning"].ToString().ToLowerInvariant() == "true")
                    {
                        orderCustomData.Add(new PublicOrderCustomData { Name = "ImmediateProvisioning", Value = "true" });
                    }

                    if (IndexHelper.IsImmediateLoginEnabled(this))
                    {
                        orderCustomData.Add(new PublicOrderCustomData { Name = "ShowHcpLandingPage", Value = "true" });
                    }

                    if (useSeparateUsernameAndEmail)
                    {
                        orderCustomData.Add(new PublicOrderCustomData { Name = "Username", Value = SubmitForm.Username });
                    }

                    myOrder.CustomData = orderCustomData.ToArray();
                    myOrder.OrderItems = myOrderItems.ToArray();
                    myOrder.ResellerId = ResellerHelper.GetResellerId();
                    myOrder.Phone = GeneralHelper.PrepareForSubmit(FormattingHelper.FormatPhoneNumber(SubmitForm.Telephone, SubmitForm.CountryCode));
                    myOrder.Zip = GeneralHelper.PrepareForSubmit(SubmitForm.PostNumber.Trim());
                    myOrder.PaymentMethod = SubmitForm.RadioPaymentMethod == "InvoiceByEmail" || SubmitForm.RadioPaymentMethod == "InvoiceByPost"
                                                ? OrderServiceReferences.AtomiaBillingPublicService.PaymentMethodEnum.PayByInvoice
                                                : OrderServiceReferences.AtomiaBillingPublicService.PaymentMethodEnum.PayByCard;

                    if (IndexHelper.IsImmediateLoginEnabled(this))
                    {
                        string resellerRootDomain = UriHelper.GetRootDomain(HttpContext.Request.Url.AbsoluteUri);
                        string token;
                        newOrder = service.CreateOrderWithLoginToken(myOrder, resellerRootDomain, out token);
                        this.Session["ImmediateLoginUrl"] = IndexHelper.GetImmediateLoginUrl(this, myOrder.Email, token);
                    }
                    else
                    {
                        newOrder = service.CreateOrder(myOrder);
                    }

                    if (newOrder == null)
                    {
                        throw new Exception("Order could not be created.");
                    }

                    this.Session["CreatedOrder"] = newOrder;

                    OrderPageLogger.LogAudit(
                        AuditActionTypes.OrderCreated,
                        string.Empty,
                        newOrder.CustomerId.ToString(),
                        newOrder.Email,
                        newOrder.Id.ToString(),
                        null);

                    if (SubmitForm.RadioPaymentMethod != "InvoiceByPost" && SubmitForm.RadioPaymentMethod != "InvoiceByEmail")
                    {
                        if (newOrder.Total > decimal.Zero)
                        {
                            paymentMethodCc = SubmitForm.RadioPaymentMethod != "PayPal";
                            string result = this.CreatePaymentTransaction(
                                this, newOrder, newOrder.Total, SubmitForm.RadioPaymentMethod);

                            if (!string.IsNullOrEmpty(result))
                            {
                                return Redirect(result);
                            }
                        }
                    }

                    if (IndexHelper.IsImmediateLoginEnabled(this))
                    {
                        Response.Redirect(this.Session["ImmediateLoginUrl"].ToString());
                    }
                    else
                    {
                        return this.RedirectToAction("Thankyou");
                    }
                }
                catch (Exception ex)
                {
                    OrderPageLogger.LogOrderPageException(ex);
                }
            }
            else
            {
                ViewData["WasAnError"] = 1;
            }

            if ((bool)Session["firstOption"])
            {
                ViewData["multiDomains"] = this.Session["multiDomains"];
                ViewData["firstOption"] = (bool)Session["firstOption"];
                ViewData["domainsForCheck"] = SubmitForm.SearchDomains;
                ViewData["OwnDomain"] = string.Empty;
            }
            else
            {
                DomainDataFromXML singleDomain = (DomainDataFromXML)Session["singleDomain"];
                ViewData["OwnDomain"] = string.Empty;
                ViewData["firstOption"] = (bool)Session["firstOption"];
                if (singleDomain != null)
                {
                    ViewData["Domain"] = singleDomain;
                    ViewData["OwnDomain"] = singleDomain.ProductName;
                }
            }

            string cartProducts = string.Empty;
            for (int i = 0; i < currentCart.Count; i++)
            {
                bool package = list.Where(listItem => listItem.productId == currentCart[i].productID).Count() > 0;

                if (i < currentCart.Count - 1)
                {
                    cartProducts += currentCart[i].productID + "|" + currentCart[i].productDesc + "|" + currentCart[i].RenewalPeriodId + "|" + package + "|";
                }
                else
                {
                    cartProducts += currentCart[i].productID + "|" + currentCart[i].productDesc + "|" + currentCart[i].RenewalPeriodId + "|" + package;
                }
            }

            // Needed for Cart partial
            ViewData["CartProducts"] = cartProducts;

            ViewData["radioList"] = list;

            // Needed for Cart partial
            string switchedId = list[0].productId + "|" + list[0].productNameDesc + "|" + list[0].RenewalPeriodId;
            if (list[0].SetupFee != null)
            {
                switchedId += "|" + list[0].SetupFee.productID + "|" + list[0].SetupFee.productDesc + "|" +
                              list[0].SetupFee.RenewalPeriodId;
            }

            ViewData["switchedId"] = switchedId;

            if (paymentMethodCc)
            {
                // only if CC payment failed
                ViewData["WasAnError"] = 2;
            }
            else
            {
                ViewData["WasAnError"] = 1;
            }

            // supported countries
            try
            {
                countryList = CountriesHelper.GetAllCountries(this.HttpContext, service);
            }
            catch (Exception ex)
            {
                OrderPageLogger.LogOrderPageException(ex);
            }

            ViewData["CountryList"] = CountriesHelper.GetSupportedCountriesSelectList(countryList);
            List<string> euCountries = CountriesHelper.GetEUCountryCodes(countryList);
            string euString = string.Empty;
            for (int i = 0; i < euCountries.Count; i++)
            {
                if (i < euCountries.Count - 1)
                {
                    euString += euCountries[i] + ' ';
                }
                else
                {
                    euString += euCountries[i];
                }
            }

            ViewData["EUCountries"] = euString;

            ViewData["RegDomainFront"] = RegularExpression.GetRegularExpression("DomainFront");
            ViewData["RegDomain"] = RegularExpression.GetRegularExpression("Domain");

            int allowedDomainLength;
            int numberOfDomainsAllowed;
            if (this.HttpContext.Application["DomainSearchAllowedDomainLength"] != null && (string)this.HttpContext.Application["DomainSearchAllowedDomainLength"] != string.Empty
                && this.HttpContext.Application["DomainSearchNumberOfDomainsAllowed"] != null && (string)this.HttpContext.Application["DomainSearchNumberOfDomainsAllowed"] != string.Empty)
            {
                allowedDomainLength = int.Parse((string)this.HttpContext.Application["DomainSearchAllowedDomainLength"]);
                numberOfDomainsAllowed = int.Parse((string)this.HttpContext.Application["DomainSearchNumberOfDomainsAllowed"]);
            }
            else
            {
                throw new ConfigurationErrorsException("Missing AllowedDomainLength or NumberOfDomainsAllowed in configuration");
            }

            ViewData["AllowedDomainLength"] = allowedDomainLength;
            ViewData["NumberOfDomainsAllowed"] = numberOfDomainsAllowed;

            // Check if there is locale setting for country in cookie ad set if there is
            if (System.Web.HttpContext.Current.Request.Cookies["OrderLocaleCookie"] != null && !string.IsNullOrEmpty(System.Web.HttpContext.Current.Request.Cookies["OrderLocaleCookie"].Value))
            {
                countryCode = System.Web.HttpContext.Current.Request.Cookies["OrderLocaleCookie"].Value.Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[1];
            }

            ViewData["defaultCountry"] = countryCode;

            // This is supose to be set in InternationalizationProvider
            CultureInfo locale = Thread.CurrentThread.CurrentCulture;

            ViewData["decimalSeparator"] = locale.NumberFormat.NumberDecimalSeparator;
            ViewData["groupSeparator"] = locale.NumberFormat.NumberGroupSeparator;

            // Show or hide Personal number field
            bool showPersonalNumber = true;
            string showPersonalNumberSetting = GeneralHelper.FetchPluginParameterFromConfig("ShowPersonalNumber");

            if (!string.IsNullOrEmpty(showPersonalNumberSetting))
            {
                bool parsedValue;
                if (bool.TryParse(showPersonalNumberSetting, out parsedValue))
                {
                    showPersonalNumber = parsedValue;
                }
            }

            ViewData["ShowPersonalNumber"] = showPersonalNumber;

            ViewData["ItemCategories"] = CustomerValidationHelper.GetItemCategories(resellerId);
            ViewData["SeparateUsernameAndEmail"] = useSeparateUsernameAndEmail;

            return View(SubmitForm);
        }
コード例 #2
0
        public ActionResult Select()
        {
            if (Session == null || Session["firstOption"] == null)
            {
                bool skipIndexPage;
                if (this.HttpContext.Application.AllKeys.Contains("SkipIndexPage") && bool.TryParse(this.HttpContext.Application["SkipIndexPage"].ToString(), out skipIndexPage)
                    && skipIndexPage)
                {
                    Session["firstOption"] = true;
                    Session["domains"] = new string[] { };
                    Session["singleDomain"] = null;
                    Session["subdomain"] = false;
                    Session["multiDomains"] = new List<DomainDataFromXml>();
                }
                else
                {
                    return RedirectToAction("Index");
                }
            }

            // supported countries
            string countryCode = ResellerHelper.GetResellerCountryCode();

            // Check if there is locale setting for country in cookie ad set if there is)
            if (System.Web.HttpContext.Current.Request.Cookies["OrderLocaleCookie"] != null && !String.IsNullOrEmpty(System.Web.HttpContext.Current.Request.Cookies["OrderLocaleCookie"].Value))
            {
                countryCode = System.Web.HttpContext.Current.Request.Cookies["OrderLocaleCookie"].Value.Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[1];
            }

            ViewData["defaultCountry"] = countryCode;
            string currencyCode = ResellerHelper.GetResellerCurrencyCode();
            var resellerId = ResellerHelper.GetResellerId();
            ViewData["ResellerId"] = resellerId;

            // Show or hide Personal number field
            bool showPersonalNumber = true;
            string showPersonalNumberSetting = GeneralHelper.FetchPluginParameterFromConfig("ShowPersonalNumber");

            if (!string.IsNullOrEmpty(showPersonalNumberSetting))
            {
                bool parsedValue;
                if (bool.TryParse(showPersonalNumberSetting, out parsedValue))
                {
                    showPersonalNumber = parsedValue;
                }
            }

            ViewData["ShowPersonalNumber"] = showPersonalNumber;

            // This is supose to be set in InternationalizationProvider
            System.Globalization.CultureInfo locale = Thread.CurrentThread.CurrentCulture;

            ViewData["decimalSeparator"] = locale.NumberFormat.NumberDecimalSeparator;
            ViewData["groupSeparator"] = locale.NumberFormat.NumberGroupSeparator;

            // Get currency decimal places from session
            int currencyDecimalPlaces = Session["CurrencyDecimalPlaces"] != null
                ? (int)Session["CurrencyDecimalPlaces"]
                : 2;

            ViewData["CurrencyDecimalPlaces"] = currencyDecimalPlaces;
            ViewData["CurrencyDecimalPlacesFormat"] = string.Format("#,###.{0}", new string('0', currencyDecimalPlaces));

            List<Country> countryList = new List<Country>();

            var service = GeneralHelper.GetPublicOrderService(this.HttpContext.ApplicationInstance.Context);

            try
            {
                countryList = CountriesHelper.GetAllCountries(this.HttpContext, service);
            }
            catch (Exception ex)
            {
                OrderPageLogger.LogOrderPageException(ex);
            }

            List<string> europeanCountriesList = CountriesHelper.GetEUCountryCodes(countryList);
            string europeanCountries = europeanCountriesList.Aggregate(string.Empty, (current, country) => current + String.Format("{0} ", country));

            ViewData["EUCountries"] = europeanCountries.Trim();
            ViewData["CountryList"] = CountriesHelper.GetSupportedCountriesSelectList(countryList);

            PaymentMethod defaultPaymentMethod;
            IList<PaymentMethod> resellerPaymentMethods = ResellerHelper.GetResellerPaymentMethods(out defaultPaymentMethod);

            bool paymentEnabled = resellerPaymentMethods.Any(m => m.GuiPluginName == "CCPayment");
            bool orderByPostEnabled = resellerPaymentMethods.Any(m => m.GuiPluginName == "InvoiceByPost");
            bool orderByEmailEnabled = resellerPaymentMethods.Any(m => m.GuiPluginName == "InvoiceByEmail");
            bool payPalEnabled = resellerPaymentMethods.Any(m => m.GuiPluginName == "PayPal");
            bool payExRedirectEnabled = resellerPaymentMethods.Any(m => m.GuiPluginName == "PayexRedirect");
            bool worldPayRedirectEnabled = resellerPaymentMethods.Any(m => m.GuiPluginName == "WorldPayRedirect");
            bool dibsFlexwinEnabled = resellerPaymentMethods.Any(m => m.GuiPluginName == "DibsFlexwin");
            bool worldPayXmlRedirectEnabled = resellerPaymentMethods.Any(m => m.GuiPluginName == "WorldPayXmlRedirect");
            bool adyenHppEnabled = resellerPaymentMethods.Any(m => m.GuiPluginName == "AdyenHpp");

            ViewData["PaymentEnabled"] = paymentEnabled;
            ViewData["PayPalEnabled"] = payPalEnabled;
            ViewData["OrderByPostEnabled"] = orderByPostEnabled;
            ViewData["OrderByEmailEnabled"] = orderByEmailEnabled;
            ViewData["PayexRedirectEnabled"] = payExRedirectEnabled;
            ViewData["WorldPayRedirectEnabled"] = worldPayRedirectEnabled;
            ViewData["DibsFlexwinEnabled"] = dibsFlexwinEnabled;
            ViewData["WorldPayXmlRedirectEnabled"] = worldPayXmlRedirectEnabled;
            ViewData["AdyenHppEnabled"] = adyenHppEnabled;

            ViewData["firstOption"] = (bool)Session["firstOption"];

            ViewData["AddingSubdomain"] = false;
            if (this.Session["subdomain"] != null)
            {
                ViewData["AddingSubdomain"] = (bool)this.Session["subdomain"];
            }

            ViewData["OrderByPostId"] = orderByPostEnabled
                                            ? OrderModel.FetchPostOrderId(
                                                resellerId, null, Guid.Empty, currencyCode, countryCode)
                                            : string.Empty;

            // enabled payment method end
            ViewData["WasAnError"] = 0;

            string filterValue = Session["FilterByPackage"] != null ? (string)Session["FilterByPackage"] : null;

            ViewData["radioList"] = GeneralHelper.FilterPackages(
                this, service, Guid.Empty, resellerId, currencyCode, countryCode, filterValue);

            ViewData["ItemCategories"] = CustomerValidationHelper.GetItemCategories(resellerId);

            this.ViewData["OwnDomain"] = string.Empty;

            if (!((bool)this.Session["firstOption"]))
            {
                DomainDataFromXML singleDomain = (DomainDataFromXML)this.Session["singleDomain"];
                if (singleDomain != null)
                {
                    this.ViewData["Domain"] = singleDomain;
                    this.ViewData["OwnDomain"] = singleDomain.ProductName;
                }
            }

            // default values
            SubmitForm submitForm = new SubmitForm
            {
                RadioYouAre = "private",
                InvoiceRadioYouAre = "private",
                CountryCode = countryCode,
                InvoiceCountryCode = countryCode,
                DomainRegCountryCode = countryCode
            };

            try
            {
                submitForm.WhoisContact = this.HttpContext.Application["ShowWhoIs"].ToString().ToLower() == "true";
            }
            catch
            {
                submitForm.WhoisContact = false;
            }

            if (this.Session["resellerAccountData"] != null)
            {
                submitForm.RadioBillingContact = "reseller";
                submitForm.RadioTechContact = "reseller";
            }

            string defaultPaymentPlugin = string.Empty;
            if (orderByEmailEnabled && defaultPaymentMethod.GuiPluginName == "InvoiceByEmail")
            {
                defaultPaymentPlugin = "PayWithInvoice";
            }
            else if (orderByPostEnabled && defaultPaymentMethod.GuiPluginName == "InvoiceByPost")
            {
                defaultPaymentPlugin = "PayWithInvoice";
            }
            else if ((paymentEnabled && defaultPaymentMethod.GuiPluginName == "CCPayment")
                || (payExRedirectEnabled && defaultPaymentMethod.GuiPluginName == "PayexRedirect")
                || (worldPayRedirectEnabled && defaultPaymentMethod.GuiPluginName == "WorldPay")
                || (dibsFlexwinEnabled && defaultPaymentMethod.GuiPluginName == "DibsFlexwin")
                || (worldPayXmlRedirectEnabled && defaultPaymentMethod.GuiPluginName == "WorldPayXmlRedirect")
                || (adyenHppEnabled && defaultPaymentMethod.GuiPluginName == "AdyenHpp"))
            {
                defaultPaymentPlugin = defaultPaymentMethod.GuiPluginName;
            }
            else if (payPalEnabled && defaultPaymentMethod.GuiPluginName == "PayPal")
            {
                defaultPaymentPlugin = "PayPal";
            }

            this.ControllerContext.HttpContext.Application["DefaultPaymentPlugin"] = ViewData["DefaultPaymentPlugin"] = defaultPaymentPlugin;
            if (Session["SavedPaymentPlugin"] != null && !string.IsNullOrEmpty((string)Session["SavedPaymentPlugin"]))
            {
                ViewData["DefaultPaymentPlugin"] = Session["SavedPaymentPlugin"];
            }

            ViewData["RegDomainFront"] = RegularExpression.GetRegularExpression("DomainFront");
            ViewData["RegDomain"] = RegularExpression.GetRegularExpression("Domain");

            int allowedDomainLength;
            int numberOfDomainsAllowed;
            if (this.HttpContext.Application["DomainSearchAllowedDomainLength"] != null && (string)this.HttpContext.Application["DomainSearchAllowedDomainLength"] != String.Empty
                && this.HttpContext.Application["DomainSearchNumberOfDomainsAllowed"] != null && (string)this.HttpContext.Application["DomainSearchNumberOfDomainsAllowed"] != String.Empty)
            {
                allowedDomainLength = Int32.Parse((string)this.HttpContext.Application["DomainSearchAllowedDomainLength"]);
                numberOfDomainsAllowed = Int32.Parse((string)this.HttpContext.Application["DomainSearchNumberOfDomainsAllowed"]);
            }
            else
            {
                throw new ConfigurationErrorsException("Missing AllowedDomainLength or NumberOfDomainsAllowed in configuration");
            }

            ViewData["AllowedDomainLength"] = allowedDomainLength;
            ViewData["NumberOfDomainsAllowed"] = numberOfDomainsAllowed;

            Session["dontShowTaxesForThisResellerHidden"] = (!GeneralHelper.TaxAreShownForReseller(this)).ToString().ToLower();

            if (Session["SavedSubmitForm"] != null)
            {
                // Used saved submit form from and earlier request to re-fill. (E.g. return to form from canceled payment).
                submitForm = (SubmitForm)Session["SavedSubmitForm"];
            }

            ViewData["SeparateUsernameAndEmail"] = Atomia.Common.Configuration.AtomiaCommon.Instance.SeparateUsernameAndEmail;

            return View(submitForm);
        }