private PublicOrder CreateBasicOrder()
        {
            string country             = this.countryProvider.GetDefaultCountry().Code;
            var    vatValidationResult = vatNumberValidator.ValidateCustomerVatNumber();
            var    vatNumber           = string.Empty;


            if (vatValidationResult != null && vatValidationResult.Valid)
            {
                vatNumber = vatValidationResult.VatNumber;
                country   = vatValidationResult.CountryCode;
            }
            else if (this.contactDataProvider != null)
            {
                var allContacts = this.contactDataProvider.GetContactData();
                IEnumerable <ContactData> contacts = allContacts?.GetContactData();
                if (contacts != null)
                {
                    ContactData contactData = contacts.FirstOrDefault(c => c.Id == "BillingContact" && !string.IsNullOrEmpty(c.Country))
                                              ?? contacts.FirstOrDefault(c => c.Id == "MainContact" && !string.IsNullOrEmpty(c.Country));
                    if (!string.IsNullOrEmpty(contactData?.Country))
                    {
                        country = contactData.Country;
                    }
                }
            }

            return(new PublicOrder
            {
                ResellerId = resellerProvider.GetReseller().Id,
                Country = country,
                Currency = currencyPreferenceProvider.GetCurrentCurrency().Code,
                LegalNumber = vatNumber
            });
        }
Beispiel #2
0
        public ActionResult ValidateVatNumber(string vatNumber)
        {
            if (!string.IsNullOrEmpty(vatNumber))
            {
                vatDataProvider.VatNumber = vatNumber;
            }

            var result = vatValidator.ValidateCustomerVatNumber();

            return(JsonEnvelope.Success(result));
        }
        /// <summary>
        /// Remove invalid VAT number from order.
        /// </summary>
        public override PublicOrder AmendOrder(PublicOrder order, PublicOrderContext orderContext)
        {
            if (!string.IsNullOrEmpty(order.LegalNumber))
            {
                var validationResult = vatNumberValidator.ValidateCustomerVatNumber();

                if (!validationResult.Valid)
                {
                    order.LegalNumber = String.Empty;
                }
            }

            return(order);
        }