valvat 1.0.0 → 1.1.2
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 +35 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +15 -0
- data/CHANGES.md +29 -1
- data/Gemfile +2 -0
- data/Guardfile +6 -4
- data/README.md +10 -4
- data/Rakefile +3 -1
- data/certs/yolk.pem +21 -21
- data/gemfiles/activemodel-5 +1 -1
- data/gemfiles/activemodel-6 +1 -1
- data/lib/active_model/validations/valvat_validator.rb +65 -32
- 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 +46 -31
- 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 +7 -5
- 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 +5 -3
- 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/checksum.rb +24 -28
- data/lib/valvat/error.rb +5 -2
- 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 +1 -0
- 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/fault.rb +17 -16
- data/lib/valvat/lookup/request.rb +21 -16
- data/lib/valvat/lookup/response.rb +11 -10
- data/lib/valvat/lookup.rb +5 -4
- data/lib/valvat/syntax.rb +31 -30
- data/lib/valvat/utils.rb +20 -9
- data/lib/valvat/version.rb +3 -1
- data/lib/valvat.rb +4 -2
- data/spec/active_model/validations/valvat_validator_spec.rb +119 -87
- data/spec/spec_helper.rb +8 -8
- data/spec/valvat/checksum/at_spec.rb +6 -4
- data/spec/valvat/checksum/be_spec.rb +6 -4
- data/spec/valvat/checksum/bg_spec.rb +7 -4
- data/spec/valvat/checksum/cy_spec.rb +3 -1
- data/spec/valvat/checksum/de_spec.rb +6 -4
- data/spec/valvat/checksum/dk_spec.rb +6 -4
- data/spec/valvat/checksum/ee_spec.rb +3 -1
- data/spec/valvat/checksum/es_spec.rb +7 -4
- data/spec/valvat/checksum/fi_spec.rb +6 -4
- data/spec/valvat/checksum/fr_spec.rb +6 -4
- data/spec/valvat/checksum/gb_spec.rb +4 -2
- data/spec/valvat/checksum/gr_spec.rb +6 -4
- data/spec/valvat/checksum/hr_spec.rb +3 -1
- data/spec/valvat/checksum/hu_spec.rb +3 -1
- data/spec/valvat/checksum/ie_spec.rb +8 -6
- data/spec/valvat/checksum/it_spec.rb +10 -8
- data/spec/valvat/checksum/lt_spec.rb +3 -1
- data/spec/valvat/checksum/lu_spec.rb +6 -4
- data/spec/valvat/checksum/mt_spec.rb +3 -1
- data/spec/valvat/checksum/nl_spec.rb +9 -7
- data/spec/valvat/checksum/pl_spec.rb +8 -6
- data/spec/valvat/checksum/pt_spec.rb +10 -11
- data/spec/valvat/checksum/ro_spec.rb +3 -1
- data/spec/valvat/checksum/se_spec.rb +8 -6
- data/spec/valvat/checksum/si_spec.rb +10 -8
- data/spec/valvat/checksum_spec.rb +24 -9
- 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 +138 -153
- data/spec/valvat/syntax_spec.rb +59 -280
- data/spec/valvat/utils_spec.rb +77 -42
- data/spec/valvat_spec.rb +140 -152
- data/valvat.gemspec +17 -17
- data.tar.gz.sig +0 -0
- metadata +44 -47
- metadata.gz.sig +0 -0
- data/.travis.yml +0 -47
- data/gemfiles/activemodel-3-2 +0 -7
- data/gemfiles/activemodel-4 +0 -7
- data/gemfiles/before-ruby21/activemodel-3-2 +0 -8
- data/gemfiles/before-ruby21/activemodel-4 +0 -8
- data/gemfiles/before-ruby21/standalone +0 -7
- data/spec/valvat/lockup/fault_spec.rb +0 -32
- data/spec/valvat/lockup/request_spec.rb +0 -15
- data/spec/valvat/lockup/response_spec.rb +0 -27
data/lib/valvat/checksum/gb.rb
CHANGED
@@ -1,51 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Valvat
|
2
4
|
module Checksum
|
3
5
|
class GB < Base
|
4
|
-
OLD_FORMAT_FORBIDDEN_RANGES = [(100_000..999_999), (9_490_001..9_700_000), (9_990_001..9_999_999)]
|
5
|
-
NEW_FORMAT_FORBIDDEN_RANGES = [(1..100_000), (100_001..1_000_000)]
|
6
|
-
GOV_NUMBER = /\A(GD[0-4]{1}\d{2})\Z
|
7
|
-
HEALTH_NUMBER = /\A(HA[5-9]{1}\d{2})\Z
|
8
|
-
|
9
|
-
def validate
|
10
|
-
vat_number = vat.to_s_wo_country
|
6
|
+
OLD_FORMAT_FORBIDDEN_RANGES = [(100_000..999_999), (9_490_001..9_700_000), (9_990_001..9_999_999)].freeze
|
7
|
+
NEW_FORMAT_FORBIDDEN_RANGES = [(1..100_000), (100_001..1_000_000)].freeze
|
8
|
+
GOV_NUMBER = /\A(GD[0-4]{1}\d{2})\Z/.freeze
|
9
|
+
HEALTH_NUMBER = /\A(HA[5-9]{1}\d{2})\Z/.freeze
|
11
10
|
|
11
|
+
def validate # rubocop:disable Metrics/CyclomaticComplexity
|
12
12
|
# government departments and health authorities, so no checksum
|
13
|
-
return true if gov_or_health?
|
14
|
-
return false if all_zero?
|
13
|
+
return true if gov_or_health?
|
14
|
+
return false if all_zero?
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
vat_base_int = vat_base.to_i
|
19
|
-
vat_base_sum = generate_vat_base_sum(vat_base)
|
16
|
+
return false if old_format_remainder.zero? && fobidden_in_old_format?
|
17
|
+
return false if new_format_remainder.zero? && fobidden_in_new_format?
|
20
18
|
|
21
|
-
old_format_remainder
|
22
|
-
|
19
|
+
old_format_remainder.zero? || new_format_remainder.zero?
|
20
|
+
end
|
23
21
|
|
24
|
-
|
25
|
-
OLD_FORMAT_FORBIDDEN_RANGES.any? { |range| range.include? vat_base_int }
|
22
|
+
private
|
26
23
|
|
27
|
-
|
28
|
-
|
24
|
+
def checksum
|
25
|
+
@checksum ||= str_wo_country[7..8].to_i
|
26
|
+
end
|
29
27
|
|
30
|
-
|
28
|
+
def vat_base
|
29
|
+
@vat_base ||= str_wo_country[0..6]
|
31
30
|
end
|
32
31
|
|
33
|
-
|
32
|
+
def gov_or_health?
|
33
|
+
str_wo_country =~ GOV_NUMBER || str_wo_country =~ HEALTH_NUMBER
|
34
|
+
end
|
34
35
|
|
35
|
-
def
|
36
|
-
|
36
|
+
def all_zero?
|
37
|
+
str_wo_country =~ /\A0{9}\Z/ || str_wo_country =~ /\A0{12}\Z/
|
37
38
|
end
|
38
39
|
|
39
|
-
def
|
40
|
-
|
40
|
+
def vat_base_sum
|
41
|
+
@vat_base_sum ||= vat_base.split('')
|
42
|
+
.map(&:to_i)
|
43
|
+
.zip([8, 7, 6, 5, 4, 3, 2])
|
44
|
+
.map { |vat_number_digit, multiplier| vat_number_digit * multiplier }
|
45
|
+
.inject(:+)
|
41
46
|
end
|
42
47
|
|
43
|
-
def
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
48
|
+
def old_format_remainder
|
49
|
+
@old_format_remainder ||= (vat_base_sum + checksum).modulo(97)
|
50
|
+
end
|
51
|
+
|
52
|
+
def new_format_remainder
|
53
|
+
@new_format_remainder ||= (vat_base_sum + 55 + checksum).modulo(97)
|
54
|
+
end
|
55
|
+
|
56
|
+
def fobidden_in_new_format?
|
57
|
+
vat_base_int = vat_base.to_i
|
58
|
+
NEW_FORMAT_FORBIDDEN_RANGES.any? { |range| range.include?(vat_base_int) }
|
59
|
+
end
|
60
|
+
|
61
|
+
def fobidden_in_old_format?
|
62
|
+
vat_base_int = vat_base.to_i
|
63
|
+
OLD_FORMAT_FORBIDDEN_RANGES.any? { |range| range.include?(vat_base_int) }
|
49
64
|
end
|
50
65
|
end
|
51
66
|
end
|
data/lib/valvat/checksum/gr.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Valvat
|
2
4
|
module Checksum
|
3
5
|
class GR < Base
|
4
6
|
def check_digit
|
5
7
|
chk = sum_figures_by do |fig, i|
|
6
|
-
fig*(2**(i+1))
|
8
|
+
fig * (2**(i + 1))
|
7
9
|
end.modulo(11)
|
8
10
|
chk > 9 ? 0 : chk
|
9
11
|
end
|
10
12
|
end
|
11
13
|
end
|
12
|
-
end
|
14
|
+
end
|
data/lib/valvat/checksum/hr.rb
CHANGED
data/lib/valvat/checksum/hu.rb
CHANGED
data/lib/valvat/checksum/ie.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Valvat
|
2
4
|
module Checksum
|
3
5
|
class IE < Base
|
4
6
|
def check_digit
|
5
7
|
total = sum_figures_by do |fig, i|
|
6
|
-
fig*(i+2)
|
7
|
-
end
|
8
|
-
if str_wo_country.size == 9
|
9
|
-
total += ((CHARS.index(str_wo_country[8]) || 0) * 9)
|
8
|
+
fig * (i + 2)
|
10
9
|
end
|
10
|
+
total += ((CHARS.index(str_wo_country[8]) || 0) * 9) if str_wo_country.size == 9
|
11
11
|
total.modulo(23)
|
12
12
|
end
|
13
13
|
|
14
|
-
CHARS =
|
14
|
+
CHARS = 'WABCDEFGHIJKLMNOPQRSTUV'.split('')
|
15
15
|
|
16
16
|
def given_check_digit
|
17
17
|
if str_wo_country.size == 9
|
@@ -38,7 +38,6 @@ class Valvat
|
|
38
38
|
super
|
39
39
|
end
|
40
40
|
end
|
41
|
-
|
42
41
|
end
|
43
42
|
end
|
44
43
|
end
|
data/lib/valvat/checksum/it.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Valvat
|
2
4
|
module Checksum
|
3
5
|
class IT < Base
|
4
6
|
def validate
|
5
7
|
y = figures_str[7..9].to_i
|
6
|
-
y >= 1 && (y <= 100 || [120, 121].include?(y)) &&
|
7
|
-
|
8
|
-
|
8
|
+
y >= 1 && (y <= 100 || [120, 121, 999].include?(y)) &&
|
9
|
+
figures_str[0..6] != '0000000' &&
|
10
|
+
super
|
9
11
|
end
|
10
12
|
|
11
13
|
def check_digit
|
12
|
-
chk = 10 - sum_of_figures_for_at_es_it_se(true).modulo(10)
|
14
|
+
chk = 10 - sum_of_figures_for_at_es_it_se(reverse_ints: true).modulo(10)
|
13
15
|
chk == 10 ? 0 : chk
|
14
16
|
end
|
15
17
|
end
|
16
18
|
end
|
17
|
-
end
|
19
|
+
end
|
data/lib/valvat/checksum/lt.rb
CHANGED
data/lib/valvat/checksum/lu.rb
CHANGED
data/lib/valvat/checksum/mt.rb
CHANGED
data/lib/valvat/checksum/nl.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Valvat
|
2
4
|
module Checksum
|
3
5
|
class NL < Base
|
4
6
|
def validate
|
5
7
|
vat.to_s.gsub(/[A-Z]/) { |let| (let.ord - 55).to_s }.to_i % 97 == 1 ||
|
6
|
-
|
8
|
+
super
|
7
9
|
end
|
8
10
|
|
9
11
|
def check_digit
|
10
12
|
sum_figures_by do |fig, i|
|
11
|
-
fig*(i+2)
|
13
|
+
fig * (i + 2)
|
12
14
|
end.modulo(11)
|
13
15
|
end
|
14
16
|
|
@@ -17,4 +19,4 @@ class Valvat
|
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
20
|
-
end
|
22
|
+
end
|
data/lib/valvat/checksum/pl.rb
CHANGED
data/lib/valvat/checksum/pt.rb
CHANGED
data/lib/valvat/checksum/ro.rb
CHANGED
data/lib/valvat/checksum/se.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Valvat
|
2
4
|
module Checksum
|
3
5
|
class SE < Base
|
4
6
|
check_digit_length 0
|
5
7
|
|
6
8
|
def validate
|
7
|
-
vat.to_s_wo_country[-2..-1].to_i
|
8
|
-
|
9
|
+
vat.to_s_wo_country[-2..-1].to_i.positive? &&
|
10
|
+
super
|
9
11
|
end
|
10
12
|
|
11
13
|
private
|
@@ -23,4 +25,4 @@ class Valvat
|
|
23
25
|
end
|
24
26
|
end
|
25
27
|
end
|
26
|
-
end
|
28
|
+
end
|
data/lib/valvat/checksum/si.rb
CHANGED
data/lib/valvat/checksum.rb
CHANGED
@@ -1,21 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Valvat
|
2
4
|
module Checksum
|
3
|
-
ALGORITHMS = {}
|
4
|
-
|
5
|
-
def self.validate(vat)
|
6
|
-
vat = Valvat(vat)
|
7
|
-
algo = ALGORITHMS[vat.iso_country_code]
|
8
|
-
Valvat::Syntax.validate(vat) && !!(algo.nil? || algo.new(vat).validate)
|
9
|
-
end
|
10
|
-
|
11
5
|
class Base
|
12
|
-
def self.inherited(klass)
|
13
|
-
ALGORITHMS[klass.name.split(/::/).last] = klass
|
14
|
-
end
|
15
|
-
|
16
6
|
attr_reader :vat
|
17
7
|
|
18
|
-
def self.check_digit_length(len=nil)
|
8
|
+
def self.check_digit_length(len = nil)
|
19
9
|
@check_digit_length = len if len
|
20
10
|
@check_digit_length || 1
|
21
11
|
end
|
@@ -39,44 +29,50 @@ class Valvat
|
|
39
29
|
end
|
40
30
|
|
41
31
|
def figures_str
|
42
|
-
str_wo_country[0..-(self.class.check_digit_length+1)]
|
32
|
+
str_wo_country[0..-(self.class.check_digit_length + 1)]
|
43
33
|
end
|
44
34
|
|
45
35
|
def figures
|
46
|
-
figures_str.split(
|
36
|
+
figures_str.split('').map(&:to_i)
|
47
37
|
end
|
48
38
|
|
49
39
|
def str_wo_country
|
50
40
|
vat.to_s_wo_country
|
51
41
|
end
|
52
42
|
|
53
|
-
def sum_figures_by
|
54
|
-
figures.reverse.each_with_index.map
|
55
|
-
yield(fig, i)
|
56
|
-
end.inject(:+)
|
43
|
+
def sum_figures_by(&block)
|
44
|
+
figures.reverse.each_with_index.map(&block).inject(:+)
|
57
45
|
end
|
58
46
|
|
59
47
|
def sum_of_squares(num)
|
60
|
-
num.to_s.split(
|
48
|
+
num.to_s.split('').map(&:to_i).inject(:+)
|
61
49
|
end
|
62
50
|
|
63
|
-
def sum_of_figures_for_at_es_it_se(reverse_ints
|
51
|
+
def sum_of_figures_for_at_es_it_se(reverse_ints: false)
|
64
52
|
ints = reverse_ints ? [2, 1] : [1, 2]
|
65
53
|
sum_figures_by do |fig, i|
|
66
|
-
sum_of_squares(fig*(i.modulo(2)
|
54
|
+
sum_of_squares(fig * (i.modulo(2).zero? ? ints[0] : ints[1]))
|
67
55
|
end
|
68
56
|
end
|
69
57
|
|
70
58
|
def sum_of_figues_for_pt_si
|
71
59
|
11 - sum_figures_by do |fig, i|
|
72
|
-
fig*(i+2)
|
60
|
+
fig * (i + 2)
|
73
61
|
end.modulo(11)
|
74
62
|
end
|
75
63
|
end
|
64
|
+
|
65
|
+
def self.validate(vat)
|
66
|
+
vat = Valvat(vat)
|
67
|
+
algo = ALGORITHMS[vat.iso_country_code]
|
68
|
+
Valvat::Syntax.validate(vat) && !!(algo.nil? || algo.new(vat).validate)
|
69
|
+
end
|
70
|
+
|
71
|
+
ALGORITHMS = Dir[File.join(__dir__, 'checksum', '*.rb')].each_with_object({}) do |path, algos|
|
72
|
+
require path.gsub(/\.rb$/, '')
|
73
|
+
|
74
|
+
classname = File.basename(path, '.rb').upcase
|
75
|
+
algos[classname] = ['Valvat', 'Checksum', classname].inject(Object, :const_get)
|
76
|
+
end.freeze
|
76
77
|
end
|
77
78
|
end
|
78
|
-
|
79
|
-
Dir[File.join(File.dirname(__FILE__), 'checksum', '*.rb')].each do |path|
|
80
|
-
# On Ruby 2.1.0 ActiveSupport goes mad if you pass it paths with .rb at the end
|
81
|
-
require path.gsub(/\.rb$/, '')
|
82
|
-
end
|
data/lib/valvat/error.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Valvat
|
2
4
|
Error = Class.new(RuntimeError)
|
3
5
|
|
4
6
|
class ViesError < Error
|
5
|
-
def initialize(faultstring='
|
7
|
+
def initialize(faultstring = 'UNKNOWN')
|
6
8
|
@faultstring = faultstring
|
9
|
+
super
|
7
10
|
end
|
8
11
|
|
9
12
|
def to_s
|
@@ -25,4 +28,4 @@ class Valvat
|
|
25
28
|
RateLimitError = Class.new(ViesError)
|
26
29
|
|
27
30
|
UnknownViesError = Class.new(ViesError)
|
28
|
-
end
|
31
|
+
end
|
data/lib/valvat/local.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Valvat
|
2
4
|
def initialize(raw)
|
3
|
-
@raw = Valvat::Utils.normalize(raw ||
|
5
|
+
@raw = Valvat::Utils.normalize(raw || '')
|
4
6
|
@vat_country_code, @to_s_wo_country = to_a
|
5
7
|
end
|
6
8
|
|
7
9
|
attr_reader :raw, :vat_country_code, :to_s_wo_country
|
8
10
|
|
9
11
|
def blank?
|
10
|
-
raw.nil? || raw.strip ==
|
12
|
+
raw.nil? || raw.strip == ''
|
11
13
|
end
|
12
14
|
|
13
15
|
def valid?
|
@@ -22,8 +24,9 @@ class Valvat
|
|
22
24
|
Valvat::Utils.vat_country_to_iso_country(vat_country_code)
|
23
25
|
end
|
24
26
|
|
27
|
+
# TODO: Remove method / not in use
|
25
28
|
def european?
|
26
|
-
Valvat::Utils::
|
29
|
+
Valvat::Utils::EU_MEMBER_STATES.include?(iso_country_code)
|
27
30
|
end
|
28
31
|
|
29
32
|
def to_a
|
@@ -35,11 +38,11 @@ class Valvat
|
|
35
38
|
end
|
36
39
|
|
37
40
|
def inspect
|
38
|
-
"#<Valvat #{[raw, iso_country_code].compact.join(
|
41
|
+
"#<Valvat #{[raw, iso_country_code].compact.join(' ')}>"
|
39
42
|
end
|
40
43
|
end
|
41
44
|
|
42
|
-
def Valvat(vat)
|
45
|
+
def Valvat(vat) # rubocop:disable Naming/MethodName
|
43
46
|
vat.is_a?(Valvat) ? vat : Valvat.new(vat)
|
44
47
|
end
|
45
48
|
|
data/lib/valvat/locales/de.yml
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
de:
|
2
2
|
errors:
|
3
3
|
messages:
|
4
|
-
invalid_vat: ist keine gültige %{country_adjective} USt-IdNr.
|
4
|
+
invalid_vat: "ist keine gültige %{country_adjective} USt-IdNr."
|
5
|
+
vies_down: "Die USt-IdNr. kann nicht überprüft werden: der VIES-Webservice ist nicht verfügbar. Bitte später noch einmal versuchen."
|
5
6
|
valvat:
|
6
7
|
country_adjectives:
|
7
8
|
eu: europäische
|
data/lib/valvat/locales/en.yml
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
en:
|
2
2
|
errors:
|
3
3
|
messages:
|
4
|
-
invalid_vat: is not a valid %{country_adjective} VAT number
|
4
|
+
invalid_vat: "is not a valid %{country_adjective} VAT number"
|
5
|
+
vies_down: "Unable to validate your VAT number: the VIES service is down. Please try again later."
|
5
6
|
valvat:
|
6
7
|
country_adjectives:
|
7
8
|
eu: European
|
data/lib/valvat/locales/es.yml
CHANGED
@@ -2,6 +2,7 @@ es:
|
|
2
2
|
errors:
|
3
3
|
messages:
|
4
4
|
invalid_vat: no es un número de IVA intracomunitario %{country_adjective} válido
|
5
|
+
vies_down: "No se ha podido validar su número de IVA: El servicio VIES no está disponible, por favor inténtelo más tarde."
|
5
6
|
valvat:
|
6
7
|
country_adjectives:
|
7
8
|
eu: europeo
|
data/lib/valvat/locales/fr.yml
CHANGED
@@ -2,6 +2,7 @@ fr:
|
|
2
2
|
errors:
|
3
3
|
messages:
|
4
4
|
invalid_vat: "Numéro de TVA %{country_adjective} invalide"
|
5
|
+
vies_down: "Impossible de valider votre numéro de TVA : le service de validation VIES est indisponible. Merci de réessayer ultérieurement."
|
5
6
|
valvat:
|
6
7
|
country_adjectives:
|
7
8
|
eu: intracommunautaire
|
data/lib/valvat/locales/hu.yml
CHANGED
data/lib/valvat/locales/nl.yml
CHANGED
data/lib/valvat/locales/pl.yml
CHANGED
data/lib/valvat/locales/pt.yml
CHANGED
@@ -4,31 +4,31 @@ pt:
|
|
4
4
|
invalid_vat: O NIF %{country_adjective} não é válido.
|
5
5
|
valvat:
|
6
6
|
country_adjectives:
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
7
|
+
eu: europeu
|
8
|
+
at: austríaco
|
9
|
+
be: belga
|
10
|
+
bg: búlgaro
|
11
|
+
cy: cipriota
|
12
|
+
cz: checo
|
13
|
+
de: alemão
|
14
|
+
dk: dinamarquês
|
15
|
+
ee: estónio
|
16
|
+
es: espanhol
|
17
|
+
fi: finlandês
|
18
|
+
fr: francês
|
19
|
+
gb: britânico
|
20
|
+
gr: grego
|
21
|
+
hu: húngaro
|
22
|
+
ie: irlandês
|
23
|
+
it: italiano
|
24
|
+
lt: lituano
|
25
|
+
lu: luxemburguês
|
26
|
+
lv: letão
|
27
|
+
mt: maltês
|
28
|
+
nl: holandês
|
29
|
+
pl: polaco
|
30
|
+
pt: português
|
31
|
+
ro: romeno
|
32
|
+
se: sueco
|
33
|
+
si: esloveno
|
34
|
+
sk: eslovaco
|
data/lib/valvat/lookup/fault.rb
CHANGED
@@ -1,30 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Valvat
|
2
4
|
class Lookup
|
3
5
|
class Fault < Response
|
4
|
-
private
|
5
|
-
|
6
6
|
def self.cleanup(hash)
|
7
7
|
fault = hash[:fault][:faultstring]
|
8
|
-
return {valid: false} if fault ==
|
9
|
-
|
8
|
+
return { valid: false } if fault == 'INVALID_INPUT'
|
9
|
+
|
10
|
+
{ error: fault_to_error(fault) }
|
10
11
|
end
|
11
12
|
|
12
13
|
FAULTS = {
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
}
|
14
|
+
'SERVICE_UNAVAILABLE' => ServiceUnavailable,
|
15
|
+
'MS_UNAVAILABLE' => MemberStateUnavailable,
|
16
|
+
'INVALID_REQUESTER_INFO' => InvalidRequester,
|
17
|
+
'TIMEOUT' => Timeout,
|
18
|
+
'VAT_BLOCKED' => BlockedError,
|
19
|
+
'IP_BLOCKED' => BlockedError,
|
20
|
+
'GLOBAL_MAX_CONCURRENT_REQ' => RateLimitError,
|
21
|
+
'GLOBAL_MAX_CONCURRENT_REQ_TIME' => RateLimitError,
|
22
|
+
'MS_MAX_CONCURRENT_REQ' => RateLimitError,
|
23
|
+
'MS_MAX_CONCURRENT_REQ_TIME' => RateLimitError
|
24
|
+
}.freeze
|
24
25
|
|
25
26
|
def self.fault_to_error(fault)
|
26
27
|
(FAULTS[fault] || UnknownViesError).new(fault)
|
27
28
|
end
|
28
29
|
end
|
29
30
|
end
|
30
|
-
end
|
31
|
+
end
|