Esempio n. 1
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);
        }
Esempio n. 2
0
        internal virtual PersonInformation Map(checkVatResponse body)
        {
            if (body == null)
            {
                throw new ArgumentNullException(nameof(body));
            }

            var person = new PersonInformation
            {
                VatNumber = body.vatNumber,
                Country   = body.countryCode
            };

            if (CanMapName(body.name))
            {
                MapName(person, body.name);
            }

            if (CanMapAddress(body.address))
            {
                MapAddress(person, body.address);
            }

            return(person);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
 public ViesData(checkVatResponse r)
 {
     Valid       = r.valid;
     CountryCode = r.countryCode;
     VatNumber   = r.vatNumber;
     Name        = r.name;
     Address     = r.address;
 }
Esempio n. 5
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);
            }
        }
        internal virtual CompanyInformation Map(checkVatResponse body)
        {
            if (body == null)
            {
                throw new ArgumentNullException(nameof(body));
            }

            var companyInformation = new CompanyInformation
            {
                CompanyName = body.name,
                VatNumber   = body.vatNumber,
                Country     = body.countryCode
            };

            if (CanMapAddress(body.address))
            {
                MapAddress(companyInformation, body.address);
            }

            return(companyInformation);
        }
Esempio n. 7
0
 internal virtual bool CanMap(checkVatResponse body)
 {
     return(body != null && body.valid);
 }
Esempio n. 8
0
        private async void VCheckAsync()
        {
            Task <checkVatResponse> vatTask = _vatService.CheckVatAsync(cbVCountry.SelectedValue.ToString(), txtVNumber.Text);

            checkVatResponse vat = new checkVatResponse();

            try
            {
                vat = await vatTask;
                if (vat.Body.valid)
                {
                    StringBuilder msg = new StringBuilder();
                    msg.AppendLine("STATUS: AKTYWNY");
                    msg.AppendLine();
                    msg.AppendLine($"NAZWA: {vat.Body.name}");
                    msg.AppendLine();
                    msg.AppendLine($"ADRES: {vat.Body.address}");
                    MessageBox.Show(msg.ToString(), "Walidacja numeru Vat", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("STATUS: NIEAKTYWNY", "Walidacja numeru Vat", MessageBoxButtons.OK,
                                    MessageBoxIcon.Hand);
                }
            }
            catch (Exception ex)
            {
                if (ex.Message == "INVALID_INPUT")
                {
                    MessageBox.Show("Wartość pola Vat nie może być pusta", "Błąd", MessageBoxButtons.OK,
                                    MessageBoxIcon.Exclamation);
                }
                else if (ex.Message == "GLOBAL_MAX_CONCURRENT_REQ")
                {
                    MessageBox.Show("Maksymalna ilość konkurencyjnych zapytań została przekroczona. Spróbuj ponownie później", "Błąd", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
                else if (ex.Message == "MS_MAX_CONCURRENT_REQ")
                {
                    MessageBox.Show("Maksymalna ilość konkurencyjnych zapytań została przekroczona. Spróbuj ponownie później", "Błąd", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
                else if (ex.Message == "SERVICE_UNAVAILABLE")
                {
                    MessageBox.Show("Wystąpił błąd sieci lub serwera VIES. Spróbuj ponownie później", "Błąd", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
                else if (ex.Message == "MS_UNAVAILABLE")
                {
                    MessageBox.Show("Wystąpił błąd sieci lub serwera VIES. Spróbuj ponownie później", "Błąd", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
                else if (ex.Message == "TIMEOUT")
                {
                    MessageBox.Show("Oczekiwana odpowiedź nie została uzyskana w określonych ramach czasowych. Spróbuj ponownie później", "Błąd", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show("Wystąpił nieoczekiwany błąd aplikacji", "Błąd", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
            }
        }