blockpoint / vat24api-php
API wrapper for Vat24API
Fund package maintenance!
Blockpoint
Requires
- php: ^8.1
Requires (Dev)
- laravel/pint: ^1.0
- phpunit/phpunit: ^10.3.2
- spatie/ray: ^1.28
README
A PHP wrapper for the Vat24API service, which provides VAT and EORI number validation for EU and UK businesses. This package makes it easy to integrate VAT and EORI validation into your PHP applications.
Installation
You can install the package via composer:
composer require blockpoint/vat24api-php
Usage
// Create a new Vat24Api instance with your API key $vat24api = new Blockpoint\Vat24Api\Vat24Api('your-api-key'); // Validate a VAT number try { $response = $vat24api->validateVat('NL', '836176320B01'); if ($response->hasError()) { echo "API Error: " . $response->getErrorMessage() . "\n"; echo "Status Code: " . $response->getStatusCode() . "\n"; } elseif ($response->isValid()) { echo "VAT number is valid!\n"; echo "Company name: " . $response->getCompanyName() . "\n"; echo "Company address: " . $response->getCompanyAddress() . "\n"; } else { echo "VAT number is not valid!\n"; echo "Reason: " . $response->getFaultString() . "\n"; } } catch (\Blockpoint\Vat24Api\Exceptions\Vat24ApiException $e) { echo "Error: " . $e->getMessage() . "\n"; } // Validate an EORI number try { $response = $vat24api->validateEori('GB', '123456789000'); if ($response->hasError()) { echo "API Error: " . $response->getErrorMessage() . "\n"; echo "Status Code: " . $response->getStatusCode() . "\n"; } elseif ($response->isValid()) { echo "EORI number is valid!\n"; echo "Company name: " . $response->getCompanyName() . "\n"; } else { echo "EORI number is not valid!\n"; echo "Reason: " . $response->getFaultString() . "\n"; } } catch (\Blockpoint\Vat24Api\Exceptions\Vat24ApiException $e) { echo "Error: " . $e->getMessage() . "\n"; }
Available Methods
Validate VAT Number
$response = $vat24api->validateVat('NL', '836176320B01');
You can also perform a mutual validation by providing a requester country code and VAT number:
$response = $vat24api->validateVat('NL', '836176320B01', 'GB', '123456789');
Validate EORI Number
$response = $vat24api->validateEori('GB', '123456789000');
Response Methods
The ValidationResponse
object provides the following methods:
isValid()
: Returns whether the VAT/EORI number is validhasError()
: Returns whether the response contains an API errorgetErrorMessage()
: Returns the error message if anygetStatusCode()
: Returns the HTTP status codegetMessage()
: Returns the status messagegetCountryCode()
: Returns the country codegetVatNumber()
: Returns the VAT numbergetEoriNumber()
: Returns the EORI numbergetValidationStatus()
: Returns the validation statusgetFaultString()
: Returns the fault string if validation failedgetRequestDate()
: Returns the request dategetConsultationNumber()
: Returns the consultation numbergetConsultationAuthority()
: Returns the consultation authoritygetCompanyName()
: Returns the company namegetCompanyAddress()
: Returns the company addresstoArray()
: Returns the raw response data as an array
Testing
composer test
License
The MIT License (MIT). Please see License File for more information.