valvat 0.9.1 → 1.0.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/.gitignore +2 -1
- data/.travis.yml +30 -16
- data/CHANGES.md +13 -0
- data/Gemfile +2 -3
- data/README.md +90 -44
- data/gemfiles/activemodel-3-2 +3 -4
- data/gemfiles/activemodel-4 +3 -4
- data/gemfiles/activemodel-5 +4 -5
- data/gemfiles/activemodel-6 +7 -0
- data/gemfiles/before-ruby21/activemodel-3-2 +3 -4
- data/gemfiles/before-ruby21/activemodel-4 +3 -4
- data/gemfiles/before-ruby21/standalone +3 -4
- data/gemfiles/standalone +3 -5
- data/lib/active_model/validations/valvat_validator.rb +20 -5
- data/lib/valvat.rb +3 -1
- data/lib/valvat/checksum/gb.rb +30 -13
- data/lib/valvat/checksum/ie.rb +1 -1
- data/lib/valvat/error.rb +28 -0
- data/lib/valvat/locales/en.yml +1 -1
- data/lib/valvat/lookup.rb +11 -43
- data/lib/valvat/lookup/fault.rb +30 -0
- data/lib/valvat/lookup/request.rb +33 -12
- data/lib/valvat/lookup/response.rb +36 -0
- data/lib/valvat/version.rb +1 -1
- data/spec/active_model/validations/valvat_validator_spec.rb +66 -66
- data/spec/valvat/checksum/at_spec.rb +2 -2
- data/spec/valvat/checksum/be_spec.rb +2 -2
- data/spec/valvat/checksum/bg_spec.rb +2 -2
- data/spec/valvat/checksum/cy_spec.rb +2 -2
- data/spec/valvat/checksum/de_spec.rb +2 -2
- data/spec/valvat/checksum/dk_spec.rb +2 -2
- data/spec/valvat/checksum/ee_spec.rb +2 -2
- data/spec/valvat/checksum/es_spec.rb +2 -2
- data/spec/valvat/checksum/fi_spec.rb +2 -2
- data/spec/valvat/checksum/fr_spec.rb +2 -2
- data/spec/valvat/checksum/gb_spec.rb +5 -3
- data/spec/valvat/checksum/gr_spec.rb +2 -2
- data/spec/valvat/checksum/hr_spec.rb +2 -2
- data/spec/valvat/checksum/hu_spec.rb +2 -2
- data/spec/valvat/checksum/ie_spec.rb +8 -2
- data/spec/valvat/checksum/it_spec.rb +4 -4
- data/spec/valvat/checksum/lt_spec.rb +2 -2
- data/spec/valvat/checksum/lu_spec.rb +2 -2
- data/spec/valvat/checksum/mt_spec.rb +2 -2
- data/spec/valvat/checksum/nl_spec.rb +2 -2
- data/spec/valvat/checksum/pl_spec.rb +3 -3
- data/spec/valvat/checksum/pt_spec.rb +2 -2
- data/spec/valvat/checksum/ro_spec.rb +2 -2
- data/spec/valvat/checksum/se_spec.rb +3 -3
- data/spec/valvat/checksum/si_spec.rb +4 -4
- data/spec/valvat/checksum_spec.rb +2 -2
- data/spec/valvat/lockup/fault_spec.rb +32 -0
- data/spec/valvat/lockup/request_spec.rb +15 -0
- data/spec/valvat/lockup/response_spec.rb +27 -0
- data/spec/valvat/lookup_spec.rb +168 -35
- data/spec/valvat/syntax_spec.rb +29 -29
- data/spec/valvat/utils_spec.rb +6 -6
- data/spec/valvat_spec.rb +18 -18
- data/valvat.gemspec +1 -0
- metadata +29 -6
- metadata.gz.sig +0 -0
- 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: 9b64b4bcee899d80f3c9205b541eeaf7123df7560e47528368bedc0e06d85f85
|
4
|
+
data.tar.gz: 31f18a7bf075a71c719002e3b34dd4a057da7ba85aeaf7283385d7ffc98f7dcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b419833c23922a653f932995541e25300a8897529cd3bfdea2078de762f5829451e35c1a658510cfbd64978f0f6165471d1331e1673d381ef5c0ecd6ca6380a
|
7
|
+
data.tar.gz: e595829c058d7b2b89a644b779c4ea95c66eb9d416e395a4b32cf4d28f73bcb717f55c720fe51dd8d027092c94ae04b3c094cd1e7fbf1fe95d833330851a37d5
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,33 +1,47 @@
|
|
1
1
|
language: ruby
|
2
|
+
cache: bundler
|
2
3
|
rvm:
|
4
|
+
- 2.7
|
3
5
|
- 2.6
|
4
6
|
- 2.5
|
5
7
|
- 2.4
|
6
8
|
- 2.3
|
7
9
|
- 2.2
|
8
10
|
- 2.1
|
11
|
+
- jruby-head
|
9
12
|
- jruby-19mode
|
10
13
|
gemfile:
|
14
|
+
- gemfiles/activemodel-6
|
11
15
|
- gemfiles/activemodel-5
|
12
16
|
- gemfiles/activemodel-4
|
13
17
|
- gemfiles/activemodel-3-2
|
14
18
|
- gemfiles/standalone
|
15
19
|
matrix:
|
16
20
|
exclude:
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
+
- rvm: 2.4
|
22
|
+
gemfile: gemfiles/activemodel-6
|
23
|
+
- rvm: 2.3
|
24
|
+
gemfile: gemfiles/activemodel-6
|
25
|
+
- rvm: 2.2
|
26
|
+
gemfile: gemfiles/activemodel-6
|
27
|
+
- rvm: 2.1
|
28
|
+
gemfile: gemfiles/activemodel-6
|
29
|
+
- rvm: jruby-19mode
|
30
|
+
gemfile: gemfiles/activemodel-6
|
31
|
+
- rvm: 2.1
|
32
|
+
gemfile: gemfiles/activemodel-5
|
33
|
+
- rvm: jruby-19mode
|
34
|
+
gemfile: gemfiles/activemodel-5
|
21
35
|
include:
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
36
|
+
- rvm: 2.0
|
37
|
+
gemfile: gemfiles/before-ruby21/activemodel-4
|
38
|
+
- rvm: 2.0
|
39
|
+
gemfile: gemfiles/before-ruby21/activemodel-3-2
|
40
|
+
- rvm: 2.0
|
41
|
+
gemfile: gemfiles/before-ruby21/standalone
|
42
|
+
- rvm: 1.9.3
|
43
|
+
gemfile: gemfiles/before-ruby21/activemodel-4
|
44
|
+
- rvm: 1.9.3
|
45
|
+
gemfile: gemfiles/before-ruby21/activemodel-3-2
|
46
|
+
- rvm: 1.9.3
|
47
|
+
gemfile: gemfiles/before-ruby21/standalone
|
data/CHANGES.md
CHANGED
@@ -3,6 +3,19 @@
|
|
3
3
|
|
4
4
|
[full changelog](http://github.com/yolk/valvat/compare/v0.9.1...master)
|
5
5
|
|
6
|
+
### 1.0.0 / 2020-11-06
|
7
|
+
|
8
|
+
[full changelog](http://github.com/yolk/valvat/compare/v0.9.1...v1.0.0)
|
9
|
+
|
10
|
+
* Refactored lookup to use specific rescue for savons soapfaults
|
11
|
+
* Raises vies specific error classes to help debugging temporary and permanent VIES errors
|
12
|
+
* Lookup#validate supports :savon option to allow altering the behaviour of the used savon client
|
13
|
+
* ActiveModel validator now supports all lookup options.
|
14
|
+
* Use https instead of http for accessing vies (by [Crazy Chris](https://github.com/lubekpl))
|
15
|
+
* Lookup#validate supports :raise_error option to return nil instead of raising (known) error when connecting to the VIES web service.
|
16
|
+
* [BUGFIX] Checksum: Prevent error on some invalid IE vat numbers
|
17
|
+
* EN: Capitalized VAT in error messages (and specs) (by [Vitalii Kashoid](https://github.com/Kashoid23))
|
18
|
+
|
6
19
|
### 0.9.1 / 2020-03-19
|
7
20
|
|
8
21
|
[full changelog](http://github.com/yolk/valvat/compare/v0.9.0...v0.9.1)
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -14,7 +14,7 @@ Validates european vat numbers. Standalone or as a ActiveModel validator.
|
|
14
14
|
* 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
15
|
* *Experimental* checksum verification
|
16
16
|
|
17
|
-
valvat is tested and works with ruby MRI 1.9.3/2.0/2.1/2.2/2.3/2.4/2.5/2.6, jruby (
|
17
|
+
valvat is tested and works with ruby MRI 1.9.3/2.0/2.1/2.2/2.3/2.4/2.5/2.6/2.7, jruby (including 1.9 mode) and ActiveModel 3/4/5/6
|
18
18
|
|
19
19
|
## Installation
|
20
20
|
|
@@ -24,7 +24,7 @@ Add it to your Gemfile:
|
|
24
24
|
|
25
25
|
To use less memory (~3.5 mb vs. ~0.5 mb) and load only the local verification functionality – and not the remote lookup with VIES – add it like this instead:
|
26
26
|
|
27
|
-
gem 'valvat', :
|
27
|
+
gem 'valvat', require: 'valvat/local'
|
28
28
|
|
29
29
|
In any case run:
|
30
30
|
|
@@ -34,72 +34,114 @@ Or install it yourself as:
|
|
34
34
|
|
35
35
|
$ gem install valvat
|
36
36
|
|
37
|
-
##
|
37
|
+
## Validate the syntax of a VAT number
|
38
38
|
|
39
39
|
To verify the syntax of a vat number:
|
40
40
|
|
41
41
|
Valvat.new("DE345789003").valid?
|
42
42
|
=> true or false
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
Valvat.new("DE345789003").exists?
|
47
|
-
=> true or false or nil
|
44
|
+
It is also possible to bypass initializing a Valvat instance and check the syntax of a vat number string directly with:
|
48
45
|
|
49
|
-
|
46
|
+
Valvat::Syntax.validate("DE345789003")
|
47
|
+
=> true or false
|
50
48
|
|
51
|
-
|
49
|
+
## Validate agains the VIES web service
|
52
50
|
|
53
|
-
|
51
|
+
To check if the given vat number exists via the VIES web service:
|
54
52
|
|
55
|
-
Valvat
|
56
|
-
=> true or false
|
53
|
+
Valvat.new("DE345789003").exists?
|
54
|
+
=> true or false or nil
|
57
55
|
|
58
56
|
Or to lookup a vat number string directly via VIES web service:
|
59
57
|
|
60
58
|
Valvat::Lookup.validate("DE345789003")
|
61
59
|
=> true or false or nil
|
62
60
|
|
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:
|
61
|
+
*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
62
|
|
67
|
-
|
68
|
-
=> true or false
|
63
|
+
### Details & request identifier
|
69
64
|
|
70
|
-
|
65
|
+
If you need all details and not only if the VAT is valid, pass {detail: true} as second parameter to the lookup call.
|
71
66
|
|
72
|
-
|
73
|
-
|
74
|
-
To bypass initializing a Valvat instance:
|
75
|
-
|
76
|
-
Valvat::Checksum.validate("DE345789003")
|
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.
|
82
|
-
|
83
|
-
Valvat.new("IE6388047V").exists?(:detail => true)
|
67
|
+
Valvat.new("IE6388047V").exists?(detail: true)
|
84
68
|
=> {
|
85
|
-
:country_code=>"IE", :vat_number => "6388047V",
|
69
|
+
:country_code=>"IE", :vat_number => "6388047V", :valid => true,
|
86
70
|
:request_date => Date.today, :name=>"GOOGLE IRELAND LIMITED",
|
87
71
|
:address=>"1ST & 2ND FLOOR ,GORDON HOUSE ,BARROW STREET ,DUBLIN 4"
|
88
72
|
} or false or nil
|
89
73
|
|
90
|
-
According to EU law, or at least as Austria sees it, it's mandatory to verify the
|
74
|
+
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
75
|
|
92
|
-
To receive a
|
76
|
+
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
77
|
|
94
|
-
Valvat.new("LU21416127").exists?(:
|
78
|
+
Valvat.new("LU21416127").exists?(requester: "IE6388047V")
|
95
79
|
=> {
|
96
|
-
:country_code=>"LU", :vat_number => "21416127",
|
80
|
+
:country_code=>"LU", :vat_number => "21416127", :valid => true,
|
97
81
|
:request_date => Date.today, :name=>"EBAY EUROPE S.A R.L.",
|
98
82
|
:address => "22, BOULEVARD ROYAL\nL-2449 LUXEMBOURG",
|
99
83
|
:company_type => nil, :request_identifier => "some_uniq_string"
|
100
84
|
} or false or nil
|
101
85
|
|
102
|
-
|
86
|
+
If the given `requester` is invalid, a `Valvat::InvalidRequester` error is thrown.
|
87
|
+
|
88
|
+
### Handling of VIES maintenance errors
|
89
|
+
|
90
|
+
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:
|
91
|
+
|
92
|
+
Valvat.new("IE6388047V").exists?(raise_error: true)
|
93
|
+
|
94
|
+
This raises `Valvat::ServiceUnavailable` or `Valvat::MemberStateUnavailable` instead of returning `nil`.
|
95
|
+
|
96
|
+
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.
|
97
|
+
|
98
|
+
### Handling of other VIES errors
|
99
|
+
|
100
|
+
All other errors accuring while validating against the VIES web service are raised and must be handled by you. These include:
|
101
|
+
|
102
|
+
* `Valvat::InvalidRequester`
|
103
|
+
* `Valvat::BlockedError`
|
104
|
+
* `Valvat::RateLimitError`
|
105
|
+
* `Valvat::Timeout`
|
106
|
+
* all IO errors
|
107
|
+
|
108
|
+
If you want to suppress all known error cases. Pass in the `raise_error` option set to `false`:
|
109
|
+
|
110
|
+
Valvat.new("IE6388047V").exists?(raise_error: false)
|
111
|
+
|
112
|
+
This will return `nil` instead of raising a known error.
|
113
|
+
|
114
|
+
### Set options for the savon client
|
115
|
+
|
116
|
+
Use the `:savon` key to set options for the used savon SOAP client. For example to log all requests:
|
117
|
+
|
118
|
+
Valvat.new("IE6388047V").exists?(savon: {log: true})
|
119
|
+
|
120
|
+
Or to use higher timeouts for the requests:
|
121
|
+
|
122
|
+
Valvat.new("IE6388047V").exists?(savon: {open_timeout: 10, read_timeout: 10})
|
123
|
+
|
124
|
+
### Skip local validation before lookup
|
125
|
+
|
126
|
+
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`.
|
127
|
+
|
128
|
+
## Experimental checksum verification
|
129
|
+
|
130
|
+
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:
|
131
|
+
|
132
|
+
Valvat.new("DE345789003").valid_checksum?
|
133
|
+
=> true or false
|
134
|
+
|
135
|
+
These results are more valuable than a simple syntax check, but keep in mind: they can not replace a lookup via VIES.
|
136
|
+
|
137
|
+
*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.
|
138
|
+
|
139
|
+
To bypass initializing a Valvat instance:
|
140
|
+
|
141
|
+
Valvat::Checksum.validate("DE345789003")
|
142
|
+
=> true or false
|
143
|
+
|
144
|
+
## Usage with ActiveModel / Rails
|
103
145
|
|
104
146
|
### Loading
|
105
147
|
|
@@ -114,30 +156,34 @@ after ActiveModel has been loaded.
|
|
114
156
|
To validate the attribute `vat_number` add this to your model:
|
115
157
|
|
116
158
|
class MyModel < ActiveRecord::Base
|
117
|
-
validates :vat_number, :
|
159
|
+
validates :vat_number, valvat: true
|
118
160
|
end
|
119
161
|
|
120
162
|
### Additional lookup validation
|
121
163
|
|
122
164
|
To additionally perform a lookup via VIES:
|
123
165
|
|
124
|
-
validates :vat_number, :
|
166
|
+
validates :vat_number, valvat: {lookup: true}
|
125
167
|
|
126
168
|
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
169
|
|
128
|
-
validates :vat_number, :
|
170
|
+
validates :vat_number, valvat: {lookup: {fail_if_down: true}}
|
171
|
+
|
172
|
+
You can pass in any options accepted by `Valvat::Lookup#validate`:
|
173
|
+
|
174
|
+
validates :vat_number, valvat: {lookup: {raise_error: true, savon: {log: true}}}
|
129
175
|
|
130
176
|
### Additional (and experimental) checksum validation
|
131
177
|
|
132
178
|
To additionally perform a checksum validation:
|
133
179
|
|
134
|
-
validates :vat_number, :
|
180
|
+
validates :vat_number, valvat: {checksum: true}
|
135
181
|
|
136
182
|
### Additional ISO country code validation
|
137
183
|
|
138
184
|
If you want the vat number’s (ISO) country to match another country attribute, use the _match_country_ option:
|
139
185
|
|
140
|
-
validates :vat_number, :
|
186
|
+
validates :vat_number, valvat: {match_country: :country}
|
141
187
|
|
142
188
|
where it is supposed that your model has a method named _country_ which returns the country ISO code you want to match.
|
143
189
|
|
@@ -145,14 +191,14 @@ where it is supposed that your model has a method named _country_ which returns
|
|
145
191
|
|
146
192
|
By default blank vat numbers validate to false. To change this add the `:allow_blank` option:
|
147
193
|
|
148
|
-
validates :vat_number, :
|
194
|
+
validates :vat_number, valvat: {allow_blank: true}
|
149
195
|
|
150
196
|
### Allow vat numbers outside of europe
|
151
197
|
|
152
198
|
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
199
|
|
154
200
|
class MyModel < ActiveRecord::Base
|
155
|
-
validates :vat_number, :
|
201
|
+
validates :vat_number, valvat: true, if: :eu?
|
156
202
|
|
157
203
|
def eu?
|
158
204
|
Valvat::Utils::EU_COUNTRIES.include?(country_code)
|
@@ -206,7 +252,7 @@ https://github.com/yolk/valvat/graphs/contributors
|
|
206
252
|
|
207
253
|
## BlaBla
|
208
254
|
|
209
|
-
Copyright (c) 2011-
|
255
|
+
Copyright (c) 2011-2020 Yolk Sebastian Munz & Julia Soergel GbR
|
210
256
|
|
211
257
|
Beyond that, the implementation is licensed under the MIT License.
|
212
258
|
|
data/gemfiles/activemodel-3-2
CHANGED
data/gemfiles/activemodel-4
CHANGED
data/gemfiles/activemodel-5
CHANGED