Пример #1
0
        public async Task <VatResponseItem> CheckOnline(string vatin, string requestingVatin)
        {
            #region CHECKING FOR ERROR

            if (!IsValidChecksum(vatin))
            {
                return(new VatResponseItem());
            }

            #endregion CHECKING FOR ERROR

            using (var client = new checkVatPortTypeClient())
            {
                var channel = client.ChannelFactory.CreateChannel();

                var response = await channel.checkVatAsync(new checkVatRequest
                {
                    countryCode = vatin.Substring(0, 2),
                    vatNumber   = vatin.Substring(2)
                });

                if (response is not null && response.valid)
                {
                    return(new VatResponseItem(new ValidVatResponseItem(
                                                   response.countryCode,
                                                   response.vatNumber,
                                                   response.requestDate,
                                                   response.name,
                                                   response.address
                                                   )));
                }
            }

            return(new VatResponseItem());
        }
Пример #2
0
        public static async Task <bool> CheckVAT()
        {
            var countryCode = "PL";
            var vatNumber   = "8512389324";

            try
            {
                checkVatPortType client          = new checkVatPortTypeClient(checkVatPortTypeClient.EndpointConfiguration.checkVatPort, "http://ec.europa.eu/taxation_customs/vies/services/checkVatService");
                checkVatRequest  checkVatRequest = new checkVatRequest {
                    countryCode = countryCode, vatNumber = vatNumber
                };

                var sw = Stopwatch.StartNew();
                checkVatResponse response = await client.checkVatAsync(checkVatRequest);

                sw.Stop();
                Console.WriteLine("Time elapsed: {0}", sw.Elapsed);

                Console.WriteLine(response.valid);
                Console.WriteLine(response.name);
                Console.WriteLine(response.address);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
            return(true);
        }
Пример #3
0
 public VIESResponse CheckVATNumber(string countryCode, string vatNumber)
 {
     var vClient = new checkVatPortTypeClient();
     var isValid = false;
     try
     {
         string name;
         string address;
         vClient.checkVat(ref countryCode, ref vatNumber, out isValid, out name, out address);
         return new VIESResponse
         {
             IsValid = isValid,
             Name = name,
             Address = address,
             CountryCode = countryCode,
             VATNumber = vatNumber
         };
     }
     catch (Exception ex)
     {
         Debug.WriteLine($"VIES threw an exception {ex.Message}");
         return new VIESResponse
         {
             IsValid = isValid,
             CountryCode = countryCode,
             VATNumber = vatNumber
         };
     }
 }
Пример #4
0
        public async Task <IViesResult> CheckVatAsync(string countryCode, string vatNumber)
        {
            if (string.IsNullOrEmpty(countryCode))
            {
                var err = new Exception("country code should not be null or empty");
                return(new ViesResult(err));
            }
            if (string.IsNullOrEmpty(vatNumber))
            {
                var err = new Exception("vat number should not be null or empty");
                return(new ViesResult(err));
            }
            vatNumber = vatNumber
                        .Replace(" ", "")
                        .Replace(".", "")
                        .Replace("-", "");

            var request = new checkVatRequest(countryCode, vatNumber);

            try
            {
                var vs = new checkVatPortTypeClient();
                var vr = await vs.checkVatAsync(request);

                var vd = new ViesData(vr);
                return(new ViesResult(vd));
            }
            catch (Exception e)
            {
                return(new ViesResult(e));
            }
        }
Пример #5
0
 private void CheckVat()
 {
     try
     {
         string countryCode           = krajSkrot.Text.ToString();
         string vatNumber             = textBox1.Text;
         checkVatPortTypeClient check = new checkVatPortTypeClient();
         check.checkVat(ref countryCode, ref vatNumber, out valid, out name, out address);
         if (valid == true)
         {
             MessageBox.Show(valid.ToString());
             MessageBox.Show(name);
             MessageBox.Show(address);
             labelValid.Text  = valid.ToString();
             labelName.Text   = name;
             labelAdress.Text = address;
         }
         else
         {
             MessageBox.Show("Podany numer VAT nie istnieje");
         }
     }
     catch (InvalidOperationException error)
     {
         MessageBox.Show(error.Message);
     }
 }
Пример #6
0
        public static CheckVatResult CheckVat(string cc, string vatNum)
        {
            var client = new checkVatPortTypeClient();

            client.checkVat(ref cc, ref vatNum, out bool valid, out string name, out string address);
            return(new CheckVatResult(cc, vatNum, valid, name, address));
        }
Пример #7
0
        public VIESResponse CheckVATNumber(string countryCode, string vatNumber)
        {
            var vClient = new checkVatPortTypeClient();
            var isValid = false;

            try
            {
                string name;
                string address;
                vClient.checkVat(ref countryCode, ref vatNumber, out isValid, out name, out address);
                return(new VIESResponse
                {
                    IsValid = isValid,
                    Name = name,
                    Address = address,
                    CountryCode = countryCode,
                    VATNumber = vatNumber
                });
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"VIES threw an exception {ex.Message}");
                return(new VIESResponse
                {
                    IsValid = isValid,
                    CountryCode = countryCode,
                    VATNumber = vatNumber
                });
            }
        }
Пример #8
0
        public ActionResult Vat()
        {
            checkVatPortTypeClient vat = new checkVatPortTypeClient();
            var model        = new List <VatViewModel>();
            var searchedVats = this.db.Vats.OrderByDescending(x => x.Id)
                               .Select(v => v.VatNumber)
                               .ToList();

            foreach (var searchedVat in searchedVats)
            {
                bool   valid;
                string name;
                string address;
                string countryCode = searchedVat.Substring(0, 2);
                string vatNumber   = searchedVat.Substring(2);

                var a        = vat.checkVat(ref countryCode, ref vatNumber, out valid, out name, out address);
                var checkVat = new VatViewModel
                {
                    IsValid = valid,
                    Name    = name,
                    Address = address
                };
                model.Add(checkVat);
            }
            return(View("Vat", model: model));
        }
Пример #9
0
        public async Task <checkVatApproxResponse> CheckVatApproxAsync(string country, string vat, string countryReq, string vatReq)
        {
            checkVatApproxRequest approxRequest = new checkVatApproxRequest()
            {
                Body = new checkVatApproxRequestBody()
                {
                    countryCode          = country,
                    vatNumber            = vat,
                    requesterCountryCode = countryReq,
                    requesterVatNumber   = vatReq,
                    traderCity           = "",
                    traderCompanyType    = "",
                    traderName           = "",
                    traderPostcode       = "",
                    traderStreet         = ""
                }
            };

            checkVatApproxResponse approxResponse = new checkVatApproxResponse();

            using (ServiceReference1.checkVatPortTypeClient client = new checkVatPortTypeClient())
            {
                approxResponse = await client.checkVatApproxAsync(approxRequest.Body.countryCode,
                                                                  approxRequest.Body.vatNumber, approxRequest.Body.traderName, approxRequest.Body.traderCompanyType, approxRequest.Body.traderStreet,
                                                                  approxRequest.Body.traderPostcode, approxRequest.Body.traderCity, approxRequest.Body.requesterCountryCode, approxRequest.Body.requesterVatNumber);

                return(approxResponse);
            }
        }
Пример #10
0
        public CheckVat CheckVat(string countryCode, string vatNumber)
        {
            try
            {
                var checkVatRequest = new checkVatRequest {
                    countryCode = countryCode, vatNumber = vatNumber
                };
                var checkVatPortTypeClient        = new checkVatPortTypeClient();
                checkVatResponse checkVatResponse = checkVatPortTypeClient.checkVat(checkVatRequest);
                if (null != checkVatResponse)
                {
                    var xmlSerializer = new XmlSerializer(checkVatResponse.GetType());
                    var textWriter    = new StringWriter();
                    xmlSerializer.Serialize(textWriter, checkVatResponse);
                    CheckVat checkVat = XmlHelper.DeserializeXmlFromString <CheckVat>(textWriter.ToString());
                    return(checkVat);
                }
            }
            catch (Exception e)
            {
                _log4Net.Error(e.Message, e);
                if (null != e.InnerException)
                {
                    _log4Net.Error(e.InnerException.Message, e.InnerException);
                }
            }

            return(null);
        }
Пример #11
0
        public ActionResult _Index(int?id)
        {
            checkVatPortTypeClient client = new checkVatPortTypeClient();
            Vat vat;
            CompanyBindingModel companyDetails = new CompanyBindingModel();

            using (InnovasysVatContext context = new InnovasysVatContext())
            {
                vat = context.Vats.FirstOrDefault(v => v.Id == id);
            }

            if (vat != null)
            {
                string countryCode = vat.VatNumber.Substring(0, 2);
                string vatNumber   = vat.VatNumber.Substring(2, vat.VatNumber.Length - 2).TrimEnd();
                client.checkVat(ref countryCode, ref vatNumber, out var isValid, out var name, out var address);
                companyDetails.VatNumber   = vatNumber;
                companyDetails.CountryCode = countryCode;
                companyDetails.Address     = address;
                companyDetails.Name        = name;
                companyDetails.IsValid     = isValid;
            }

            client.Close();

            return(PartialView(companyDetails));
        }
