コード例 #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
    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);
    }
コード例 #4
0
        static void Main(string[] args)
        {
            // VS 2017
            // add service reference -> button "Advanced" -> button "Add Web Reference" ->
            // URL = http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl

            string Landcode  = "NL";
            string BTWNummer = "820471616B01";     // VAT nr BOL.COM

            checkVatService test = new checkVatService();

            test.checkVat(ref Landcode, ref BTWNummer, out bool GeldigBTWNr, out string Naam, out string Adres);

            Console.WriteLine(Landcode + BTWNummer + " " + GeldigBTWNr);
            Console.WriteLine(Naam + Adres);
            Console.ReadKey();
        }
コード例 #5
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);
            }
        }
コード例 #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))
            {
                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);
            }
        }
コード例 #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
        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);
                }
            }
        }
コード例 #9
0
        public ViesCompanyInfo GetCompany(string vatNumber, string askingVatNumber, out bool isValid, out string requestIdentifier)
        {
            vatNumber = NormalizeVatNumber(vatNumber);

            using (var client = new checkVatService())
            {
                string countryCode = vatNumber.Substring(0, 2);
                vatNumber = vatNumber.Substring(2, vatNumber.Length - 2);

                string traderName           = string.Empty;
                string traderCompanyType    = string.Empty;
                string traderStreet         = string.Empty;
                string traderPostcode       = string.Empty;
                string traderCity           = string.Empty;
                string requesterCountryCode = string.Empty;
                string requesterVatNumber   = string.Empty;

                if (askingVatNumber != null)
                {
                    requesterCountryCode = askingVatNumber.Substring(0, 2);
                    requesterVatNumber   = askingVatNumber.Substring(2, vatNumber.Length - 2);
                }

                bool      valid;
                string    traderAddress;
                matchCode traderNameMatch;
                bool      traderNameMatchSpecified;
                matchCode traderCompanyTypeMatch;
                bool      traderCompanyTypeMatchSpecified;
                matchCode traderStreetMatch;
                bool      traderStreetMatchSpecified;
                matchCode traderPostcodeMatch;
                bool      traderPostcodeMatchSpecified;
                matchCode traderCityMatch;
                bool      traderCityMatchSpecified;
                //string requestIdentifier;

                var result = client.checkVatApprox(
                    ref countryCode,
                    ref vatNumber,
                    ref traderName,
                    ref traderCompanyType,
                    ref traderStreet,
                    ref traderPostcode,
                    ref traderCity,
                    requesterCountryCode,
                    requesterVatNumber,
                    out valid,
                    out traderAddress,
                    out traderNameMatch,
                    out traderNameMatchSpecified,
                    out traderCompanyTypeMatch,
                    out traderCompanyTypeMatchSpecified,
                    out traderStreetMatch,
                    out traderStreetMatchSpecified,
                    out traderPostcodeMatch,
                    out traderPostcodeMatchSpecified,
                    out traderCityMatch,
                    out traderCityMatchSpecified,
                    out requestIdentifier);

                isValid = valid;

                return(new ViesCompanyInfo
                {
                    Name = traderName,
                    VatNumber = vatNumber,
                    Address = traderAddress,
                    CountryCode = countryCode
                });
            }
        }
コード例 #10
0
 public VatValidator()
 {
     _vatService = new checkVatService();
 }