Skip to content

Commit

Permalink
Merge branch 'release/0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrej Galuf committed Jan 27, 2018
2 parents 3187407 + c7416d5 commit 33e8683
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
8 changes: 4 additions & 4 deletions resources/vat.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"DE[0-9]{9}"
],
"DK": [
"DK[0-9]{2}\\s?[0-9]{2}\\s?[0-9]{2}\\s?[0-9]{2}"
"DK[0-9]{8}"
],
"EE": [
"EE[0-9]{9}"
Expand All @@ -32,11 +32,11 @@
"FI[0-9]{8}"
],
"FR": [
"FR[A-Z]{2}\\s?[0-9]{9}"
"FR[A-Z0-9]{2}[0-9]{9}"
],
"GB" : [
"GB[0-9]{3}\\s?[0-9]{4}\\s?[0-9]{2}",
"GB[0-9]{3}\\s?[0-9]{4}\\s?[0-9]{2}\\s?[0-9]{3}",
"GB[0-9]{9}",
"GB[0-9]{12}",
"GB[A-Z0-9]{5}"
],
"GR": [
Expand Down
5 changes: 5 additions & 0 deletions src/Vatty.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ public function validate(/* string */ $countryCode, /* string */ $vatNumber) {
try {
$vat = $this->repository->get($countryCode);

// Vies service expects the Vat number to be passed without any spaces,
// even though official Vat numbers may contain them (see France, GB).
// To simplify and unify the validations, we remove the spaces here.
$vatNumber = str_replace(' ', '', $vatNumber);

$syntaxValid = $vat->validate($vatNumber);

if ($syntaxValid && $this->vies === TRUE) {
Expand Down
9 changes: 5 additions & 4 deletions tests/Unit/Repository/VatRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,17 @@ public function provideViesSamples() {
['CZ', 'CZ999999999'],
['CZ', 'CZ9999999999'],
['DE', 'DE999999999'],
['DK', 'DK99 99 99 99'],
['DK', 'DK99999999'],
['EE', 'EE999999999'],
['GR', 'EL999999999'],
['ES', 'ESX99999999'],
['ES', 'ESX9999999X'],
['ES', 'ES99999999X'],
['FI', 'FI99999999'],
['FR', 'FRXX 999999999'],
['GB', 'GB999 9999 99'],
['GB', 'GB999 9999 99 999'],
['FR', 'FRXX999999999'],
['FR', 'FR99999999999'],
['GB', 'GB999999999'],
['GB', 'GB999999999999'],
['GB', 'GBGD999'],
['GB', 'GBHA999'],
['HR', 'HR99999999999'],
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/VattyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ public function provideValidationData() {
return [
['DE', 'DE123456789', TRUE],
['DE', 'FR123456789', FALSE],
['DE', 'DE 123456789', TRUE],
['DE', 'DE12345678', FALSE],
['DE', 'DE1234567890', FALSE],
['FO', 'Invalid', FALSE],
Expand Down

0 comments on commit 33e8683

Please sign in to comment.