コード例 #1
0
    public static bool Check(string vatstring)
    {
        bool     result = false;
        string   vat, country;
        DateTime retDate;

        vatstring = vatstring.ToUpper();
        Regex rgx = new Regex("[^A-Z0-9]");

        vatstring = rgx.Replace(vatstring, string.Empty);
        if (IsValid(vatstring))
        {
            country = vatstring.Substring(0, 2);
            vat     = vatstring.Substring(2);
            checkVatService checker = new checkVatService();
            try
            {
                retDate = checker.checkVat(ref country, ref vat, out result, out retName, out retAddress);
            }
            catch
            {
                result = false;
            }
        }
        return(result);
    }
コード例 #2
0
ファイル: TaxService.cs プロジェクト: Adernal/DreamSale
        /// <summary>
        /// Performs a basic check of a VAT number for validity
        /// </summary>
        /// <param name="twoLetterIsoCode">Two letter ISO code of a country</param>
        /// <param name="vatNumber">VAT number</param>
        /// <param name="name">Company name</param>
        /// <param name="address">Address</param>
        /// <param name="exception">Exception</param>
        /// <returns>VAT number status</returns>
        public virtual VatNumberStatus DoVatCheck(string twoLetterIsoCode, string vatNumber,
                                                  out string name, out string address, out Exception exception)
        {
            name    = string.Empty;
            address = string.Empty;

            if (vatNumber == null)
            {
                vatNumber = string.Empty;
            }
            vatNumber = vatNumber.Trim().Replace(" ", "");

            if (twoLetterIsoCode == null)
            {
                twoLetterIsoCode = string.Empty;
            }
            if (!String.IsNullOrEmpty(twoLetterIsoCode))
            {
                //The service returns INVALID_INPUT for country codes that are not uppercase.
                twoLetterIsoCode = twoLetterIsoCode.ToUpper();
            }

            checkVatService s = null;

            try
            {
                bool valid;

                s = new checkVatService();
                s.checkVat(ref twoLetterIsoCode, ref vatNumber, out valid, out name, out address);
                exception = null;
                return(valid ? VatNumberStatus.Valid : VatNumberStatus.Invalid);
            }
            catch (Exception ex)
            {
                name      = address = string.Empty;
                exception = ex;
                return(VatNumberStatus.Unknown);
            }
            finally
            {
                if (name == null)
                {
                    name = string.Empty;
                }

                if (address == null)
                {
                    address = string.Empty;
                }

                if (s != null)
                {
                    s.Dispose();
                }
            }
        }
コード例 #3
0
        private bool Validate(string countryCode, string vatNumber)
        {
            string address;
            string name;
            bool   valid;

            _vatService.checkVat(ref countryCode, ref vatNumber, out valid, out name, out address);

            return(valid);
        }
コード例 #4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        var    svc         = new checkVatService();
        var    countryCode = Request.QueryString["Country"];
        var    vatNumber   = Request.QueryString["VAT"];
        string name;
        string address;
        bool   valid;

        svc.checkVat(ref countryCode, ref vatNumber, out valid, out name, out address);
        var data   = new { name, address };
        var output = JsonConvert.SerializeObject(data);

        Response.Write(output);
    }
コード例 #5
0
        /// <summary>Perform the validation</summary>
        /// <param name="country">One of Country codes, included in the supportedCountries array</param>
        /// <param name="vatId">The VAT ID to validate</param>
        /// <returns>Vies Object with attributs fullfiled</returns>
        public Vies Validate(string country, string vatId)
        {
            if (Array.IndexOf(this.supportedCountries, country) < 0)
            {
                throw new Exception("Country " + country + " is not supported");
            }
            else
            {
                this.country = country;
            }

            this.vatId = vatId;
            checkSercive.checkVat(ref this.country, ref this.vatId, out this.valid, out this.name, out this.address);
            return(this);
        }
コード例 #6
0
        /// <summary>
        /// Check if the VAT number is valid or not
        /// </summary>
        /// <returns>True if the VAT number could be validated otherwise false</returns>
        public bool CheckVat()
        {
            if (string.IsNullOrEmpty(VATNumber) || string.IsNullOrEmpty(CountryCode))
            {
                return(false);
            }

            //If the country code is AT for Austria we need a U before the UID
            if (CountryCode.ToUpper().Equals("AT"))
            {
                if (!VATNumber.StartsWith("U"))
                {
                    VATNumber = "U" + VATNumber;
                }
            }

            string strVat     = VATNumber;
            string strCountry = CountryCode;

            bool   bValid     = false;
            string strName    = string.Empty;
            string strAddress = string.Empty;

            try
            {
                checkVatService visService = new checkVatService();

                RetDate = visService.checkVat(ref strCountry, ref strVat,
                                              out bValid, out strName, out strAddress);

                IsValid = bValid;
                Name    = strName;
                Address = strAddress;

                return(IsValid);
            }
            catch (Exception err)
            {
                System.Diagnostics.Trace.TraceError(err.ToString());
                return(false);
            }
        }
