Git Product home page Git Product logo

vatin's Introduction

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);

vatin's People

Contributors

alexanderglueck avatar cmoralesweb avatar ddeboer avatar fpalamour avatar grahamcampbell avatar lnpbk avatar martinknor avatar midnightdesign avatar mweimerskirch avatar neodc avatar peter279k avatar pumatertion avatar siemendev avatar simonschaufi avatar spekulatius avatar timonf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vatin's Issues

Proposal: Make Validator callable?

So validating single records is quite easy with $bool = $validator->isValid('NL123456789B01'). When using with FilterIterators, i.e. CallbackFilterIterator, I feel it would be useful to make the Validator class callable.

My proposal is to alias the isValid method with a new __invoke method. One could then do:

$is_valid = new Validator;
$bool = $is_valid('NL123456789B01');

or, respectively:

$my_records = ask_database();
$is_valid = new Validator;
$valid_records = new \CallbackFilterIterator( $my_records, $is_valid);

What do you think?

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)"}

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.

Norway VatIds may contain MVA

Hi there!
The VatId Regex-Pattern for Norway is not correct. According to this: "9 digits and the letters 'MVA' to indicate VAT registration" the vat id for norway may include a "MVA" at the end of the VatId. Customers of our online-shop that include this in their vat id input (which is parsed through "ddeboer/vatin") get the notification, that their entered vat id in invalid, which is not the expected behavior.

I try to open up a pull request to get this asap into master since we're heavily depending on the vatin-bundle package from you. By the way: Great bundle, thanks for the effort you put in there!

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?

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

Uncaught PHP Exception SoapFault from VAT information exchange system service

As reported by @PaddyLock at ddeboer/vatin-bundle#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)"} []

Fix CH regex

According to this and this the (MWST|TVA|IVA) suffix on the VAT is absolutely not mandatory and is thus optional. The regex should be changed accordingly.

See #41

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

Regarding vatin bundle

Hi,

I would like to know whether this bundle checks only for EU based vatnumbers or does it validate both EU and non-EU as well?

Thanks in advance.

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 ?

Non EU vat numbers ?

Hi,

According to this wikipedia page there are other countries that use VAT numbers.
Would you consider a pull request to add the validation necessary for those other countries even if the VIES system is not usable for thoses (I suppose).

Thanks

Add Swiss VAT Numbers

Hi,

We have a customer with a Swiss VAT Number, can we add this format to the check?
CHE-123.456.789

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.