/// <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(" ", string.Empty); 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(); } try { var s = new EuropaCheckVatService.checkVatPortTypeClient(); var task = s.checkVatAsync(new EuropaCheckVatService.checkVatRequest { vatNumber = vatNumber, countryCode = twoLetterIsoCode }); task.Wait(); var result = task.Result; var valid = result.valid; name = result.name; address = result.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; } } }
/// <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(); } EuropaCheckVatService.checkVatPortTypeClient s = null; try { bool valid; s = new EuropaCheckVatService.checkVatPortTypeClient(); 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.Close(); } } }
DoVatCheck(string twoLetterIsoCode, string vatNumber) { var name = string.Empty; var 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(); } EuropaCheckVatService.checkVatPortTypeClient s = null; try { s = new EuropaCheckVatService.checkVatPortTypeClient(); var result = await s.checkVatAsync(new EuropaCheckVatService.checkVatRequest { vatNumber = vatNumber, countryCode = twoLetterIsoCode }); var valid = result.valid; name = result.name; address = result.address; return(valid ? VatNumberStatus.Valid : VatNumberStatus.Invalid, name, address, null); } catch (Exception ex) { return(VatNumberStatus.Unknown, string.Empty, string.Empty, ex); } finally { if (name == null) { name = string.Empty; } if (address == null) { address = string.Empty; } } }
/// <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> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the vAT number status. Company name. Address. Exception /// </returns> protected virtual async Task <(VatNumberStatus vatNumberStatus, string name, string address, Exception exception)> DoVatCheckAsync(string twoLetterIsoCode, string vatNumber) { if (vatNumber == null) { vatNumber = string.Empty; } vatNumber = vatNumber.Trim().Replace(" ", string.Empty); 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(); } string name; string address; try { var s = new EuropaCheckVatService.checkVatPortTypeClient(); var result = await s.checkVatAsync(new EuropaCheckVatService.checkVatRequest { vatNumber = vatNumber, countryCode = twoLetterIsoCode }); var valid = result.valid; name = result.name; address = result.address; return(valid ? VatNumberStatus.Valid : VatNumberStatus.Invalid, name, address, null); } catch (Exception ex) { name = address = string.Empty; var exception = ex; return(VatNumberStatus.Unknown, name, address, exception); } }