Bonchev Information Technologies and Systems
Software for organizations and people.
How to Use the VAT Registration Number Validator Hi guest
Sign up - Login
VAT Registration Number Validator Home How to Use Download Reference Manual License Awards & Reviews  
VAT Registration Number Validator Icon
Using the software is straightforward. Copy the VAT-Validator DLL appropriate for your web server into the Bin folder of your website, or alternatively copy the "VAT-Validator.cs" file into its App_Code folder. Then you can start using the software immediately as shown in the example below.
Let the ddlECCountry and ddlResponseLanguage be two drop-down lists, populated with items to represent respective European Union Member Countries and Languages. Since in the example below we will use the values of the selected list-items directly in function calls, it is important that they are populated with valid European Union Member Country and Language Codes, which are available in the VAT Registration Number Validator Reference Manual. Alternatively these drop-lists can also be dynamically populated using:

public static string[] VATValidator.GetMemberStates(); and
public static string[] VATValidator.GetLanguages();

We will also assume that textVATNumber is a text box in which the visitor will enter their VAT number, and that the checkObtainReference is a check box which is used to indicate whether a Consultation Reference Number is required or not. We will place the overall validation result in the LabelVATValidationStatus label field, and the obtained registrant data in two strings AllItemsData and AllKnownItemsData.

Then an eCommerce website using the VAT Registration Number Validator can use similar code to obtain the details of a VAT number.
using MBBSoftware;


[some code to ensure that there is a valid selection in ddlECCountry]
[some code to ensure that there is a text (VAT number) entered in the textVATNumber]
[some code to ensure that there is a valid selection in ddlResponseLanguage]


// Dictionary which will be used to contain the VIES data for the queried VAT number.
Dictionary< VATValidator.DataItem, string > dictVATNumber = new Dictionary< VATValidator.DataItem, string >();


// Get the selected state and language in separate variables for example clarity. Note that both
// GetMemberState( param ) and GetLanguage( param ) throw exceptions when invalid arguments are supplied.
VATValidator.MemberState state    = VATValidator.GetMemberState( ddlECCountry.SelectedValue );
VATValidator.Language    language = VATValidator.GetLanguage( ddlResponseLanguage.SelectedValue );


// Variables for the results and any possible warnings that need to be sent to the webmaster.
string AllItemsData = "";
string AllKnownItemsData = "";
string WebMasterMessage = "";


try
{
   // Now create a VAT validator instance which will be used to acquire the data. Use the default 
   // constructor if you do not require a Consultation reference number. Use the parameters overload 
   // constructor to supply your own VAT number as parameterized if you require a Consultation reference number.
   VATValidator validatorVAT = checkObtainReference.Checked ? 
                             new VATValidator( VATValidator.MemberState.UnitedKingdom, "YourVATNnumber" ) : 
                             new VATValidator();


   if( validatorVAT.IsValidVAT( state, textVATNumber.Text, language, ref dictVATNumber, ref WebMasterMessage ) )
   {
      // Valid VAT Number.
      LabelVATValidationStatus.Text = dictVATNumber[VATValidator.DataItem.Status];


      // Example: build a html string for all VAT validation data items.
      foreach( VATValidator.DataItem dataFileld in VATValidator.GetAllItems() )
      {
         AllItemsData += string.Format( "{0}: {1}<br />", 
                                        VATValidator.GetItemName( dataFileld, VATValidator.Language.English ),
                                        dictVATNumber.ContainsKey( dataFileld ) ? 
                                                      dictVATNumber[dataFileld] : 
                                                      "[VAT-Validator: No Available Data]" );
      }


      // Example: build a html string only for the data items delivered through the request.
      foreach( KeyValuePair< VATValidator.DataItem, string > dataFileld in dictVATNumber )
      {
         // Ignore any empty or containing only "-" data items.
         if( !string.IsNullOrEmpty( dataFileld.Value.Trim( '-' ).Trim() ) )
         {
            AllKnownItemsData += string.Format( "{0}: {1}<br />",
                                        VATValidator.GetItemName( dataFileld.Key, VATValidator.Language.English ),
                                        dataFileld.Value );
         }
      }
   }
   else
   {
      // Invalid/Unconfirmed VAT Number. This message can be either "No, ..." for invalid VAT number or
      // ["Explanation what went wrong & why the VAT number could not be confirmed."]; use the coma as an indicator.
      LabelVATValidationStatus.Text = -1 != dictVATNumber[VATValidator.DataItem.Status].Substring(0,5).IndexOf(',') ?
                                            dictVATNumber[VATValidator.DataItem.Status] : 
                                            ("The entered VAT number could not be validated. Response: " + 
                                             dictVATNumber[VATValidator.DataItem.Status]);
   }
}
catch( Exception ex )
{
   LabelVATValidationStatus.Text = 
          "The following exception occurred while trying to obtain the requested VAT registration data: " + ex.Message;
}


if( !string.IsNullOrEmpty( WebMasterMessage ) )
{
   // There is a warning message from the VAT Registration Number Validator. Send an email to the webmaster.
   SendWarningNotification( "Warning from the VAT Registration Number Validator - [function name]", 
                           string.Format( "Warning from the VAT-Validation assembly. Message: {0}",
                                          WebMasterMessage ) );
}
The use of the VAT Validator class is simple and straightforward. First create an instance of the VAT Validator object and then execute the IsValidVAT( parameters ) method on that object. The return value of this call is either true or false depending on the circumstances. The registrant information is returned via a key-value dictionary which can be queried for any particular data item. Any administrative messages from the software to the webmaster are propagated through the WebMasterMessage ref parameter string. It is important to envelop the IsValidVAT( parameters ) function call in a try-catch block(s) as this method throws exceptions in cases when there are unrecoverable errors. Note that WebMasterMessage may contain a message to the webmaster even regardless of whether IsValidVAT( parameters ) has thrown an exception or not. The types of the thrown exceptions are documented in the VAT Registration Number Validator Reference Manual.
Reference Manual Download Now
Community Content
(To enter your comments you must be signed in. Log in or create FREE account.)
MemberComments
Be the first to comment.
Products
The ELIAS Project
Fine Art App
Information Presenter
Act On File
Audio Control
Photo Window
Information Presenter
Homepage
for Museums and Art galleries
for Schools and Universities
for Resorts, Hotels and Cruises
for Parks of any kind
for Corporations
for any business
Learning
Encryption and Authentication
Safe Online Communication
Website Testimonials
Learn how to store private keys
Make The Most From Your Files
Convenient Volume Control
Photo Window - an Awesome Gift
Support
My Account
FAQ - Forum
 
Community
Blog
Email this page
Newsletter
Bonchev IT
About
Contact
Download
Public Authentication Key
Public Encryption Key

Sitemap
Disclaimer
Privacy
Antispam
© Copyright 2024 Bonchev Information Technologies. All Rights Reserved.
Machine translation:
Search: 


Email this page
To:
use semicolon to separate emails eg: joe@abc.com; lea@abc.com
Subject:
Message:
a link to this page will be automatically added to your message
From:
Please type the anti-bot text below.
Type text:
Thank you for subscribing to the MBBSoftware newsletter.
Enter your email address:
Please type the anti-bot text below.
Type text: