VAT number validator. This version contains validation for EU countries only. You can view the on-line help using this link https://firewallapi.asp-waf.com/?topic=html/T-Walter.Vat.EuropeanVatInformationQuery.htm and get some code samples to help you get started. This package exposes EuropeanVatInformationQuery class allowing you to query VAT data for the European Union as well as the UnitedKingdom. Please note that this package works best in combination with the Walter.Web.FireWall NuGet package allowing you to use GEO discovery to obtain the location of a request see https://www.nuget.org/packages/Walter.Web.FireWall/ for more information.
$ dotnet add package Walter.VatAllows you to query the VAT interface for the European union or the united kingdom
var vies = await Walter.Vat.EuropeanVatInformationQuery.GetAsync("LU12345678").ConfigureAwait(false);
You can do UK VAT validation (even after brexit) using UK as county code and the 9 or 12 number VAT ID
var vies = await Walter.Vat.EuropeanVatInformationQuery.GetAsync("UK123456789").ConfigureAwait(false);
You could integrate this in a controller using the Walter.Bom NuGet package testing if a country is in the EU
[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);
}
}
}