valvat 1.0.1 → 1.1.3
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 +41 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +15 -0
- data/CHANGES.md +27 -1
- data/Gemfile +2 -0
- data/Guardfile +6 -4
- data/README.md +6 -4
- data/Rakefile +3 -1
- data/certs/yolk.pem +25 -24
- data/gemfiles/activemodel-5 +1 -1
- data/gemfiles/activemodel-6 +1 -1
- data/gemfiles/{activemodel-3-2 → activemodel-7} +2 -2
- 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 +8 -2
- data/lib/valvat/local.rb +6 -4
- 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/lookup/fault.rb +29 -21
- 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 +12 -9
- data/lib/valvat/version.rb +3 -1
- data/lib/valvat.rb +4 -2
- data/spec/active_model/validations/valvat_validator_spec.rb +99 -93
- 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 +32 -0
- data/spec/valvat/lookup/response_spec.rb +29 -0
- data/spec/valvat/lookup_spec.rb +171 -152
- data/spec/valvat/syntax_spec.rb +59 -280
- data/spec/valvat/utils_spec.rb +64 -47
- data/spec/valvat_spec.rb +140 -152
- data/valvat.gemspec +17 -17
- data.tar.gz.sig +1 -2
- metadata +48 -50
- metadata.gz.sig +0 -0
- data/.travis.yml +0 -47
- 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,13 @@
|
|
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='UNKNOWN')
|
6
|
-
@faultstring = faultstring
|
7
|
+
def initialize(faultstring = 'UNKNOWN', exception = nil)
|
8
|
+
@faultstring = faultstring || exception.inspect
|
9
|
+
@exception = exception
|
10
|
+
super(faultstring)
|
7
11
|
end
|
8
12
|
|
9
13
|
def to_s
|
@@ -19,6 +23,8 @@ class Valvat
|
|
19
23
|
ServiceUnavailable = Class.new(ViesMaintenanceError)
|
20
24
|
MemberStateUnavailable = Class.new(ViesMaintenanceError)
|
21
25
|
|
26
|
+
OperationUnknown = Class.new(ViesError)
|
27
|
+
HTTPError = Class.new(ViesError)
|
22
28
|
Timeout = Class.new(ViesError)
|
23
29
|
InvalidRequester = Class.new(ViesError)
|
24
30
|
BlockedError = Class.new(ViesError)
|
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?
|
@@ -36,11 +38,11 @@ class Valvat
|
|
36
38
|
end
|
37
39
|
|
38
40
|
def inspect
|
39
|
-
"#<Valvat #{[raw, iso_country_code].compact.join(
|
41
|
+
"#<Valvat #{[raw, iso_country_code].compact.join(' ')}>"
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
43
|
-
def Valvat(vat)
|
45
|
+
def Valvat(vat) # rubocop:disable Naming/MethodName
|
44
46
|
vat.is_a?(Valvat) ? vat : Valvat.new(vat)
|
45
47
|
end
|
46
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/lookup/fault.rb
CHANGED
@@ -1,30 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Valvat
|
2
4
|
class Lookup
|
3
5
|
class Fault < Response
|
4
|
-
|
6
|
+
def to_hash
|
7
|
+
@to_hash ||= case @raw
|
8
|
+
when Savon::HTTPError
|
9
|
+
{ error: HTTPError.new(nil, @raw) }
|
10
|
+
when Savon::UnknownOperationError
|
11
|
+
{ error: OperationUnknown.new(nil, @raw) }
|
12
|
+
else
|
13
|
+
fault = @raw.to_hash[:fault][:faultstring]
|
5
14
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
15
|
+
if fault == 'INVALID_INPUT'
|
16
|
+
{ valid: false }
|
17
|
+
else
|
18
|
+
error = (FAULTS[fault] || UnknownViesError).new(fault)
|
19
|
+
{ error: error }
|
20
|
+
end
|
21
|
+
end
|
10
22
|
end
|
11
23
|
|
12
24
|
FAULTS = {
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
}
|
24
|
-
|
25
|
-
def self.fault_to_error(fault)
|
26
|
-
(FAULTS[fault] || UnknownViesError).new(fault)
|
27
|
-
end
|
25
|
+
'SERVICE_UNAVAILABLE' => ServiceUnavailable,
|
26
|
+
'MS_UNAVAILABLE' => MemberStateUnavailable,
|
27
|
+
'INVALID_REQUESTER_INFO' => InvalidRequester,
|
28
|
+
'TIMEOUT' => Timeout,
|
29
|
+
'VAT_BLOCKED' => BlockedError,
|
30
|
+
'IP_BLOCKED' => BlockedError,
|
31
|
+
'GLOBAL_MAX_CONCURRENT_REQ' => RateLimitError,
|
32
|
+
'GLOBAL_MAX_CONCURRENT_REQ_TIME' => RateLimitError,
|
33
|
+
'MS_MAX_CONCURRENT_REQ' => RateLimitError,
|
34
|
+
'MS_MAX_CONCURRENT_REQ_TIME' => RateLimitError
|
35
|
+
}.freeze
|
28
36
|
end
|
29
37
|
end
|
30
|
-
end
|
38
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'savon'
|
2
4
|
|
3
5
|
class Valvat
|
@@ -12,13 +14,11 @@ class Valvat
|
|
12
14
|
end
|
13
15
|
|
14
16
|
def perform
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
Fault.new(fault)
|
21
|
-
end
|
17
|
+
Response.new(
|
18
|
+
client.call(action, message: message, message_tag: message_tag, soap_action: nil)
|
19
|
+
)
|
20
|
+
rescue Savon::SOAPFault, Savon::HTTPError, Savon::UnknownOperationError => e
|
21
|
+
Fault.new(e)
|
22
22
|
end
|
23
23
|
|
24
24
|
private
|
@@ -30,14 +30,10 @@ class Valvat
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def message
|
33
|
-
{
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
requester_country_code: @requester.vat_country_code,
|
38
|
-
requester_vat_number: @requester.to_s_wo_country
|
39
|
-
} : {}
|
40
|
-
)
|
33
|
+
add_requester({
|
34
|
+
country_code: @vat.vat_country_code,
|
35
|
+
vat_number: @vat.to_s_wo_country
|
36
|
+
})
|
41
37
|
end
|
42
38
|
|
43
39
|
def message_tag
|
@@ -47,6 +43,15 @@ class Valvat
|
|
47
43
|
def action
|
48
44
|
@requester ? :check_vat_approx : :check_vat
|
49
45
|
end
|
46
|
+
|
47
|
+
def add_requester(message)
|
48
|
+
return message unless @requester
|
49
|
+
|
50
|
+
message[:requester_country_code] = @requester.vat_country_code
|
51
|
+
message[:requester_vat_number] = @requester.to_s_wo_country
|
52
|
+
|
53
|
+
message
|
54
|
+
end
|
50
55
|
end
|
51
56
|
end
|
52
|
-
end
|
57
|
+
end
|