EuropeanVatInformationQuery Class
The European Value Added Tax Information Query class allow you to query European VAT entries directly with the EU registrar.
Namespace:
Walter.VatAssembly: Walter.Vat (in Walter.Vat.dll)
Remarks
Examples
The bellow sample makes use of the County being of type GeoLocation. and uses that property to test if EU tax is applicable and if so validate if the VAT identifier is belonging to the company name provided.
This sample uses the location provided by the firewall framework using NuGet package Walter.Web.FireWall
This code is overly simplified but demonstrate how you could use this feature.
C#
[HttpPost] [ValidateAntiForgeryToken] public async Task<IActionResult> ProcessOrder(Order model) { if (!ModelState.IsValid) return View(model); if (model.Country.IsInTheEuropeanUnion()) { var vies = await Walter.Vat.EuropeanVatInformationQuery.GetAsync(model.VATNumber).ConfigureAwait(false); if (!vies.IsValid || !vies.CompanyName.Equals(model.CompanyName, StringComparison.OrdinalIgnoreCase)) { if (!vies.IsValid) { if (vies.Exception is null) { _logger?.Lazy().LogWarning(vies.Exception, "Query European VAT failed with a for {vat} in {country}", model.VATNumber, model.Country); } else { _logger?.Lazy().LogWarning(vies.Exception, "Query European VAT failed with a {exception} exception error {message}", vies.Exception.GetType().Name, vies.Exception.Message); } ModelState.AddModelError(nameof(model.VATNumber), "The VAT number is not valid"); } if (!vies.CompanyName.Equals(model.CompanyName, StringComparison.OrdinalIgnoreCase)) { ModelState.AddModelError(nameof(model.VATNumber), $"The VAT ID provided is belongs to another company than the one you specified, did you enter the wrong ID?"); if (vies.CompanyName.Contains(model.CompanyName, StringComparison.OrdinalIgnoreCase)) { ModelState.AddModelError(nameof(model.CompanyName), $"The VAT number provided is belongs to {vies.CompanyName}, this sounds like {model.CompanyName} but you should update it to avoid complications."); } else { ModelState.AddModelError(nameof(model.CompanyName), $"The VAT number provided is belongs to {vies.CompanyName} did you provide the wrong name?"); } } return View(model); } } }
See Also
[Walter.BOM.Geo.GeoLocationMapping]
[Walter.BOM.Geo.GeoLocationMapping.IsInEurope(GeoLocation)]
[Walter.BOM.Geo.GeoLocationMapping.IsInEasternEurope(GeoLocation)]
[Walter.BOM.Geo.GeoLocationMapping.IsInAfrica(GeoLocation)]
[Walter.BOM.Geo.GeoLocationMapping.IsInAsia(GeoLocation)]
[Walter.BOM.Geo.GeoLocationMapping.IsInLatinAmerica(GeoLocation)]
[Walter.BOM.Geo.GeoLocationMapping.IsInTheAmericas(GeoLocation)]
[Walter.BOM.Geo.GeoLocationMapping.TryGetValue(string, out GeoLocation)]