Пример #12
0
        public static ApproxResult CheckVatApprox(string countryCode, string vatNumber, string traderName, string traderCompanyType,
                                                  string traderStreet, string traderPostcode, string traderCity, string requesterCountryCode, string requesterVatNumber, bool valid)
        {
            matchCode traderNameMatch;
            matchCode traderCompanyTypeMatch;
            matchCode traderStreetMatch;
            matchCode traderPostcodeMatch;
            matchCode traderCityMatch;

            var connection = new checkVatPortTypeClient();

            connection.checkVatApprox(ref countryCode, ref vatNumber, ref traderName, ref traderCompanyType, ref traderStreet, ref traderPostcode,
                                      ref traderCity, requesterCountryCode, requesterVatNumber, out valid, out string traderAddress, out traderNameMatch, out traderCompanyTypeMatch,
                                      out traderStreetMatch, out traderPostcodeMatch, out traderCityMatch, out string requestIdentifier);

            return(new ApproxResult(valid, traderAddress, traderNameMatch, traderCompanyTypeMatch, traderStreetMatch, traderPostcodeMatch, traderCityMatch, requestIdentifier));
        }
Пример #13
0
        public async Task <checkVatResponse> CheckVatAsync(string country, string vat)
        {
            checkVatRequest vatRequest = new checkVatRequest()
            {
                Body = new checkVatRequestBody()
                {
                    countryCode = country,
                    vatNumber   = vat
                }
            };

            checkVatResponse vatResponse = new checkVatResponse();

            using (ServiceReference1.checkVatPortTypeClient client = new checkVatPortTypeClient())
            {
                vatResponse = await client.checkVatAsync(vatRequest.Body.countryCode, vatRequest.Body.vatNumber);

                return(vatResponse);
            }
        }
Пример #14
0
        private void CheckVatApprox()
        {
            try
            {
                string countryCode          = krajSkrot.Text.ToString();
                string vatNumber            = textBox1.Text;
                string requesterCountryCode = countryCode;
                string requesterVatNumber   = vatNumber;

                checkVatPortTypeClient check = new checkVatPortTypeClient();
                check.checkVatApprox(ref countryCode, ref vatNumber, ref traderName, ref traderCompanyType, ref traderStreet, ref traderPostcode, ref traderCity, requesterCountryCode, requesterVatNumber, out valid, out traderAddress, out matchCode traderNameMatch, out matchCode traderCompanyTypeMatch, out matchCode traderStreetMatch, out matchCode traderPostcodeMatch, out matchCode traderCityMatch, out requestIdentifier);
                labelID.Text   = requestIdentifier.ToString();
                labelData.Text = DateTime.Now.ToString();
                labelPanstwoCzlonkowskie.Text = countryCode;
                labelNumer.Text = vatNumber;
            }
            catch (InvalidOperationException error)
            {
                MessageBox.Show(error.Message);
            }
        }
Пример #15
0
        public CheckVatApprox CheckVatApprox(string countryCode, string vatNumber, string requesterCountryCode = null,
                                             string requesterVatNumber = null)
        {
            try
            {
                var checkVatApproxRequest = new checkVatApproxRequest
                {
                    countryCode          = countryCode,
                    vatNumber            = vatNumber,
                    requesterCountryCode = countryCode,
                    requesterVatNumber   = vatNumber
                };
                var checkVatPortTypeClient = new checkVatPortTypeClient();
                checkVatApproxResponse checkVatApproxResponse =
                    checkVatPortTypeClient.checkVatApprox(checkVatApproxRequest);
                if (null != checkVatApproxResponse)
                {
                    var xmlSerializer = new XmlSerializer(checkVatApproxResponse.GetType());
                    var textWriter    = new StringWriter();
                    xmlSerializer.Serialize(textWriter, checkVatApproxResponse);
                    CheckVatApprox checkVatApprox =
                        XmlHelper.DeserializeXmlFromString <CheckVatApprox>(textWriter.ToString());
//#if DEBUG
//                    _log4Net.Debug(JsonConvert.SerializeObject(checkVatApprox));
//                    _log4Net.Debug(JsonConvert.SerializeObject(checkVatApproxResponse));
//#endif
                    return(checkVatApprox);
                }
            }
            catch (Exception e)
            {
                _log4Net.Error(e.Message, e);
                if (null != e.InnerException)
                {
                    _log4Net.Error(e.InnerException.Message, e.InnerException);
                }
            }

            return(null);
        }
Пример #16
0
 public VIESConnector()
 {
     _client = new checkVatPortTypeClient();
 }