valvat 1.1.4 → 1.1.5
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/.github/workflows/ruby.yml +1 -1
- data/.rubocop.yml +3 -0
- data/CHANGES.md +9 -1
- data/README.md +115 -59
- data/gemfiles/activemodel-6 +3 -0
- data/gemfiles/activemodel-7 +3 -0
- data/gemfiles/standalone +3 -0
- data/lib/active_model/validations/valvat_validator.rb +1 -1
- data/lib/valvat/checksum/es.rb +1 -1
- data/lib/valvat/checksum/fr.rb +1 -1
- data/lib/valvat/checksum/hr.rb +1 -1
- data/lib/valvat/checksum/hu.rb +1 -1
- data/lib/valvat/lookup/fault.rb +20 -14
- data/lib/valvat/lookup/response.rb +1 -1
- data/lib/valvat/version.rb +1 -1
- data/spec/valvat/checksum/es_spec.rb +7 -0
- data/spec/valvat/lookup/request_spec.rb +2 -2
- data/spec/valvat/lookup_spec.rb +19 -15
- data/spec/valvat/utils_spec.rb +1 -1
- data/spec/valvat_spec.rb +12 -12
- data/valvat.gemspec +1 -0
- data.tar.gz.sig +0 -0
- metadata +4 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51672c127e1f949767059172b89bcadfc148888809889c8cd0b425031c002132
|
4
|
+
data.tar.gz: '04189c3b112baeff2001a6f5b6bdccb0de3052e66d05636e597fb6bde175e94c'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f330e05a5c50652036ed2b445884e202c72708d10210fd09528b3f54d54afe5de3acf59d84af4bea66aba76d0f98ee4d7464ce9c0399c80644257368b4880472
|
7
|
+
data.tar.gz: b730f20e4c950324d99111cb73add8dc833d56587554bc62fd39e6576bd6a41a914c4e68e1666a6ed1ed7bdc2b36881fc6e69b48ca30d02a76bd9e01a6e8b446
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/.github/workflows/ruby.yml
CHANGED
@@ -17,7 +17,7 @@ jobs:
|
|
17
17
|
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}
|
18
18
|
strategy:
|
19
19
|
matrix:
|
20
|
-
ruby-version: ['2.6', '2.7', '3.0', '3.1', '
|
20
|
+
ruby-version: ['2.6', '2.7', '3.0', '3.1', 'jruby-9.3.2.0']
|
21
21
|
gemfile: [ 'standalone', 'activemodel-5', 'activemodel-6', 'activemodel-7' ]
|
22
22
|
exclude:
|
23
23
|
- ruby-version: '3.0'
|
data/.rubocop.yml
CHANGED
data/CHANGES.md
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
|
2
2
|
### dev
|
3
3
|
|
4
|
-
[full changelog](http://github.com/yolk/valvat/compare/v1.1.
|
4
|
+
[full changelog](http://github.com/yolk/valvat/compare/v1.1.5...master)
|
5
|
+
|
6
|
+
### 1.1.5 / 2022-09-14
|
7
|
+
|
8
|
+
[full changelog](http://github.com/yolk/valvat/compare/v1.1.4...v1.1.5)
|
9
|
+
|
10
|
+
* Fixed natural person VAT checksum validation for ES #114 (by [Thomas Scalise](https://github.com/KirtashW17))
|
11
|
+
* Better (ruby) code blocks in README #113
|
12
|
+
* Minor internal syntax changes / refactorings
|
5
13
|
|
6
14
|
### 1.1.4 / 2022-05-05
|
7
15
|
|
data/README.md
CHANGED
@@ -20,17 +20,21 @@ Northern Ireland received its own VAT number prefix - XI which is supported by V
|
|
20
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.
|
21
21
|
* *Experimental* checksum verification
|
22
22
|
|
23
|
-
valvat is tested and works with ruby MRI 2.6/2.7/3.0/3.1, jruby
|
23
|
+
valvat is tested and works with ruby MRI 2.6/2.7/3.0/3.1, jruby and ActiveModel 5/6/7. 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).
|
24
24
|
|
25
25
|
## Installation
|
26
26
|
|
27
27
|
Add it to your Gemfile:
|
28
28
|
|
29
|
-
|
29
|
+
```ruby
|
30
|
+
gem 'valvat'
|
31
|
+
```
|
30
32
|
|
31
33
|
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:
|
32
34
|
|
33
|
-
|
35
|
+
```ruby
|
36
|
+
gem 'valvat', require: 'valvat/local'
|
37
|
+
```
|
34
38
|
|
35
39
|
In any case run:
|
36
40
|
|
@@ -44,25 +48,33 @@ Or install it yourself as:
|
|
44
48
|
|
45
49
|
To verify the syntax of a vat number:
|
46
50
|
|
47
|
-
|
48
|
-
|
51
|
+
```ruby
|
52
|
+
Valvat.new("DE345789003").valid?
|
53
|
+
# => true or false
|
54
|
+
```
|
49
55
|
|
50
56
|
It is also possible to bypass initializing a Valvat instance and check the syntax of a vat number string directly with:
|
51
57
|
|
52
|
-
|
53
|
-
|
58
|
+
```ruby
|
59
|
+
Valvat::Syntax.validate("DE345789003")
|
60
|
+
# => true or false
|
61
|
+
```
|
54
62
|
|
55
|
-
## Validate
|
63
|
+
## Validate against the VIES web service
|
56
64
|
|
57
65
|
To check if the given vat number exists via the VIES web service:
|
58
66
|
|
59
|
-
|
60
|
-
|
67
|
+
```ruby
|
68
|
+
Valvat.new("DE345789003").exists?
|
69
|
+
# => true or false or nil
|
70
|
+
```
|
61
71
|
|
62
72
|
Or to lookup a vat number string directly via VIES web service:
|
63
73
|
|
64
|
-
|
65
|
-
|
74
|
+
```ruby
|
75
|
+
Valvat::Lookup.validate("DE345789003")
|
76
|
+
# => true or false or nil
|
77
|
+
```
|
66
78
|
|
67
79
|
*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.
|
68
80
|
|
@@ -70,24 +82,28 @@ Or to lookup a vat number string directly via VIES web service:
|
|
70
82
|
|
71
83
|
If you need all details and not only if the VAT is valid, pass {detail: true} as second parameter to the lookup call.
|
72
84
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
85
|
+
```ruby
|
86
|
+
Valvat.new("IE6388047V").exists?(detail: true)
|
87
|
+
=> {
|
88
|
+
:country_code=>"IE", :vat_number => "6388047V", :valid => true,
|
89
|
+
:request_date => Date.today, :name=>"GOOGLE IRELAND LIMITED",
|
90
|
+
:address=>"1ST & 2ND FLOOR ,GORDON HOUSE ,BARROW STREET ,DUBLIN 4"
|
91
|
+
} or false or nil
|
92
|
+
```
|
79
93
|
|
80
94
|
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`.
|
81
95
|
|
82
96
|
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)
|
83
97
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
98
|
+
```ruby
|
99
|
+
Valvat.new("LU21416127").exists?(requester: "IE6388047V")
|
100
|
+
=> {
|
101
|
+
:country_code=>"LU", :vat_number => "21416127", :valid => true,
|
102
|
+
:request_date => Date.today, :name=>"EBAY EUROPE S.A R.L.",
|
103
|
+
:address => "22, BOULEVARD ROYAL\nL-2449 LUXEMBOURG",
|
104
|
+
:company_type => nil, :request_identifier => "some_uniq_string"
|
105
|
+
} or false or nil
|
106
|
+
```
|
91
107
|
|
92
108
|
If the given `requester` is invalid, a `Valvat::InvalidRequester` error is thrown.
|
93
109
|
|
@@ -95,7 +111,9 @@ If the given `requester` is invalid, a `Valvat::InvalidRequester` error is throw
|
|
95
111
|
|
96
112
|
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
113
|
|
98
|
-
|
114
|
+
```ruby
|
115
|
+
Valvat.new("IE6388047V").exists?(raise_error: true)
|
116
|
+
```
|
99
117
|
|
100
118
|
This raises `Valvat::ServiceUnavailable` or `Valvat::MemberStateUnavailable` instead of returning `nil`.
|
101
119
|
|
@@ -113,7 +131,9 @@ All other errors accuring while validating against the VIES web service are rais
|
|
113
131
|
|
114
132
|
If you want to suppress all known error cases. Pass in the `raise_error` option set to `false`:
|
115
133
|
|
116
|
-
|
134
|
+
```ruby
|
135
|
+
Valvat.new("IE6388047V").exists?(raise_error: false)
|
136
|
+
```
|
117
137
|
|
118
138
|
This will return `nil` instead of raising a known error.
|
119
139
|
|
@@ -121,11 +141,15 @@ This will return `nil` instead of raising a known error.
|
|
121
141
|
|
122
142
|
Use the `:savon` key to set options for the used savon SOAP client. For example to log all requests:
|
123
143
|
|
124
|
-
|
144
|
+
```ruby
|
145
|
+
Valvat.new("IE6388047V").exists?(savon: { log: true })
|
146
|
+
```
|
125
147
|
|
126
148
|
Or to use higher timeouts for the requests:
|
127
149
|
|
128
|
-
|
150
|
+
```ruby
|
151
|
+
Valvat.new("IE6388047V").exists?(savon: {open_timeout: 10, read_timeout: 10})
|
152
|
+
```
|
129
153
|
|
130
154
|
### Skip local validation before lookup
|
131
155
|
|
@@ -135,8 +159,10 @@ To prevent unnecessary requests, valvat performs a local syntax check before mak
|
|
135
159
|
|
136
160
|
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
161
|
|
138
|
-
|
139
|
-
|
162
|
+
```ruby
|
163
|
+
Valvat.new("DE345789003").valid_checksum?
|
164
|
+
# => true or false
|
165
|
+
```
|
140
166
|
|
141
167
|
These results are more valuable than a simple syntax check, but keep in mind: they can not replace a lookup via VIES.
|
142
168
|
|
@@ -144,8 +170,10 @@ These results are more valuable than a simple syntax check, but keep in mind: th
|
|
144
170
|
|
145
171
|
To bypass initializing a Valvat instance:
|
146
172
|
|
147
|
-
|
148
|
-
|
173
|
+
```ruby
|
174
|
+
Valvat::Checksum.validate("DE345789003")
|
175
|
+
# => true or false
|
176
|
+
```
|
149
177
|
|
150
178
|
## Usage with ActiveModel / Rails
|
151
179
|
|
@@ -153,7 +181,9 @@ To bypass initializing a Valvat instance:
|
|
153
181
|
|
154
182
|
When the valvat gem is required and ActiveModel is already loaded, everything will work fine out of the box. If your load order differs just add
|
155
183
|
|
156
|
-
|
184
|
+
```ruby
|
185
|
+
require 'active_model/validations/valvat_validator'
|
186
|
+
```
|
157
187
|
|
158
188
|
after ActiveModel has been loaded.
|
159
189
|
|
@@ -161,35 +191,47 @@ after ActiveModel has been loaded.
|
|
161
191
|
|
162
192
|
To validate the attribute `vat_number` add this to your model:
|
163
193
|
|
164
|
-
|
165
|
-
|
166
|
-
|
194
|
+
```ruby
|
195
|
+
class MyModel < ActiveRecord::Base
|
196
|
+
validates :vat_number, valvat: true
|
197
|
+
end
|
198
|
+
```
|
167
199
|
|
168
200
|
### Additional lookup validation
|
169
201
|
|
170
202
|
To additionally perform a lookup via VIES:
|
171
203
|
|
172
|
-
|
204
|
+
```ruby
|
205
|
+
validates :vat_number, valvat: { lookup: true }
|
206
|
+
```
|
173
207
|
|
174
208
|
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:
|
175
209
|
|
176
|
-
|
210
|
+
```ruby
|
211
|
+
validates :vat_number, valvat: { lookup: { fail_if_down: true } }
|
212
|
+
```
|
177
213
|
|
178
214
|
You can pass in any options accepted by `Valvat::Lookup#validate`:
|
179
215
|
|
180
|
-
|
216
|
+
```ruby
|
217
|
+
validates :vat_number, valvat: { lookup: { raise_error: true, savon: { log: true } } }
|
218
|
+
```
|
181
219
|
|
182
220
|
### Additional (and experimental) checksum validation
|
183
221
|
|
184
222
|
To additionally perform a checksum validation:
|
185
223
|
|
186
|
-
|
224
|
+
```ruby
|
225
|
+
validates :vat_number, valvat: { checksum: true }
|
226
|
+
```
|
187
227
|
|
188
228
|
### Additional ISO country code validation
|
189
229
|
|
190
230
|
If you want the vat number’s (ISO) country to match another country attribute, use the _match_country_ option:
|
191
231
|
|
192
|
-
|
232
|
+
```ruby
|
233
|
+
validates :vat_number, valvat: { match_country: :country }
|
234
|
+
```
|
193
235
|
|
194
236
|
where it is supposed that your model has a method named _country_ which returns the country ISO code you want to match.
|
195
237
|
|
@@ -197,48 +239,62 @@ where it is supposed that your model has a method named _country_ which returns
|
|
197
239
|
|
198
240
|
By default blank vat numbers validate to false. To change this add the `:allow_blank` option:
|
199
241
|
|
200
|
-
|
242
|
+
```ruby
|
243
|
+
validates :vat_number, valvat: { allow_blank: true }
|
244
|
+
```
|
201
245
|
|
202
246
|
### Allow vat numbers outside of europe
|
203
247
|
|
204
248
|
To allow vat numbers from outside of europe, add something like this to your model (country_code should return a upcase ISO country code):
|
205
249
|
|
206
|
-
|
207
|
-
|
250
|
+
```ruby
|
251
|
+
class MyModel < ActiveRecord::Base
|
252
|
+
validates :vat_number, valvat: true, if: :eu?
|
208
253
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
254
|
+
def eu?
|
255
|
+
Valvat::Utils::EU_MEMBER_STATES.include?(country_code)
|
256
|
+
end
|
257
|
+
end
|
258
|
+
```
|
213
259
|
|
214
260
|
## Utilities
|
215
261
|
|
216
262
|
To split a vat number into the country code and the remaining chars:
|
217
263
|
|
218
|
-
|
219
|
-
|
264
|
+
```ruby
|
265
|
+
Valvat::Utils.split("ATU345789003")
|
266
|
+
# => ["AT", "U345789003"]
|
267
|
+
```
|
220
268
|
|
221
269
|
or
|
222
270
|
|
223
|
-
|
224
|
-
|
271
|
+
```ruby
|
272
|
+
Valvat.new("ATU345789003").to_a
|
273
|
+
# => ["AT", "U345789003"]
|
274
|
+
```
|
225
275
|
|
226
276
|
Both methods always return an array. If it can not detect the country or the given country is located outside of europe it returns `[nil, nil]`. Please note that this does not strictly return the ISO country code: for greek vat numbers this returns the ISO language code 'EL' instead of the ISO country code 'GR'.
|
227
277
|
|
228
278
|
To extract the ISO country code of a given vat number:
|
229
279
|
|
230
|
-
|
231
|
-
|
280
|
+
```ruby
|
281
|
+
Valvat.new("EL7345789003").iso_country_code
|
282
|
+
# => "GR"
|
283
|
+
```
|
232
284
|
|
233
285
|
To extract the vat country code (first two chars in every european vat number):
|
234
286
|
|
235
|
-
|
236
|
-
|
287
|
+
```ruby
|
288
|
+
Valvat.new("EL7345789003").vat_country_code
|
289
|
+
# => "EL"
|
290
|
+
```
|
237
291
|
|
238
292
|
To normalize a vat number:
|
239
293
|
|
240
|
-
|
241
|
-
|
294
|
+
```ruby
|
295
|
+
Valvat::Utils.normalize("atu345789003")
|
296
|
+
# => "ATU345789003"
|
297
|
+
```
|
242
298
|
|
243
299
|
This basically just removes trailing spaces and ensures all chars are uppercase.
|
244
300
|
|
data/gemfiles/activemodel-6
CHANGED
data/gemfiles/activemodel-7
CHANGED
data/gemfiles/standalone
CHANGED
@@ -74,7 +74,7 @@ module ActiveModel
|
|
74
74
|
message: options[:message],
|
75
75
|
country_adjective: I18n.translate(
|
76
76
|
:"valvat.country_adjectives.#{iso_country_code.downcase}",
|
77
|
-
default: [:
|
77
|
+
default: [:'valvat.country_adjectives.eu', 'european']
|
78
78
|
))
|
79
79
|
end
|
80
80
|
|
data/lib/valvat/checksum/es.rb
CHANGED
@@ -4,7 +4,7 @@ class Valvat
|
|
4
4
|
module Checksum
|
5
5
|
class ES < Base
|
6
6
|
NATURAL_PERSON_CHARS = %w[T R W A G M Y F P D X B N J Z S Q V H L C K E].freeze
|
7
|
-
NATURAL_PERSON_EXP = /\A(
|
7
|
+
NATURAL_PERSON_EXP = /\A([KLMXYZ\d])/.freeze
|
8
8
|
LEGAL_PERSON_CHARS = [false] + %w[A B C D E F G H I J]
|
9
9
|
LEGAL_PERSON_EXP = /\A[NPQRSW]\d{7}[ABCDEFGHIJ]\Z/.freeze
|
10
10
|
NIE_DIGIT_BY_LETTER = %w[X Y Z].freeze
|
data/lib/valvat/checksum/fr.rb
CHANGED
data/lib/valvat/checksum/hr.rb
CHANGED
data/lib/valvat/checksum/hu.rb
CHANGED
data/lib/valvat/lookup/fault.rb
CHANGED
@@ -5,20 +5,13 @@ class Valvat
|
|
5
5
|
class Fault < Response
|
6
6
|
def to_hash
|
7
7
|
@to_hash ||= case @raw
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
if fault == 'INVALID_INPUT'
|
16
|
-
{ valid: false }
|
17
|
-
else
|
18
|
-
error = (FAULTS[fault] || UnknownViesError).new(fault)
|
19
|
-
{ error: error }
|
20
|
-
end
|
21
|
-
end
|
8
|
+
when Savon::HTTPError
|
9
|
+
{ error: HTTPError.new(nil, @raw) }
|
10
|
+
when Savon::UnknownOperationError
|
11
|
+
{ error: OperationUnknown.new(nil, @raw) }
|
12
|
+
else
|
13
|
+
soap_fault
|
14
|
+
end
|
22
15
|
end
|
23
16
|
|
24
17
|
FAULTS = {
|
@@ -33,6 +26,19 @@ class Valvat
|
|
33
26
|
'MS_MAX_CONCURRENT_REQ' => RateLimitError,
|
34
27
|
'MS_MAX_CONCURRENT_REQ_TIME' => RateLimitError
|
35
28
|
}.freeze
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def soap_fault
|
33
|
+
fault = @raw.to_hash[:fault][:faultstring]
|
34
|
+
|
35
|
+
if fault == 'INVALID_INPUT'
|
36
|
+
{ valid: false }
|
37
|
+
else
|
38
|
+
error = (FAULTS[fault] || UnknownViesError).new(fault)
|
39
|
+
{ error: error }
|
40
|
+
end
|
41
|
+
end
|
36
42
|
end
|
37
43
|
end
|
38
44
|
end
|
@@ -19,7 +19,7 @@ class Valvat
|
|
19
19
|
(
|
20
20
|
hash[:check_vat_approx_response] || hash[:check_vat_response] || {}
|
21
21
|
).each_with_object({}) do |(key, value), result|
|
22
|
-
result[cleanup_key(key)] = cleanup_value(value) unless key ==
|
22
|
+
result[cleanup_key(key)] = cleanup_value(value) unless key == :@xmlns
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
data/lib/valvat/version.rb
CHANGED
@@ -15,4 +15,11 @@ describe Valvat::Checksum::ES do
|
|
15
15
|
expect(Valvat::Checksum.validate(invalid_vat)).to be(false)
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
19
|
+
describe 'if starts with [KLMXYZ\\d], is always a natural person' do
|
20
|
+
invalid_vat = 'ESX65474207'
|
21
|
+
it "returns false on invalid VAT #{invalid_vat}" do
|
22
|
+
expect(Valvat::Checksum.validate(invalid_vat)).to be(false)
|
23
|
+
end
|
24
|
+
end
|
18
25
|
end
|
@@ -19,12 +19,12 @@ describe Valvat::Lookup::Request do
|
|
19
19
|
|
20
20
|
context 'when Savon::UnknownOperationError is (wrongly) thrown' do
|
21
21
|
before do
|
22
|
-
dbl =
|
22
|
+
dbl = instance_double(Savon::Client)
|
23
23
|
allow(Savon::Client).to receive(:new).and_return(dbl)
|
24
24
|
allow(dbl).to receive(:call).and_raise(Savon::UnknownOperationError.new('from stub'))
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
27
|
+
it 'does handle it like vies down' do
|
28
28
|
response = described_class.new('IE6388047V', {}).perform
|
29
29
|
expect(response.to_hash[:error]).to be_a(Valvat::OperationUnknown)
|
30
30
|
end
|
data/spec/valvat/lookup_spec.rb
CHANGED
@@ -36,6 +36,7 @@ describe Valvat::Lookup do
|
|
36
36
|
context 'with details' do
|
37
37
|
let(:details) do
|
38
38
|
{
|
39
|
+
'@xmlns:ns2': 'urn:ec.europa.eu:taxud:vies:services:checkVat:types',
|
39
40
|
country_code: 'IE',
|
40
41
|
vat_number: '6388047V',
|
41
42
|
name: 'GOOGLE IRELAND LIMITED',
|
@@ -64,6 +65,7 @@ describe Valvat::Lookup do
|
|
64
65
|
let(:response) { described_class.validate('IE6388047V', requester: 'IE6388047V') }
|
65
66
|
let(:details) do
|
66
67
|
{
|
68
|
+
'@xmlns:ns2': 'urn:ec.europa.eu:taxud:vies:services:checkVat:types',
|
67
69
|
country_code: 'IE',
|
68
70
|
vat_number: '6388047V',
|
69
71
|
name: 'GOOGLE IRELAND LIMITED',
|
@@ -132,7 +134,7 @@ describe Valvat::Lookup do
|
|
132
134
|
subject(:result) { described_class.validate('DE300', options) }
|
133
135
|
|
134
136
|
it 'returns nil' do
|
135
|
-
expect(result).to
|
137
|
+
expect(result).to be_nil
|
136
138
|
end
|
137
139
|
|
138
140
|
it 'raises error with raise_error: true' do
|
@@ -146,7 +148,7 @@ describe Valvat::Lookup do
|
|
146
148
|
subject(:result) { described_class.validate('DE301', options) }
|
147
149
|
|
148
150
|
it 'returns nil' do
|
149
|
-
expect(result).to
|
151
|
+
expect(result).to be_nil
|
150
152
|
end
|
151
153
|
|
152
154
|
it 'raises error with raise_error: true' do
|
@@ -164,7 +166,7 @@ describe Valvat::Lookup do
|
|
164
166
|
end
|
165
167
|
|
166
168
|
it 'returns nil with raise_error set to false' do
|
167
|
-
expect(described_class.validate('DE302', options.merge(raise_error: false))).to
|
169
|
+
expect(described_class.validate('DE302', options.merge(raise_error: false))).to be_nil
|
168
170
|
end
|
169
171
|
end
|
170
172
|
|
@@ -176,7 +178,7 @@ describe Valvat::Lookup do
|
|
176
178
|
end
|
177
179
|
|
178
180
|
it 'returns nil with raise_error set to false' do
|
179
|
-
expect(described_class.validate('DE400', options.merge(raise_error: false))).to
|
181
|
+
expect(described_class.validate('DE400', options.merge(raise_error: false))).to be_nil
|
180
182
|
end
|
181
183
|
end
|
182
184
|
|
@@ -188,7 +190,7 @@ describe Valvat::Lookup do
|
|
188
190
|
end
|
189
191
|
|
190
192
|
it 'returns nil with raise_error set to false' do
|
191
|
-
expect(described_class.validate('DE401', options.merge(raise_error: false))).to
|
193
|
+
expect(described_class.validate('DE401', options.merge(raise_error: false))).to be_nil
|
192
194
|
end
|
193
195
|
end
|
194
196
|
|
@@ -200,7 +202,7 @@ describe Valvat::Lookup do
|
|
200
202
|
end
|
201
203
|
|
202
204
|
it 'returns nil with raise_error set to false' do
|
203
|
-
expect(described_class.validate('DE500', options.merge(raise_error: false))).to
|
205
|
+
expect(described_class.validate('DE500', options.merge(raise_error: false))).to be_nil
|
204
206
|
end
|
205
207
|
end
|
206
208
|
|
@@ -212,7 +214,7 @@ describe Valvat::Lookup do
|
|
212
214
|
end
|
213
215
|
|
214
216
|
it 'returns nil with raise_error set to false' do
|
215
|
-
expect(described_class.validate('DE501', options.merge(raise_error: false))).to
|
217
|
+
expect(described_class.validate('DE501', options.merge(raise_error: false))).to be_nil
|
216
218
|
end
|
217
219
|
end
|
218
220
|
|
@@ -224,7 +226,7 @@ describe Valvat::Lookup do
|
|
224
226
|
end
|
225
227
|
|
226
228
|
it 'returns nil with raise_error set to false' do
|
227
|
-
expect(described_class.validate('DE600', options.merge(raise_error: false))).to
|
229
|
+
expect(described_class.validate('DE600', options.merge(raise_error: false))).to be_nil
|
228
230
|
end
|
229
231
|
end
|
230
232
|
|
@@ -236,41 +238,43 @@ describe Valvat::Lookup do
|
|
236
238
|
end
|
237
239
|
|
238
240
|
it 'returns nil with raise_error set to false' do
|
239
|
-
expect(described_class.validate('DE601', options.merge(raise_error: false))).to
|
241
|
+
expect(described_class.validate('DE601', options.merge(raise_error: false))).to be_nil
|
240
242
|
end
|
241
243
|
end
|
242
244
|
|
243
245
|
describe 'Error : Savon::UnknownOperationError' do
|
246
|
+
subject(:result) { described_class.validate('DE601', options) }
|
247
|
+
|
244
248
|
before do
|
245
|
-
dbl =
|
249
|
+
dbl = instance_double(Savon::Client)
|
246
250
|
allow(Savon::Client).to receive(:new).and_return(dbl)
|
247
251
|
allow(dbl).to receive(:call).and_raise(Savon::UnknownOperationError.new('from stub'))
|
248
252
|
end
|
249
|
-
subject(:result) { described_class.validate('DE601', options) }
|
250
253
|
|
251
254
|
it 'raises error' do
|
252
255
|
expect { result }.to raise_error(Valvat::OperationUnknown, /#<Savon::UnknownOperationError: from stub>/)
|
253
256
|
end
|
254
257
|
|
255
258
|
it 'returns nil with raise_error set to false' do
|
256
|
-
expect(described_class.validate('DE601', options.merge(raise_error: false))).to
|
259
|
+
expect(described_class.validate('DE601', options.merge(raise_error: false))).to be_nil
|
257
260
|
end
|
258
261
|
end
|
259
262
|
|
260
263
|
describe 'Error : Savon::HTTPError' do
|
264
|
+
subject(:result) { described_class.validate('DE601', options) }
|
265
|
+
|
261
266
|
before do
|
262
|
-
dbl =
|
267
|
+
dbl = instance_double(Savon::Client)
|
263
268
|
allow(Savon::Client).to receive(:new).and_return(dbl)
|
264
269
|
allow(dbl).to receive(:call).and_raise(Savon::HTTPError.new(Struct.new(:code, :body).new(403, 'from stub')))
|
265
270
|
end
|
266
|
-
subject(:result) { described_class.validate('DE601', options) }
|
267
271
|
|
268
272
|
it 'raises error' do
|
269
273
|
expect { result }.to raise_error(Valvat::HTTPError, /#<Savon::HTTPError: HTTP error \(403\): from stub>/)
|
270
274
|
end
|
271
275
|
|
272
276
|
it 'returns nil with raise_error set to false' do
|
273
|
-
expect(described_class.validate('DE601', options.merge(raise_error: false))).to
|
277
|
+
expect(described_class.validate('DE601', options.merge(raise_error: false))).to be_nil
|
274
278
|
end
|
275
279
|
end
|
276
280
|
end
|
data/spec/valvat/utils_spec.rb
CHANGED
@@ -56,7 +56,7 @@ describe Valvat::Utils do
|
|
56
56
|
it 'removes special chars' do
|
57
57
|
expect(described_class.normalize('DE.345-889_00:3,;')).to eql('DE345889003')
|
58
58
|
expect(described_class.normalize("→ DE·Ö34588 9003\0 ☺")).to eql(
|
59
|
-
|
59
|
+
'→DEÖ345889003☺'
|
60
60
|
)
|
61
61
|
end
|
62
62
|
end
|
data/spec/valvat_spec.rb
CHANGED
@@ -171,15 +171,15 @@ describe Valvat do
|
|
171
171
|
|
172
172
|
describe '#iso_country_code' do
|
173
173
|
it 'returns nil' do
|
174
|
-
expect(us_vat.iso_country_code).to
|
175
|
-
expect(ch_vat.iso_country_code).to
|
174
|
+
expect(us_vat.iso_country_code).to be_nil
|
175
|
+
expect(ch_vat.iso_country_code).to be_nil
|
176
176
|
end
|
177
177
|
end
|
178
178
|
|
179
179
|
describe '#vat_country_code' do
|
180
180
|
it 'returns nil' do
|
181
|
-
expect(us_vat.vat_country_code).to
|
182
|
-
expect(ch_vat.vat_country_code).to
|
181
|
+
expect(us_vat.vat_country_code).to be_nil
|
182
|
+
expect(ch_vat.vat_country_code).to be_nil
|
183
183
|
end
|
184
184
|
end
|
185
185
|
|
@@ -231,19 +231,19 @@ describe Valvat do
|
|
231
231
|
|
232
232
|
describe '#iso_country_code' do
|
233
233
|
it 'returns nil' do
|
234
|
-
expect(only_iso_vat.iso_country_code).to
|
235
|
-
expect(num_vat.iso_country_code).to
|
236
|
-
expect(empty_vat.iso_country_code).to
|
237
|
-
expect(nil_vat.iso_country_code).to
|
234
|
+
expect(only_iso_vat.iso_country_code).to be_nil
|
235
|
+
expect(num_vat.iso_country_code).to be_nil
|
236
|
+
expect(empty_vat.iso_country_code).to be_nil
|
237
|
+
expect(nil_vat.iso_country_code).to be_nil
|
238
238
|
end
|
239
239
|
end
|
240
240
|
|
241
241
|
describe '#vat_country_code' do
|
242
242
|
it 'returns nil' do
|
243
|
-
expect(only_iso_vat.vat_country_code).to
|
244
|
-
expect(num_vat.vat_country_code).to
|
245
|
-
expect(empty_vat.vat_country_code).to
|
246
|
-
expect(nil_vat.vat_country_code).to
|
243
|
+
expect(only_iso_vat.vat_country_code).to be_nil
|
244
|
+
expect(num_vat.vat_country_code).to be_nil
|
245
|
+
expect(empty_vat.vat_country_code).to be_nil
|
246
|
+
expect(nil_vat.vat_country_code).to be_nil
|
247
247
|
end
|
248
248
|
end
|
249
249
|
|
data/valvat.gemspec
CHANGED
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: valvat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Munz
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
BUdT7mtr41GgvWnIjaGWAldSuabxx5H+PKS5FzjNDMHThRZWuvYp/nP2RXDh4gIa
|
36
36
|
7hV09P+XxvS96G+petG5KmC/lev8VqKu
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2022-
|
38
|
+
date: 2022-09-14 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: savon
|
@@ -211,7 +211,8 @@ files:
|
|
211
211
|
homepage: https://github.com/yolk/valvat
|
212
212
|
licenses:
|
213
213
|
- MIT
|
214
|
-
metadata:
|
214
|
+
metadata:
|
215
|
+
rubygems_mfa_required: 'true'
|
215
216
|
post_install_message:
|
216
217
|
rdoc_options: []
|
217
218
|
require_paths:
|
metadata.gz.sig
CHANGED
Binary file
|