PageRenderTime 26ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/README.md

https://github.com/DragonBe/vies
Markdown | 320 lines | 221 code | 99 blank | 0 comment | 0 complexity | 065bf16d865357c5f21f164c7a46ae62 MD5 | raw file
  1. # VIES
  2. Component using the European Commission (EC) VAT Information Exchange System (VIES) to verify and validate VAT registration numbers in the EU, using PHP and Composer.
  3. The `Vies` class provides functionality to make a SOAP call to VIES and returns an object `CheckVatResponse` containing the following information:
  4. - Country code (string): a 2-character notation of the country code
  5. - VAT registration number (string): contains the complete registration number without the country code
  6. - Date of request (DateTime): the date when the request was made
  7. - Valid (boolean): flag indicating the registration number was valid (TRUE) or not (FALSE)
  8. - Name (string): registered company name (if provided by EC member state)
  9. - Address (string): registered company address (if provided by EC member state)
  10. Stated on the European Commission website:
  11. > To make an intra-Community supply without charging VAT, you **should ensure** that the person to whom you are supplying the goods is a taxable person in another Member State, and that the goods in question have left, or will leave your Member State to another MS. VAT-number should also be in the invoice.
  12. More information at http://ec.europa.eu/taxation_customs/vies/faqvies.do#item16
  13. [![Actions Status](https://github.com/DragonBe/vies/workflows/PHP%20Composer/badge.svg?branch=master)](https://github.com/DragonBe/vies/actions) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=dragonbe-vies&metric=alert_status)](https://sonarcloud.io/dashboard?id=dragonbe-vies)
  14. ## GDPR and privacy regulation of VAT within the EU
  15. On May 25, 2018 the General Data Protection Regulation or GDPR becomes law within all 28 European Member States. Is this VIES service package going to be compliant with GDPR?
  16. In short: yes.
  17. The longer answer is that this VIES package only interacts with the service for VAT ID verification provided by the European Commission. VAT validation is mandatory in European countries and therefor this service is allowed as lawfulness and legal basis. Please read more about this in [European DPO-3816.1](http://ec.europa.eu/dpo-register/details.htm?id=40647). This service does not store any data itself or collects more information than what's strictly required by law and provided by the EC VIES service.
  18. When you have implemented this service package in your own project, be sure that you're making sure you're just store the VAT ID, the timestamp of validation, the result of validation and optionally the given validation ID provided by the EC VIES service.
  19. ## Requirements
  20. - Minimum PHP version: 7.3
  21. - Recommended PHP version: 7.4
  22. - Extension: soap
  23. - Extension: pcntl
  24. - Extension: ctype
  25. Please read the [release notes](https://github.com/DragonBe/vies/releases) for details.
  26. ## Installation
  27. This project is on [Packagist](https://packagist.org/packages/dragonbe/vies)!
  28. To install the latest stable version use `composer require dragonbe/vies`.
  29. To install specifically a version (e.g. 2.2.0), just add it to the command above, for example `composer require dragonbe/vies:2.2.0`
  30. ## Usage
  31. Here's a usage example you can immediately execute on the command line (or in cron, worker or whatever) as this will most likely be your most common usecase.
  32. ### 1. Setting it up
  33. ```php
  34. <?php
  35. use DragonBe\Vies\Vies;
  36. use DragonBe\Vies\ViesException;
  37. use DragonBe\Vies\ViesServiceException;
  38. require_once dirname(__DIR__) . '/vendor/autoload.php';
  39. $vies = new Vies();
  40. ```
  41. ### 2. See if the VIES service is alive
  42. ```php
  43. if (false === $vies->getHeartBeat()->isAlive()) {
  44. echo 'Service is not available at the moment, please try again later.' . PHP_EOL;
  45. exit(1);
  46. }
  47. ```
  48. #### If using a proxy, you can now use the following approach
  49. ```php
  50. $vies = new Vies();
  51. $options = [
  52. 'proxy_host' => '127.0.0.1',
  53. 'proxy_port' => '8888',
  54. ];
  55. $vies->setOptions($options);
  56. $heartBeat = new \DragonBe\Vies\HeartBeat('tcp://' . $options['proxy_host'], $options['proxy_port']);
  57. $vies->setHeartBeat($heartBeat);
  58. $isAlive = $vies->getHeartBeat()->isAlive();
  59. ```
  60. ### 3. Validate VAT
  61. Now that we know the service is alive, we can start validating VAT ID's
  62. #### 3.1. Simple usage
  63. ```php
  64. $vatResult = $vies->validateVat(
  65. 'BE', // Trader country code
  66. '0203430576', // Trader VAT ID
  67. 'BE', // Requester country code
  68. '0811231190' // Requester VAT ID
  69. );
  70. ```
  71. #### 3.2. Advanced usage
  72. ```php
  73. $vatResult = $vies->validateVat(
  74. 'BE', // Trader country code
  75. '0203430576', // Trader VAT ID
  76. 'BE', // Requester country code
  77. '0811231190' // Requester VAT ID
  78. 'B-Rail', // Trader name
  79. 'NV', // Trader company type
  80. 'Frankrijkstraat 65', // Trader street address
  81. '1060', // Trader postcode
  82. 'Sint-Gillis' // Trader city
  83. );
  84. ```
  85. #### 3.3. Result methods
  86. ##### 3.3.1. Is the VAT ID valid?
  87. The most important functionality is to see if the VAT ID is valid
  88. ```php
  89. echo ($vatResult->isValid() ? 'Valid' : 'Not valid') . PHP_EOL;
  90. // Result: Valid
  91. ```
  92. ##### 3.3.2. Retrieve the VAT validation identifier
  93. ```php
  94. echo 'Identifier: ' . $vatResult->getIdentifier() . PHP_EOL;
  95. // Result: Identifier: WAPIAAAAWaXGj4Ra
  96. ```
  97. ##### 3.3.3. Retrieve validation date
  98. **Note: VIES service returns date and timezone, but no time**
  99. ```php
  100. echo 'Date and time: ' . $vatResult->getRequestDate()->format('r') . PHP_EOL;
  101. // Result: Date and time: Sat, 31 Aug 2019 00:00:00 +0200
  102. ```
  103. ##### 3.3.4. Retrieve official trader name (not always available)
  104. ```php
  105. echo 'Company name: ' . $vatResult->getName() . PHP_EOL;
  106. // Result: Company name: NV OR NATIONALE MAATSCHAPPIJ DER BELGISCHE SPOORWEGEN
  107. ```
  108. ##### 3.3.5. Retrieve official trader street (not always available)
  109. ```php
  110. echo 'Company address: ' . $vatResult->getAddress() . PHP_EOL;
  111. // Result: Company address: FRANKRIJKSTRAAT 56
  112. 1060 SINT-GILLIS (BIJ-BRUSSEL)
  113. ```
  114. ##### 3.3.6. Retrieve a match for trader name (not always available)
  115. ```php
  116. echo 'Trader name match: ' . $vatResult->getNameMatch() . PHP_EOL;
  117. // Result: Trader name match:
  118. ```
  119. ##### 3.3.7. Retrieve a match for trader company type (not always available)
  120. ```php
  121. echo 'Trader company type match: ' . $vatResult->getCompanyTypeMatch() . PHP_EOL;
  122. // Result: Trader company type match:
  123. ```
  124. ##### 3.3.8. Retrieve a match for trader street (not always available)
  125. ```php
  126. echo 'Trader street match: ' . $vatResult->getStreetMatch() . PHP_EOL;
  127. // Result: Trader street match:
  128. ```
  129. ##### 3.3.9. Retrieve a match for trader postcode (not always available)
  130. ```php
  131. echo 'Trader postcode match: ' . $vatResult->getPostcodeMatch() . PHP_EOL;
  132. // Result: Trader postcode match:
  133. ```
  134. ##### 3.3.10. Retrieve a match for trader city (not always available)
  135. ```php
  136. echo 'Trader city match: ' . $vatResult->getCityMatch() . PHP_EOL;
  137. // Result: Trader city match:
  138. ```
  139. ### Example code
  140. ```php
  141. <?php
  142. use DragonBe\Vies\Vies;
  143. use DragonBe\Vies\ViesException;
  144. use DragonBe\Vies\ViesServiceException;
  145. require_once dirname(__DIR__) . '/vendor/autoload.php';
  146. $vies = new Vies();
  147. $company = [
  148. 'country_code' => 'BE',
  149. 'vat_id' => '0203430576',
  150. 'trader_name' => 'B-Rail',
  151. 'trader_company_type' => 'NV',
  152. 'trader_street' => 'Frankrijkstraat 65',
  153. 'trader_postcode' => '1060',
  154. 'trader_city' => 'Sint-Gillis',
  155. ];
  156. try {
  157. $vatResult = $vies->validateVat(
  158. $company['country_code'], // Trader country code
  159. $company['vat_id'], // Trader VAT ID
  160. 'BE', // Requester country code (your country code)
  161. '0811231190', // Requester VAT ID (your VAT ID)
  162. $company['trader_name'], // Trader name
  163. $company['trader_company_type'], // Trader company type
  164. $company['trader_street'], // Trader street address
  165. $company['trader_postcode'], // Trader postcode
  166. $company['trader_city'] // Trader city
  167. );
  168. } catch (ViesException $viesException) {
  169. echo 'Cannot process VAT validation: ' . $viesException->getMessage();
  170. exit (2);
  171. } catch (ViesServiceException $viesServiceException) {
  172. echo 'Cannot process VAT validation: ' . $viesServiceException->getMessage();
  173. exit (2);
  174. }
  175. echo ($vatResult->isValid() ? 'Valid' : 'Not valid') . PHP_EOL;
  176. echo 'Identifier: ' . $vatResult->getIdentifier() . PHP_EOL;
  177. echo 'Date and time: ' . $vatResult->getRequestDate()->format('d/m/Y H:i') . PHP_EOL;
  178. echo 'Company name: ' . $vatResult->getName() . PHP_EOL;
  179. echo 'Company address: ' . $vatResult->getAddress() . PHP_EOL;
  180. echo 'Trader name match: ' . $vatResult->getNameMatch() . PHP_EOL;
  181. echo 'Trader company type match: ' . $vatResult->getCompanyTypeMatch() . PHP_EOL;
  182. echo 'Trader street match: ' . $vatResult->getStreetMatch() . PHP_EOL;
  183. echo 'Trader postcode match: ' . $vatResult->getPostcodeMatch() . PHP_EOL;
  184. echo 'Trader city match: ' . $vatResult->getCityMatch() . PHP_EOL;
  185. echo PHP_EOL;
  186. ```
  187. When you run this, you will get the following result:
  188. ```
  189. Valid
  190. Identifier: WAPIAAAAWaYR0O8D
  191. Date and time: 21/10/2018 02:00
  192. Company name: NV OR NATIONALE MAATSCHAPPIJ DER BELGISCHE SPOORWEGEN
  193. Company address: FRANKRIJKSTRAAT 56
  194. 1060 SINT-GILLIS (BIJ-BRUSSEL)
  195. Trader name match:
  196. Trader company type match:
  197. Trader street match:
  198. Trader postcode match:
  199. Trader city match:
  200. ```
  201. ## Community involvement
  202. Here's a list of products or projects that have included this VIES package
  203. - [Symfony bundle](https://github.com/MyOnlineStore/ViesBundle) by [MyOnlineStore](https://www.myonlinestore.com)
  204. - [sandwich/vies-bundle](https://packagist.org/packages/sandwich/vies-bundle)
  205. If you have a product or a project that's using this package and you want some attribution for your work, send me an [email](mailto://dragonbe+github@gmail.com) or ping me on [Twitter](https://www.twitter.com/DragonBe) or [Facebook](https://www.facebook.com/dragonbe).
  206. ## Docker containers
  207. If you like to have Docker containers, you can now make use of a container designed for that purpose.
  208. ```shell
  209. docker run --rm -d -p 8000:18080 dragonbe/vies-web
  210. ```
  211. Point your browser to [localhost:8000](http://localhost:8000) to use the web interface for validating VAT.
  212. ![A screenshot of VIES web application](docs/images/vies-web-screenshot.png)
  213. ## Referenced on the web
  214. - [Microsoft Dynamics GP - Dynamics GP real time EU tax registration number validation using VIES](http://timwappat.info/post/2013/08/22/Dynamics-GP-real-time-EU-tax-registration-number-validation-using-VIES)
  215. - [Popular RIA law eu projects](https://libraries.io/search?keywords=RIA%2Claw%2Ceu)
  216. - [PHP Code Examples - HotExamples.com](https://hotexamples.com/examples/dragonbe.vies/Vies/validateVat/php-vies-validatevat-method-examples.html)
  217. ## Clarification on exceptions
  218. For Greece the [international country ISO code](https://www.iso.org/obp/ui/#iso:code:3166:GR) is **GR**, but for VAT IDN's they use the prefix **EL**. Thanks to [Johan Wilfer](https://github.com/johanwilfer) for [reporting this](https://github.com/DragonBe/vies/issues/57).
  219. Since January 1, 2021 the UK is no longer a member of the European Union and as a result, the VIES service provided by the European Commission no longer validates VAT ID's for the UK. There is one exception though and that is for Northern Ireland (XI) for which VAT ID's can be validated using this library and the EC VIES service.
  220. ## Licence
  221. DragonBe\Vies is released under the MIT Licence. See the bundled [LICENCE](LICENCE) file for details.