valvat 0.8.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.github/workflows/ruby.yml +35 -0
- data/.gitignore +3 -1
- data/.rubocop.yml +15 -0
- data/CHANGES.md +45 -1
- data/Gemfile +4 -3
- data/Guardfile +6 -4
- data/README.md +99 -47
- data/Rakefile +3 -1
- data/certs/yolk.pem +21 -21
- data/gemfiles/activemodel-5 +4 -5
- data/gemfiles/activemodel-6 +7 -0
- data/gemfiles/standalone +3 -5
- data/lib/active_model/validations/valvat_validator.rb +70 -22
- data/lib/valvat.rb +7 -3
- data/lib/valvat/checksum.rb +14 -13
- data/lib/valvat/checksum/at.rb +3 -1
- data/lib/valvat/checksum/be.rb +3 -1
- data/lib/valvat/checksum/bg.rb +17 -17
- data/lib/valvat/checksum/cy.rb +2 -0
- data/lib/valvat/checksum/de.rb +5 -3
- data/lib/valvat/checksum/dk.rb +3 -1
- data/lib/valvat/checksum/ee.rb +2 -0
- data/lib/valvat/checksum/es.rb +14 -16
- data/lib/valvat/checksum/fi.rb +3 -1
- data/lib/valvat/checksum/fr.rb +4 -2
- data/lib/valvat/checksum/gb.rb +53 -21
- data/lib/valvat/checksum/gr.rb +4 -2
- data/lib/valvat/checksum/hr.rb +2 -0
- data/lib/valvat/checksum/hu.rb +2 -0
- data/lib/valvat/checksum/ie.rb +5 -6
- data/lib/valvat/checksum/it.rb +6 -4
- data/lib/valvat/checksum/lt.rb +2 -0
- data/lib/valvat/checksum/lu.rb +3 -1
- data/lib/valvat/checksum/mt.rb +2 -0
- data/lib/valvat/checksum/nl.rb +9 -2
- data/lib/valvat/checksum/pl.rb +3 -1
- data/lib/valvat/checksum/pt.rb +3 -1
- data/lib/valvat/checksum/ro.rb +2 -0
- data/lib/valvat/checksum/se.rb +5 -3
- data/lib/valvat/checksum/si.rb +4 -2
- data/lib/valvat/error.rb +31 -0
- data/lib/valvat/local.rb +8 -5
- data/lib/valvat/locales/de.yml +2 -1
- data/lib/valvat/locales/en.yml +2 -1
- data/lib/valvat/locales/es.yml +1 -0
- data/lib/valvat/locales/fr.yml +18 -17
- data/lib/valvat/locales/hu.yml +1 -0
- data/lib/valvat/locales/nl.yml +1 -0
- data/lib/valvat/locales/pl.yml +1 -0
- data/lib/valvat/locales/pt.yml +28 -28
- data/lib/valvat/lookup.rb +14 -45
- data/lib/valvat/lookup/fault.rb +31 -0
- data/lib/valvat/lookup/request.rb +37 -11
- data/lib/valvat/lookup/response.rb +37 -0
- data/lib/valvat/syntax.rb +31 -30
- data/lib/valvat/utils.rb +20 -9
- data/lib/valvat/version.rb +3 -1
- data/spec/active_model/validations/valvat_validator_spec.rb +132 -100
- data/spec/spec_helper.rb +8 -8
- data/spec/valvat/checksum/at_spec.rb +8 -6
- data/spec/valvat/checksum/be_spec.rb +8 -6
- data/spec/valvat/checksum/bg_spec.rb +9 -6
- data/spec/valvat/checksum/cy_spec.rb +5 -3
- data/spec/valvat/checksum/de_spec.rb +8 -6
- data/spec/valvat/checksum/dk_spec.rb +8 -6
- data/spec/valvat/checksum/ee_spec.rb +5 -3
- data/spec/valvat/checksum/es_spec.rb +9 -6
- data/spec/valvat/checksum/fi_spec.rb +8 -6
- data/spec/valvat/checksum/fr_spec.rb +8 -6
- data/spec/valvat/checksum/gb_spec.rb +9 -5
- data/spec/valvat/checksum/gr_spec.rb +8 -6
- data/spec/valvat/checksum/hr_spec.rb +5 -3
- data/spec/valvat/checksum/hu_spec.rb +5 -3
- data/spec/valvat/checksum/ie_spec.rb +13 -5
- data/spec/valvat/checksum/it_spec.rb +12 -10
- data/spec/valvat/checksum/lt_spec.rb +5 -3
- data/spec/valvat/checksum/lu_spec.rb +8 -6
- data/spec/valvat/checksum/mt_spec.rb +5 -3
- data/spec/valvat/checksum/nl_spec.rb +9 -7
- data/spec/valvat/checksum/pl_spec.rb +10 -8
- data/spec/valvat/checksum/pt_spec.rb +12 -13
- data/spec/valvat/checksum/ro_spec.rb +5 -3
- data/spec/valvat/checksum/se_spec.rb +10 -8
- data/spec/valvat/checksum/si_spec.rb +12 -10
- data/spec/valvat/checksum_spec.rb +12 -10
- data/spec/valvat/lookup/fault_spec.rb +34 -0
- data/spec/valvat/lookup/request_spec.rb +19 -0
- data/spec/valvat/lookup/response_spec.rb +29 -0
- data/spec/valvat/lookup_spec.rb +202 -84
- data/spec/valvat/syntax_spec.rb +59 -280
- data/spec/valvat/utils_spec.rb +76 -42
- data/spec/valvat_spec.rb +140 -152
- data/valvat.gemspec +18 -17
- metadata +61 -41
- metadata.gz.sig +0 -0
- data/.travis.yml +0 -33
- data/gemfiles/activemodel-3-2 +0 -8
- data/gemfiles/activemodel-4 +0 -8
- data/gemfiles/before-ruby21/activemodel-3-2 +0 -9
- data/gemfiles/before-ruby21/activemodel-4 +0 -9
- data/gemfiles/before-ruby21/standalone +0 -8
- data/lib/valvat/lookup/request_with_id.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddc578b98f0c869566769b5588b5768bbdcc5ba4901ab97227c7908502a7b5c9
|
4
|
+
data.tar.gz: f7bfc69d3cd2983bb3d306d0932ef6d436890850bc67f6c63e639d2c666dc1ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 910d4c387c6e82adeee3146b54e928b253fcd4aae6873ae438a575612b72a136459d50411c565ba47683b1b8f325f90771774add2b7110b1c4a6c4e880ba0999
|
7
|
+
data.tar.gz: a93a4d12a53fe3601525a153c6f2ae042259371f1775c05fb27ada151e91f3ff0325f794332797eb31ff502606dd31edee502d910866e8c76feeb6613cb3b95e
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
@@ -0,0 +1,35 @@
|
|
1
|
+
name: Specs
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
paths-ignore:
|
7
|
+
- 'README.md'
|
8
|
+
- 'CHANGES.md'
|
9
|
+
pull_request:
|
10
|
+
branches: [ master ]
|
11
|
+
|
12
|
+
jobs:
|
13
|
+
test:
|
14
|
+
if: "!contains(github.event.head_commit.message, '[skip ci]')"
|
15
|
+
runs-on: ubuntu-latest
|
16
|
+
env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
|
17
|
+
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}
|
18
|
+
strategy:
|
19
|
+
matrix:
|
20
|
+
ruby-version: ['2.5', '2.6', '2.7', '3.0', 'jruby-head']
|
21
|
+
gemfile: [ 'standalone', 'activemodel-5', 'activemodel-6' ]
|
22
|
+
exclude:
|
23
|
+
- ruby-version: '3.0'
|
24
|
+
gemfile: 'activemodel-5'
|
25
|
+
|
26
|
+
steps:
|
27
|
+
- uses: actions/checkout@v2
|
28
|
+
- name: Set up Ruby
|
29
|
+
uses: ruby/setup-ruby@v1
|
30
|
+
with:
|
31
|
+
ruby-version: ${{ matrix.ruby-version }}
|
32
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
33
|
+
- name: Run specs
|
34
|
+
run: |
|
35
|
+
bundle exec rspec
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
data/CHANGES.md
CHANGED
@@ -1,6 +1,50 @@
|
|
1
|
+
|
1
2
|
### dev
|
2
3
|
|
3
|
-
[full changelog](http://github.com/yolk/valvat/compare/
|
4
|
+
[full changelog](http://github.com/yolk/valvat/compare/v1.1.0...master)
|
5
|
+
|
6
|
+
### 1.1.0 / 2021-01-15
|
7
|
+
|
8
|
+
[full changelog](http://github.com/yolk/valvat/compare/v1.0.1...v1.1.0)
|
9
|
+
|
10
|
+
* Added support for Northern Ireland XI prefixed VAT numbers (by [Avatar Ignacy Kasperowicz](https://github.com/kspe))
|
11
|
+
* ActiveModel: Return specific error message if VIES is down and fail_if_down is set to true (by [Arkadiy Zabazhanov](https://github.com/pyromaniac))
|
12
|
+
* Removed support for EOL rubies (all before 2.5) and ActiveModel before 5.0
|
13
|
+
|
14
|
+
### 1.0.1 / 2020-12-06
|
15
|
+
|
16
|
+
[full changelog](http://github.com/yolk/valvat/compare/v1.0.0...v1.0.1)
|
17
|
+
|
18
|
+
* Added missing spaces to malformatted portuegese locale file
|
19
|
+
* Removed GB from EU_COUNTRIES / EU_MEMBER_STATES but kept support
|
20
|
+
* Fixed typo in error message: UNK(N)OWN (by [Igor Gonchar](https://github.com/gigorok))
|
21
|
+
|
22
|
+
### 1.0.0 / 2020-11-06
|
23
|
+
|
24
|
+
[full changelog](http://github.com/yolk/valvat/compare/v0.9.1...v1.0.0)
|
25
|
+
|
26
|
+
* Refactored lookup to use specific rescue for savons soapfaults
|
27
|
+
* Raises vies specific error classes to help debugging temporary and permanent VIES errors
|
28
|
+
* Lookup#validate supports :savon option to allow altering the behaviour of the used savon client
|
29
|
+
* ActiveModel validator now supports all lookup options.
|
30
|
+
* Use https instead of http for accessing vies (by [Crazy Chris](https://github.com/lubekpl))
|
31
|
+
* Lookup#validate supports :raise_error option to return nil instead of raising (known) error when connecting to the VIES web service.
|
32
|
+
* [BUGFIX] Checksum: Prevent error on some invalid IE vat numbers
|
33
|
+
* EN: Capitalized VAT in error messages (and specs) (by [Vitalii Kashoid](https://github.com/Kashoid23))
|
34
|
+
|
35
|
+
### 0.9.1 / 2020-03-19
|
36
|
+
|
37
|
+
[full changelog](http://github.com/yolk/valvat/compare/v0.9.0...v0.9.1)
|
38
|
+
|
39
|
+
* Follow redirects to fix alteration of VIES-API (by [xxswingxx](https://github.com/xxswingxx))
|
40
|
+
|
41
|
+
### 0.9.0 / 2020-02-28
|
42
|
+
|
43
|
+
[full changelog](http://github.com/yolk/valvat/compare/v0.8.2...v0.9.0)
|
44
|
+
|
45
|
+
* Validate new dutch 2020 vat identification number (by [yvonnenieuwerth](https://github.com/yvonnenieuwerth))
|
46
|
+
* Set the country adjectives to masculine in FR locales (by [bobmaerten](https://github.com/bobmaerten))
|
47
|
+
* Fix greek country adjectif in french (by [bobmaerten](https://github.com/bobmaerten))
|
4
48
|
|
5
49
|
### 0.8.2 / 2019-11-15
|
6
50
|
|
data/Gemfile
CHANGED
data/Guardfile
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
watch(
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
guard :rspec, cmd: 'bundle exec rspec --color' do
|
4
|
+
watch(%r{^spec/(.*)_spec.rb})
|
5
|
+
watch(%r{^lib/(.*)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
|
6
|
+
watch(%r{^spec/spec_helper.rb}) { 'spec' }
|
5
7
|
end
|
data/README.md
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
valvat
|
2
2
|
===========
|
3
3
|
|
4
|
-
[![
|
4
|
+
[![rubygems](https://badgen.net/rubygems/v/valvat)](https://rubygems.org/gems/valvat) [![Specs](https://github.com/yolk/valvat/workflows/Specs/badge.svg)](https://github.com/yolk/valvat/actions?query=workflow%3ASpecs)
|
5
5
|
|
6
6
|
Validates european vat numbers. Standalone or as a ActiveModel validator.
|
7
7
|
|
8
|
+
## A note on Brexit
|
9
|
+
|
10
|
+
Valvat supports validating VAT-IDs from the UK by syntax & checksum for now. Validation against the VIES web service will probably stop working (and return `false`) in 2021.
|
11
|
+
|
12
|
+
Northern Ireland received its own VAT number prefix - XI which is supported by VIES web service so any XI-prefixed VAT numbers should be validated as any EU VAT number.
|
13
|
+
|
8
14
|
## Features
|
9
15
|
|
10
16
|
* Simple syntax verification
|
@@ -14,7 +20,7 @@ Validates european vat numbers. Standalone or as a ActiveModel validator.
|
|
14
20
|
* I18n locales for language specific error messages in English, German, French, Spanish, Italian, Portuguese, Polish, Swedish, Dutch, Danish, Czech, Slovakian, Hungarian, Bulgarian, Romanian, Latvian, Catalan, Norwegian, and Finnish.
|
15
21
|
* *Experimental* checksum verification
|
16
22
|
|
17
|
-
valvat is tested and works with ruby MRI
|
23
|
+
valvat is tested and works with ruby MRI 2.5/2.6/2.7/3.0, jruby-head and ActiveModel 5/6. If you need support for ruby down to 1.9.3 and ActiveModel 3 and 4 use [v1.0.1](https://github.com/yolk/valvat/tree/v1.0.1).
|
18
24
|
|
19
25
|
## Installation
|
20
26
|
|
@@ -22,9 +28,9 @@ Add it to your Gemfile:
|
|
22
28
|
|
23
29
|
gem 'valvat'
|
24
30
|
|
25
|
-
To
|
31
|
+
To use less memory (~0.5 mb vs. ~3.5 mb) and load only the local verification functionality – and not the remote lookup with VIES – add it like this instead:
|
26
32
|
|
27
|
-
gem 'valvat', :
|
33
|
+
gem 'valvat', require: 'valvat/local'
|
28
34
|
|
29
35
|
In any case run:
|
30
36
|
|
@@ -34,72 +40,114 @@ Or install it yourself as:
|
|
34
40
|
|
35
41
|
$ gem install valvat
|
36
42
|
|
37
|
-
##
|
43
|
+
## Validate the syntax of a VAT number
|
38
44
|
|
39
45
|
To verify the syntax of a vat number:
|
40
46
|
|
41
47
|
Valvat.new("DE345789003").valid?
|
42
48
|
=> true or false
|
43
49
|
|
44
|
-
|
45
|
-
|
46
|
-
Valvat.new("DE345789003").exists?
|
47
|
-
=> true or false or nil
|
50
|
+
It is also possible to bypass initializing a Valvat instance and check the syntax of a vat number string directly with:
|
48
51
|
|
49
|
-
|
52
|
+
Valvat::Syntax.validate("DE345789003")
|
53
|
+
=> true or false
|
50
54
|
|
51
|
-
|
55
|
+
## Validate agains the VIES web service
|
52
56
|
|
53
|
-
|
57
|
+
To check if the given vat number exists via the VIES web service:
|
54
58
|
|
55
|
-
Valvat
|
56
|
-
=> true or false
|
59
|
+
Valvat.new("DE345789003").exists?
|
60
|
+
=> true or false or nil
|
57
61
|
|
58
62
|
Or to lookup a vat number string directly via VIES web service:
|
59
63
|
|
60
64
|
Valvat::Lookup.validate("DE345789003")
|
61
65
|
=> true or false or nil
|
62
66
|
|
63
|
-
|
64
|
-
|
65
|
-
valvat allows to check vat numbers from AT, BE, BG, DE, DK, ES, FR, FI, GR, IE, IT, LU, NL, PL, PT, SE and SI against a checksum calculation. All other countries will fall back to a simple syntax check:
|
67
|
+
*IMPORTANT* Keep in mind that the VIES web service might be offline at some time for all or some member states. If this happens `exists?` or `Valvat::Lookup.validate` will return `nil`. See *Handling of VIES maintenance errors* for further details.
|
66
68
|
|
67
|
-
|
68
|
-
=> true or false
|
69
|
-
|
70
|
-
These results are more valuable than a simple syntax check, but keep in mind: they can not replace a lookup via VIES.
|
71
|
-
|
72
|
-
*IMPORTANT* This feature was tested against all vat numbers I could get my hand on, but it is still marked as *experimental* because these calculations are not documented and may return wrong results.
|
73
|
-
|
74
|
-
To bypass initializing a Valvat instance:
|
69
|
+
### Details & request identifier
|
75
70
|
|
76
|
-
|
77
|
-
=> true or false
|
78
|
-
|
79
|
-
## Details & request identifier
|
80
|
-
|
81
|
-
If you need all details and not only if the VAT is valid, pass {:detail => true} as second parameter to the lookup call.
|
71
|
+
If you need all details and not only if the VAT is valid, pass {detail: true} as second parameter to the lookup call.
|
82
72
|
|
83
|
-
Valvat.new("IE6388047V").exists?(:
|
73
|
+
Valvat.new("IE6388047V").exists?(detail: true)
|
84
74
|
=> {
|
85
|
-
:country_code=>"IE", :vat_number => "6388047V",
|
75
|
+
:country_code=>"IE", :vat_number => "6388047V", :valid => true,
|
86
76
|
:request_date => Date.today, :name=>"GOOGLE IRELAND LIMITED",
|
87
77
|
:address=>"1ST & 2ND FLOOR ,GORDON HOUSE ,BARROW STREET ,DUBLIN 4"
|
88
78
|
} or false or nil
|
89
79
|
|
90
|
-
According to EU law, or at least as Austria sees it, it's mandatory to verify the
|
80
|
+
According to EU law, or at least as Austria sees it, it's mandatory to verify the VAT number of every new customer, but also to check the VAT number periodicaly. To prove that you have checked the VAT number, the VIES Web service can return a `request_identifier`.
|
91
81
|
|
92
|
-
To receive a
|
82
|
+
To receive a `request_identifier` you need to pass your own VAT number in the options hash. In this example, Google (VAT IE6388047V) is checking the validity of eBays VAT number (LU21416127)
|
93
83
|
|
94
|
-
Valvat.new("LU21416127").exists?(:
|
84
|
+
Valvat.new("LU21416127").exists?(requester: "IE6388047V")
|
95
85
|
=> {
|
96
|
-
:country_code=>"LU", :vat_number => "21416127",
|
86
|
+
:country_code=>"LU", :vat_number => "21416127", :valid => true,
|
97
87
|
:request_date => Date.today, :name=>"EBAY EUROPE S.A R.L.",
|
98
88
|
:address => "22, BOULEVARD ROYAL\nL-2449 LUXEMBOURG",
|
99
89
|
:company_type => nil, :request_identifier => "some_uniq_string"
|
100
90
|
} or false or nil
|
101
91
|
|
102
|
-
|
92
|
+
If the given `requester` is invalid, a `Valvat::InvalidRequester` error is thrown.
|
93
|
+
|
94
|
+
### Handling of VIES maintenance errors
|
95
|
+
|
96
|
+
From time to time the VIES web service for one or all member states is down for maintenance. To handle this kind of temporary errors, `Valvat::Lookup#validate` returns `nil` by default to indicate that there is no way at the moment to say if the given VAT is valid or not. You should revalidate the VAT later. If you prefer an error, use the `raise_error` option:
|
97
|
+
|
98
|
+
Valvat.new("IE6388047V").exists?(raise_error: true)
|
99
|
+
|
100
|
+
This raises `Valvat::ServiceUnavailable` or `Valvat::MemberStateUnavailable` instead of returning `nil`.
|
101
|
+
|
102
|
+
Visit [http://ec.europa.eu/taxation_customs/vies/viesspec.do](http://ec.europa.eu/taxation_customs/vies/viesspec.do) for more accurate information at what time the service for a specific member state will be down.
|
103
|
+
|
104
|
+
### Handling of other VIES errors
|
105
|
+
|
106
|
+
All other errors accuring while validating against the VIES web service are raised and must be handled by you. These include:
|
107
|
+
|
108
|
+
* `Valvat::InvalidRequester`
|
109
|
+
* `Valvat::BlockedError`
|
110
|
+
* `Valvat::RateLimitError`
|
111
|
+
* `Valvat::Timeout`
|
112
|
+
* all IO errors
|
113
|
+
|
114
|
+
If you want to suppress all known error cases. Pass in the `raise_error` option set to `false`:
|
115
|
+
|
116
|
+
Valvat.new("IE6388047V").exists?(raise_error: false)
|
117
|
+
|
118
|
+
This will return `nil` instead of raising a known error.
|
119
|
+
|
120
|
+
### Set options for the savon client
|
121
|
+
|
122
|
+
Use the `:savon` key to set options for the used savon SOAP client. For example to log all requests:
|
123
|
+
|
124
|
+
Valvat.new("IE6388047V").exists?(savon: {log: true})
|
125
|
+
|
126
|
+
Or to use higher timeouts for the requests:
|
127
|
+
|
128
|
+
Valvat.new("IE6388047V").exists?(savon: {open_timeout: 10, read_timeout: 10})
|
129
|
+
|
130
|
+
### Skip local validation before lookup
|
131
|
+
|
132
|
+
To prevent unnecessary requests, valvat performs a local syntax check before making the request to the VIES web service. If you want to skip this step (for any reason), set the `:skip_local_validation` option to `true`.
|
133
|
+
|
134
|
+
## Experimental checksum verification
|
135
|
+
|
136
|
+
valvat allows to check vat numbers from AT, BE, BG, DE, DK, ES, FR, FI, GR, IE, IT, LU, NL, PL, PT, SE and SI against a checksum calculation. All other member states will fall back to a basic syntax check:
|
137
|
+
|
138
|
+
Valvat.new("DE345789003").valid_checksum?
|
139
|
+
=> true or false
|
140
|
+
|
141
|
+
These results are more valuable than a simple syntax check, but keep in mind: they can not replace a lookup via VIES.
|
142
|
+
|
143
|
+
*IMPORTANT* This feature was tested against all vat numbers I could get my hand on, but it is still marked as *experimental* because these calculations are not documented and may return wrong results.
|
144
|
+
|
145
|
+
To bypass initializing a Valvat instance:
|
146
|
+
|
147
|
+
Valvat::Checksum.validate("DE345789003")
|
148
|
+
=> true or false
|
149
|
+
|
150
|
+
## Usage with ActiveModel / Rails
|
103
151
|
|
104
152
|
### Loading
|
105
153
|
|
@@ -114,30 +162,34 @@ after ActiveModel has been loaded.
|
|
114
162
|
To validate the attribute `vat_number` add this to your model:
|
115
163
|
|
116
164
|
class MyModel < ActiveRecord::Base
|
117
|
-
validates :vat_number, :
|
165
|
+
validates :vat_number, valvat: true
|
118
166
|
end
|
119
167
|
|
120
168
|
### Additional lookup validation
|
121
169
|
|
122
170
|
To additionally perform a lookup via VIES:
|
123
171
|
|
124
|
-
validates :vat_number, :
|
172
|
+
validates :vat_number, valvat: {lookup: true}
|
125
173
|
|
126
174
|
By default this will validate to true if the VIES web service is down. To fail in this case simply add the `:fail_if_down` option:
|
127
175
|
|
128
|
-
validates :vat_number, :
|
176
|
+
validates :vat_number, valvat: {lookup: {fail_if_down: true}}
|
177
|
+
|
178
|
+
You can pass in any options accepted by `Valvat::Lookup#validate`:
|
179
|
+
|
180
|
+
validates :vat_number, valvat: {lookup: {raise_error: true, savon: {log: true}}}
|
129
181
|
|
130
182
|
### Additional (and experimental) checksum validation
|
131
183
|
|
132
184
|
To additionally perform a checksum validation:
|
133
185
|
|
134
|
-
validates :vat_number, :
|
186
|
+
validates :vat_number, valvat: {checksum: true}
|
135
187
|
|
136
188
|
### Additional ISO country code validation
|
137
189
|
|
138
190
|
If you want the vat number’s (ISO) country to match another country attribute, use the _match_country_ option:
|
139
191
|
|
140
|
-
validates :vat_number, :
|
192
|
+
validates :vat_number, valvat: {match_country: :country}
|
141
193
|
|
142
194
|
where it is supposed that your model has a method named _country_ which returns the country ISO code you want to match.
|
143
195
|
|
@@ -145,17 +197,17 @@ where it is supposed that your model has a method named _country_ which returns
|
|
145
197
|
|
146
198
|
By default blank vat numbers validate to false. To change this add the `:allow_blank` option:
|
147
199
|
|
148
|
-
validates :vat_number, :
|
200
|
+
validates :vat_number, valvat: {allow_blank: true}
|
149
201
|
|
150
202
|
### Allow vat numbers outside of europe
|
151
203
|
|
152
204
|
To allow vat numbers from outside of europe, add something like this to your model (country_code should return a upcase ISO country code):
|
153
205
|
|
154
206
|
class MyModel < ActiveRecord::Base
|
155
|
-
validates :vat_number, :
|
207
|
+
validates :vat_number, valvat: true, if: :eu?
|
156
208
|
|
157
209
|
def eu?
|
158
|
-
Valvat::Utils::
|
210
|
+
Valvat::Utils::EU_MEMBER_STATES.include?(country_code)
|
159
211
|
end
|
160
212
|
end
|
161
213
|
|
@@ -206,7 +258,7 @@ https://github.com/yolk/valvat/graphs/contributors
|
|
206
258
|
|
207
259
|
## BlaBla
|
208
260
|
|
209
|
-
Copyright (c) 2011-
|
261
|
+
Copyright (c) 2011-2020 Yolk Sebastian Munz & Julia Soergel GbR
|
210
262
|
|
211
263
|
Beyond that, the implementation is licensed under the MIT License.
|
212
264
|
|
data/Rakefile
CHANGED
data/certs/yolk.pem
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
-----BEGIN CERTIFICATE-----
|
2
2
|
MIIELDCCApSgAwIBAgIBATANBgkqhkiG9w0BAQsFADAgMR4wHAYDVQQDDBVzZWJh
|
3
|
-
|
3
|
+
c3RpYW4vREM9eW8vREM9bGswHhcNMjEwMTA2MTAzMDU3WhcNMjIwMTA2MTAzMDU3
|
4
4
|
WjAgMR4wHAYDVQQDDBVzZWJhc3RpYW4vREM9eW8vREM9bGswggGiMA0GCSqGSIb3
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
5
|
+
DQEBAQUAA4IBjwAwggGKAoIBgQC1KB7VOGa6pr926eaL2xCrnbnTxadpjq+6JoFj
|
6
|
+
6rvDpmgD8wkdfU7aFTwBiEK9JKzhqCoW86Rt/8wOrEJRMXz1QBbpMBSrubtMB+0/
|
7
|
+
N59hKPLwgBkhbxY7BwGnujxnTICgiGzkhjlgBe/MisoabfK5Tn84GWVk5e0/LUp1
|
8
|
+
qTRkSgcaDlnKs2/dAUo1lXHa13TJeemgz76TYx4p4J2w7VGh7WS2ax5SNWKw+J+q
|
9
|
+
HVSHT2Chc+a7As2cJyU/r2jX0oqSfvyg09CmF0inUBykeiuB9aeP/Me29hvg13/D
|
10
|
+
r1gaQ3/Vyfuqjs8lrwIZCWLU607g5q3+UM884WWpvApsZwzajNM2+9l5jay7Dnan
|
11
|
+
m05PcDtMYbPHiMyvuN9Vp4YIRqSBXP/DPGMnIYXbpzAQgtZymPQ8I3k8doj9q4+E
|
12
|
+
2Cf+x/nqvF09r/+gJj4ybzNW23zU6mhZ+xzBTDWrWBDetz+Y3wdbU5X6j08jLuEg
|
13
|
+
mMHmtgFdr/4VQxeaon7kHPR3DUsCAwEAAaNxMG8wCQYDVR0TBAIwADALBgNVHQ8E
|
14
|
+
BAMCBLAwHQYDVR0OBBYEFG8VE8+yijOldghb3w0MpSQnrslxMBoGA1UdEQQTMBGB
|
15
15
|
D3NlYmFzdGlhbkB5by5sazAaBgNVHRIEEzARgQ9zZWJhc3RpYW5AeW8ubGswDQYJ
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
-----END CERTIFICATE-----
|
16
|
+
KoZIhvcNAQELBQADggGBAIky67U9hnB8d4qMKwXHGb3Ne7JLvEigtEhjqGlDVecb
|
17
|
+
C94vQ8Jg7lYB3kKVjvFN2drptq/JUpxmAxPQIqfx39gKcKyv0BjkroVFE8MS1324
|
18
|
+
khMOZFOoSPMd9pkpm7oJ1M+sCYcUM+tPKnU8Ojq6r9j5b5XrbxG8YSpwahva3Vap
|
19
|
+
1g0+3KzuWPpFjFen1VbS/Sb1cyE5uQtUj7lVcdhF3EFvzXkUMUUtJ4xsk114znFO
|
20
|
+
986sKab5AjlJ7TnsmPphCv/UXans7rAVB2lnozlt/kw6dcct5JD4kz1tD6AmO5Qd
|
21
|
+
jWRuKNZs66GBglRvseKoypXz1XDCCu1m/uI1IGmKnq8Ry+IeRq9RnlvbfPvSxRIx
|
22
|
+
9aowoL79T9plhcEcEX/KYRp8ht1z+3Vyk2UVZP8Xl5x+K44co5xdhljYi1gtw0w8
|
23
|
+
KzzULF0bF9oNpXwBEamlH2myNb19u1W8ijobQ7Y19ca8UFHr5LI32ZW5Zlmep8je
|
24
|
+
vb+o07oLRx3t2T/EO4DZ1w==
|
25
|
+
-----END CERTIFICATE-----
|