Skip to content

cbmono/eu-vat-id-validation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

European VAT number validation (VIES) in PHP Build Status

VIES API documentation

Getting Started

To start validating VAT-ID's you only need to include src/eu_vat_validation.php in your code. All other files and folders are only needed for PHPUnit and unit tests.


Options / Functions

__construct()

  • param: string $vatId [optional]
  • throws: SoapFault

Tries to establish a connection with the SOAP client. If $vatId isn't empty, the validation ($this->validate()) is triggered right away.


setVatId()

  • param: string $vatId
  • throws: Exception

Sets the current VAT-ID value and extracts the VAT-Number and the country code from it.


getVatId()

  • return: string

Gets the last set VAT-ID value.


getVatIdExtended()

  • return: array

Gets the last set VAT-ID value and all associated details:

  • VAT-ID
  • VAT-Number
  • Country code
  • Is valid?
  • Company name (not always available)
  • Company address (not always available)

Example:

Array (
    [vatId] => IT01775560442
    [vatNumber] => 01775560442
    [countryCode] => IT
    [isValid] => 1
    [companyName] => M.A.B. SOFTWARE SRL
    [companyAddress] => C DA CAMPIGLIONE 20 63900 FERMO FM
)

validate()

Sends a request to the VIES API and validates the last set VAT-ID value.


isValid()

  • return: boolean

Internally triggers $this->validate() if it hasn't been executed yet, and returns whether the last set VAT-ID is valid.


Usage Examples

Check if passed VAT-ID is valid:

$vatId = new EuVatValidation('IT01775560442');  
print_r($vatId->isValid());

// Output
true

Check multiple VAT-ID's:

$vatId = new EuVatValidation;

$vatId->setVatId('IT01775560442');
print_r($vatId->isValid());             // Output: true

$vatId->setVatId('XX123456789');
print_r($vatId->isValid());             // Output: false

Display all VAT-ID details:

$vatId = new EuVatValidation('IT01775560442');
print_r($vatId->getVatIdExtended());

// Output
Array (
    [vatId] => IT01775560442
    [vatNumber] => 01775560442
    [countryCode] => IT
    [isValid] => 1
    [companyName] => M.A.B. SOFTWARE SRL
    [companyAddress] => C DA CAMPIGLIONE 20 63900 FERMO FM
)

Using all public class functions:

$vatId = new EuVatValidation;
$vatId->setVatId('IT01775560442');
$vatId->validate();

print_r($vatId->isValid());             // Output: true
print_r($vatId->getVatId());            // Output: 'IT01775560442'

print_r($vatId->getVatIdExtended());

// Output
Array (
    [vatId] => IT01775560442
    [vatNumber] => 01775560442
    [countryCode] => IT
    [isValid] => 1
    [companyName] => M.A.B. SOFTWARE SRL
    [companyAddress] => C DA CAMPIGLIONE 20 63900 FERMO FM
)

About

European VAT number validation (VIES)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages