A small PHP library for validating VAT identification numbers (VATINs).

Overview

VATIN

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version

A small PHP library for validating VAT identification numbers (VATINs).

Installation

This library is available on Packagist:

$ composer require ddeboer/vatin

If you want to use this library in a Symfony application, you can use the VatinBundle instead.

Usage

Validate a VAT number’s format:

use Ddeboer\Vatin\Validator;

$validator = new Validator;
$bool = $validator->isValid('NL123456789B01');

Additionally check whether the VAT number is in use, with a call to the VAT Information Exchange System (VIES) SOAP web service:

use Ddeboer\Vatin\Validator;

$validator = new Validator;
$bool = $validator->isValid('NL123456789B01', true);
Comments
  • Regex tweak for GB VAT nos.

    Regex tweak for GB VAT nos.

    Forgive me if I'm wrong, but should the regex pattern for GB VAT ids be wrapped in parens?

    'GB' => '(\d{9}|\d{12}|(GD|HA)\d{3})'

    Currently if you supply a valid VAT number with any random string after it, it still passes validation. Wrapping the pattern in parentheses fixes the issue, but wanted to raise this here first in case I was missing something obvious.

    opened by lnpbk 9
  • GB does not validate against the VIES

    GB does not validate against the VIES

    Because of BREXIT, the EU API (VIES) does not validate GB VATINs anymore. There is an API provided by the HMRC https://developer.service.hmrc.gov.uk/api-documentation/docs/api/service/vat-registered-companies-api/1.0#_get-a-vat-registration_get_accordion

    Not sure if this is beyond the scope of this package.

    opened by ostark 7
  • Optionally catch WSDL client exceptions

    Optionally catch WSDL client exceptions

    This fixes #9 and #10 if a third parameter is passed to Validator::isValid.

    When there is an error with the service, the third parameter becomes the return value, so set it to true to assume a valid number or false to assume an invalid number.

    I'm not too sure whether it makes sense to have the default/null handled as it is currently, but I wanted to make sure that testWrongConnectionThrowsException passed. Any thoughts?

    opened by alanpearce 7
  • Test enhancement

    Test enhancement

    Changed log

    • Use expectedException annotation to be compatible with the different PHPUnit version.
    • Use the ::class approach directly in assertInstanceOf expected object.
    opened by peter279k 5
  • Speed of VIES

    Speed of VIES

    The web service is not responding for me. I don't get results within 30 seconds. Is this simply a problem with VIES at the moment? Or is this service no longer available?

    opened by roelvanduijnhoven 5
  • Uncaught PHP Exception SoapFault from VAT information exchange system service

    Uncaught PHP Exception SoapFault from VAT information exchange system service

    As reported by @PaddyLock at https://github.com/ddeboer/vatin-bundle/issues/4:

    When checking the vat number existence against the VAT information exchange system service, the bundle does not catch an exception if the server is busy.

    request.CRITICAL: Uncaught PHP Exception SoapFault: "SERVER_BUSY" at /var/www/releases/20141211152308/vendor/ddeboer/vatin/src/Ddeboer/Vatin/Vies/Client.php line 60 {"exception":"[object] (SoapFault: SERVER_BUSY at /var/www/releases/20141211152308/vendor/ddeboer/vatin/src/Ddeboer/Vatin/Vies/Client.php:60)"} []
    
    opened by ddeboer 5
  • Added Switzerland to the list of available VAT ID formats

    Added Switzerland to the list of available VAT ID formats

    Added CH validation rule and tests.

    Furthermore, I had to increase the whitespaces because the CH check would have ruined the alignment of the comments.

    opened by alexanderglueck 4
  • Uncaught Soap Fault

    Uncaught Soap Fault

    Hi, I have recently had another uncaught Exception which occured several times in succession.

    [2015-01-19 16:46:12] request.CRITICAL: Uncaught PHP Exception SoapFault: "MS_UNAVAILABLE" at /var/www/releases/20150107155314/vendor/ddeboer/vatin/src/Ddeboer/Vatin/Vies/Client.php line 60 {"exception":"[object](SoapFault: MS_UNAVAILABLE at /var/www/releases/20150107155314/vendor/ddeboer/vatin/src/Ddeboer/Vatin/Vies/Client.php:60)"} []

    Is this related to #9 ?

    opened by PaddyLock 4
  • CH country

    CH country

    Use CH country code here https://github.com/ddeboer/vatin/blob/master/src/Validator.php#L27 when VIES doesn't work with it. https://ec.europa.eu/taxation_customs/vies/faq.html?locale=lt#item_11

    opened by martinknor 3
  • Uncaught Vies Exception

    Uncaught Vies Exception

    Hi, I am using the VATIN directly (no bundle) to validate with in a custom validator

    if ($vatNumber != '') {
            $validator = new \Ddeboer\Vatin\Validator();
    
            try {
                $valid = $validator->isValid($vatNumber, true);
                if (!$valid) {
                    $this->context->addViolation($constraint->message, array('%vatNumber%' => $vatNumber));
                }
            } catch (Exception $e) {
    
            }
        }
    

    However, I still get an uncaught exception when there is a problem with the VIES service

    [2015-06-03 09:14:14] request.CRITICAL: Uncaught PHP Exception Ddeboer\Vatin\Exception\ViesException: "Error communicating with VIES service" at /var/www/releases/20150603055730/vendor/ddeboer/vatin/src/Ddeboer/Vatin/Vies/Client.php line 67 {"exception":"[object] (Ddeboer\\Vatin\\Exception\\ViesException(code: 0): Error communicating with VIES service at /var/www/releases/20150603055730/vendor/ddeboer/vatin/src/Ddeboer/Vatin/Vies/Client.php:67, SoapFault(code: 0): SERVER_BUSY at /var/www/releases/20150603055730/vendor/ddeboer/vatin/src/Ddeboer/Vatin/Vies/Client.php:65)"}
    
    opened by PaddyLock 3
  • Uncaught ViesException using checkExistence=true

    Uncaught ViesException using checkExistence=true

    If I use the validation with checkExistence=true

    @Vatin(checkExistence=true)
    

    I am getting the following error:

    Error communicating with VIES service 500 Internal Server Error - ViesException 1 linked Exception: SoapFault »

    ViesException: Error communicating with VIES service SoapFault: SERVER_BUSY

    Can this Exception be caught?

    Thanks

    opened by PaddyLock 3
  • Feature/php72

    Feature/php72

    hi. i bumped php to 7.2. i suggest to bump further to php 7.4 as latest supported version (for this and your symfony-bundle). What is you opionen about that? https://php.watch/versions

    github actions are added

    opened by Chris53897 0
  • Improvement: make checkVat() exception message more accurate

    Improvement: make checkVat() exception message more accurate

    Currently the method checkVat() just throws a ViesException with the message: 'Error communicating with VIES service'. Bit it is possible to give a more accurate message back. This is from the documentation of the https://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl :

    In case of problems, the returned FaultString can take the following specific values:

    • INVALID_INPUT: The provided CountryCode is invalid or the VAT number is empty;

    • GLOBAL_MAX_CONCURRENT_REQ: Your Request for VAT validation has not been processed; the maximum number of concurrent requests has been reached. Please re-submit your request later or contact [email protected] for further information": Your request cannot be processed due to high traffic on the web application. Please try again later;

    • MS_MAX_CONCURRENT_REQ: Your Request for VAT validation has not been processed; the maximum number of concurrent requests for this Member State has been reached. Please re-submit your request later or contact [email protected] for further information": Your request cannot be processed due to high traffic towards the Member State you are trying to reach. Please try again later.

    • SERVICE_UNAVAILABLE: an error was encountered either at the network level or the Web application level, try again later;

    • MS_UNAVAILABLE: The application at the Member State is not replying or not available. Please refer to the Technical Information page to check the status of the requested Member State, try again later;

    • TIMEOUT: The application did not receive a reply within the allocated time period, try again later.

    It would be helpful to know why the check failed. Was it because of a wrong VAT number or a failed request? What do you think about throwing different exceptions or the ViesException with different messages? We could group it like

    • INVALID_INPUT: "The provided CountryCode is invalid or the VAT number is empty"
    • GLOBAL_MAX_CONCURRENT_REQ, MS_MAX_CONCURRENT_REQ, SERVICE_UNAVAILABLE, SERVICE_UNAVAILABLE, MS_UNAVAILABLE: "an error was encountered either at the network level or the Web application level, try again later"
    • TIMEOUT: when there is a timeout the vatin check could try the validation for a second time. If it fails again the app would return the upper message/error.
    opened by dzschille 1
  • Change property visibility and make SOAP client options configurable for VIES client

    Change property visibility and make SOAP client options configurable for VIES client

    We want to change the URL address and add a SOAP client timeout.

    It would be helpful if the $wsdl property would be changed to protected (in order to extend the class and change the property) and if the options passed into the \SoapClient (second parameter) would be configurable using a protected property.

    Related file is ddeboer/vatin/src/Vies/Client.php

    opened by fnagel 1
Releases(2.4.0)
Owner
David de Boer
Open sourcerer
David de Boer
Handle all the hard stuff related to EU MOSS tax/vat regulations, the way it should be.

VatCalculator Handle all the hard stuff related to EU MOSS tax/vat regulations, the way it should be. Integrates with Laravel and Cashier — or in a st

Dries Vints 1.1k Jan 5, 2023
Handle all the hard stuff related to EU MOSS tax/vat regulations, the way it should be.

VatCalculator Handle all the hard stuff related to EU MOSS tax/vat regulations, the way it should be. Integrates with Laravel and Cashier — or in a st

Dries Vints 1.1k Jan 7, 2023
Automatically validating Eloquent models for Laravel

Validating, a validation trait for Laravel Validating is a trait for Laravel Eloquent models which ensures that models meet their validation criteria

Dwight Watson 955 Dec 25, 2022
Laravel package to convert English numbers to Bangla number or Bangla text, Bangla month name and Bangla Money Format

Number to Bangla Number, Word or Month Name in Laravel | Get Wordpress Plugin Laravel package to convert English numbers to Bangla number or Bangla te

Md. Rakibul Islam 50 Dec 26, 2022
Laravel package to convert English numbers to Bangla number or Bangla text, Bangla month name and Bangla Money Format