コード例 #7
0
        /// <summary>
        ///     Check if the VAT number is valid or not
        /// </summary>
        /// <returns>True if the VAT number could be validated otherwise false</returns>
        public bool CheckVat()
        {
            if (string.IsNullOrEmpty(VATNumber) || string.IsNullOrEmpty(CountryCode))
            {
                Log.Instance.LogDebug("CheckVat() FALSE: string.IsNullOrEmpty(VATNumber) || string.IsNullOrEmpty(CountryCode)");
                return(false);
            }

            //If the country code is AT for Austria we need a U before the UID
            if (CountryCode.ToUpper().Equals("AT"))
            {
                if (!VATNumber.StartsWith("U"))
                {
                    VATNumber = "U" + VATNumber;
                }
            }

            string strVat     = VATNumber;
            string strCountry = CountryCode;

            try
            {
                var visService = new checkVatService();

                bool   bValid;
                string strName;
                string strAddress;
                RetDate = visService.checkVat(ref strCountry, ref strVat, out bValid, out strName, out strAddress);
                IsValid = bValid;
                Name    = strName;
                Address = strAddress;

                Log.Instance.LogDebug("CheckVat() IsValid: " + IsValid);
                return(IsValid);
            }
            catch (Exception err)
            {
                Trace.TraceError(err.ToString());
                Log.Instance.LogDebug("CheckVat() FALSE: EXCEPTION");
                return(false);
            }
        }
コード例 #8
0
		/// <summary>
		///     Check if the VAT number is valid or not
		/// </summary>
		/// <returns>True if the VAT number could be validated otherwise false</returns>
		public bool CheckVat()
		{
			if (string.IsNullOrEmpty(VATNumber) || string.IsNullOrEmpty(CountryCode))
			{
				Log.Instance.LogDebug("CheckVat() FALSE: string.IsNullOrEmpty(VATNumber) || string.IsNullOrEmpty(CountryCode)");
				return (false);
			}

			//If the country code is AT for Austria we need a U before the UID
			if (CountryCode.ToUpper().Equals("AT"))
			{
				if (!VATNumber.StartsWith("U"))
					VATNumber = "U" + VATNumber;
			}

			string strVat = VATNumber;
			string strCountry = CountryCode;

			try
			{
				var visService = new checkVatService();

				bool bValid;
				string strName;
				string strAddress;
				RetDate = visService.checkVat(ref strCountry, ref strVat, out bValid, out strName, out strAddress);
				IsValid = bValid;
				Name = strName;
				Address = strAddress;

				Log.Instance.LogDebug("CheckVat() IsValid: " + IsValid);
				return (IsValid);
			}
			catch (Exception err)
			{
				Trace.TraceError(err.ToString());
				Log.Instance.LogDebug("CheckVat() FALSE: EXCEPTION");
				return (false);
			}
		}
コード例 #9
0
        public bool CheckVat()
        {
            int retSession = GetSessionId();

            if (retSession == 0)
            {
                if (string.IsNullOrEmpty(VATNumber) || string.IsNullOrEmpty(CountryCode))
                {
                    return(false);
                }

                string strVat     = CountryCode + VATNumber;
                string strCountry = CountryCode;

                string strName     = string.Empty;
                string strAddress1 = string.Empty;
                string strAddress2 = string.Empty;
                string strAddress3 = string.Empty;
                string strAddress4 = string.Empty;
                string strAddress5 = string.Empty;
                string strAddress6 = string.Empty;
                string strReturn   = string.Empty;

                int      ReturnCodeLoc = 0;
                string   ReturnMsgLoc  = string.Empty;
                string[] stuff;
                VatService = "Finanz Online";
                try
                {
                    uidAbfrageService uidAbfrageService = new uidAbfrageService();
                    ReturnCodeLoc = uidAbfrageService.uidAbfrage(Memberid, UserId, SessionId, ProducerVatNum, strVat, uidAbfrageServiceRequestStufe.Item2, out ReturnMsgLoc, out strName, out strAddress1, out strAddress2, out strAddress3, out strAddress4, out strAddress5, out strAddress6);
                    stuff         = new string[] { strAddress1, strAddress2, strAddress3, strAddress4, strAddress5, strAddress6 };
                    stuff         = stuff.Where(x => !string.IsNullOrEmpty(x)).ToArray();
                    Address       = string.Join("\n", stuff);
                    Name          = strName;
                    //MessageBox.Show(text: Name);
                    //MessageBox.Show(text: Address);
                    //MessageBox.Show(text: strReturn);
                    //MessageBox.Show(text: strAddress1 + '\n\r' + strAddress1);
                    if (ReturnCodeLoc != 0)
                    {
                        ReturnCode = ReturnCodeLoc;
                        ReturnMsg  = ReturnMsgLoc;
                        //MessageBox.Show(text: ReturnMsgLoc);
                        //MessageBox.Show(text: ReturnCodeLoc.ToString());
                    }
                    else
                    {
                        IsValid    = true;
                        ReturnCode = ReturnCodeLoc;
                        ReturnMsg  = ReturnMsgLoc;
                    }
                    logout();
                    return(IsValid);
                }
                catch (Exception err)
                {
                    System.Diagnostics.Trace.TraceError(err.ToString());
                    return(false);
                }
            }
            else
            {
                string strVat     = VATNumber;
                string strCountry = CountryCode;

                bool   bValid     = false;
                string strName    = string.Empty;
                string strAddress = string.Empty;
                VatService = "EU VIES";
                try
                {
                    checkVatService visService = new checkVatService();

                    RetDate = visService.checkVat(ref strCountry, ref strVat,
                                                  out bValid, out strName, out strAddress);
                    IsValid = bValid;
                    Name    = strName;
                    Address = strAddress;
                    if (IsValid)
                    {
                        ReturnCode = 0;
                        ReturnMsg  = "Die UID des Erwerbers ist gültig";
                    }
                    else
                    {
                        ReturnCode = -1;
                        ReturnMsg  = "Die UID-Nummer des Erwerbers ist falsch";
                    }

                    return(IsValid);
                }
                catch (Exception err)
                {
                    System.Diagnostics.Trace.TraceError(err.ToString());
                    ReturnCode = -1;
                    ReturnMsg  = err.ToString();
                    return(false);
                }
            }
        }