Number to Bangla Number, Word or Month Name in Laravel | Get Wordpress Plugin Laravel package to convert English numbers to Bangla number or Bangla te

Md. Rakibul Islam 50 Dec 26, 2022
Flexihash is a small PHP library which implements consistent hashing.

Flexihash Flexihash is a small PHP library which implements consistent hashing, which is most useful in distributed caching. It requires PHP5 and uses

Paul Annesley 364 Oct 18, 2022
Simple timesheets and vacation management for small businesses.

About Daybreak Daybreak is a very simplistic timesheet and vacation planning program for small businesses. It was created because I needed something I

Erik Porsche 110 Dec 27, 2022
A small package for adding UUIDs to Eloquent models.

A small package for adding UUIDs to Eloquent models. Installation You can install the package via composer: composer require ryangjchandler/laravel-uu

Ryan Chandler 40 Jun 5, 2022
An issue tracking tool based on laravel+reactjs for small and medium-sized enterprises, open-source and free, similar to Jira.

ActionView English | 中文 An issue tracking tool based on php laravel-framework in back-end and reactjs+redux in front-end, it's similar to Jira. You co

null 1.7k Dec 23, 2022
Datenstrom Yellow is for people who make small websites.

Datenstrom Yellow is for people who make small websites.

Datenstrom 389 Jan 7, 2023
A package to handle the SEO in any Laravel application, big or small.

Never worry about SEO in Laravel again! Currently there aren't that many SEO-packages for Laravel and the available ones are quite complex to set up a

Ralph J. Smit 267 Jan 2, 2023
Package with small support traits and classes for the Laravel Eloquent models

Contains a set of traits for the eloquent model. In future can contain more set of classes/traits for the eloquent database.

Martin Kluska 3 Feb 10, 2022
Lavacharts is a graphing / charting library for PHP 5.4+ that wraps Google's Javascript Chart API.

Lavacharts 3.1.12 Lavacharts is a graphing / chart library for PHP5.4+ that wraps the Google Chart API. Stable: Dev: Developer Note Please don't be di

Kevin Hill 616 Dec 17, 2022
A laravel service provider for the netsuite-php library service

netsuite-laravel A PHP supplemental package to the ryanwinchester/netsuite-php package to add the NetSuite service client to the service container of

NetsuitePHP 6 Nov 9, 2022
PHP client library for reCAPTCHA, a free service to protect your website from spam and abuse.

reCAPTCHA PHP client library reCAPTCHA is a free CAPTCHA service that protects websites from spam and abuse. This is a PHP library that wraps up the s

Google 3.3k Dec 23, 2022
Menu Library for PHP

KnpMenu The KnpMenu library provides object oriented menus for PHP. It is used by the KnpMenuBundle for Symfony but can now be used stand-alone. Insta

KNP Labs 1.3k Jan 1, 2023
PHP 5.3 Object Oriented image manipulation library

Imagine Tweet about it using the #php_imagine hashtag. Image manipulation library for PHP 5.3 inspired by Python's PIL and other image libraries. Requ

null 4.3k Dec 29, 2022
Geo-related tools PHP 7.3+ library built atop Geocoder and React libraries

Geotools Geotools is a PHP geo-related library, built atop Geocoder and React libraries. Features Batch geocode & reverse geocoding request(s) in seri

The League of Extraordinary Packages 1.3k Dec 27, 2022
A PHP library for simplifying the use of accessors.

Accessor A PHP library for simplifying the use of accessors. Usage use Doctrine\ORM\Mapping as ORM; use Phine\Accessor\AccessorTrait; use Phine\Access

KHerGe - Archived Projects 5 May 14, 2020