valvat 0.3.6 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.md +9 -1
- data/Guardfile +3 -3
- data/README.md +32 -1
- data/lib/valvat.rb +4 -2
- data/lib/valvat/lookup.rb +27 -5
- data/lib/valvat/lookup/request.rb +30 -0
- data/lib/valvat/lookup/request_with_id.rb +27 -0
- data/lib/valvat/version.rb +1 -1
- data/spec/valvat/lookup_spec.rb +41 -0
- data/spec/valvat_spec.rb +7 -0
- data/valvat.gemspec +1 -1
- metadata +61 -18
data/CHANGES.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
### dev
|
2
2
|
|
3
|
-
[full changelog](http://github.com/yolk/valvat/compare/v0.
|
3
|
+
[full changelog](http://github.com/yolk/valvat/compare/v0.4.0...master)
|
4
|
+
|
5
|
+
### 0.4.0 / 2012-07-17
|
6
|
+
|
7
|
+
[full changelog](http://github.com/yolk/valvat/compare/v0.3,6...v0.4.0)
|
8
|
+
|
9
|
+
* Added support for company details and requester identifiers in successful responses
|
10
|
+
(by [lcx](https://github.com/lcx))
|
11
|
+
* Added Valvat::Lookup.last_error for debugging
|
4
12
|
|
5
13
|
### 0.3.6 / 2012-04-10
|
6
14
|
|
data/Guardfile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
guard 'rspec', :version => 2 do
|
2
|
-
watch(
|
3
|
-
watch(
|
4
|
-
watch(
|
2
|
+
watch(/^spec\/(.*)_spec.rb/)
|
3
|
+
watch(/^lib\/(.*)\.rb/) { |m| "spec/#{m[1]}_spec.rb" }
|
4
|
+
watch(/^spec\/spec_helper.rb/) { "spec" }
|
5
5
|
end
|
data/README.md
CHANGED
@@ -28,7 +28,7 @@ To check if the given vat number exists via the VIES web service:
|
|
28
28
|
Valvat.new("DE345789003").exists?
|
29
29
|
=> true or false or nil
|
30
30
|
|
31
|
-
Keep in mind that the VIES web service might be offline at some time for some countries. If this happens `Valvat::Lookup.validate`
|
31
|
+
*IMPORTANT* Keep in mind that the VIES web service might be offline at some time for some countries. If this happens `exists?` or `Valvat::Lookup.validate` will return `nil`.
|
32
32
|
|
33
33
|
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 country will be down.
|
34
34
|
|
@@ -41,6 +41,29 @@ Or to lookup a vat number string directly via VIES web service:
|
|
41
41
|
|
42
42
|
Valvat::Lookup.validate("DE345789003")
|
43
43
|
=> true or false or nil
|
44
|
+
|
45
|
+
## Details & request identifier
|
46
|
+
|
47
|
+
If you need all details and not only if the VAT is valid, pass {:detail => true} as second parameter to the lookup call.
|
48
|
+
|
49
|
+
Valvat.new("IE6388047V").exists?(:detail => true)
|
50
|
+
=> {
|
51
|
+
:country_code=>"IE", :vat_number => "6388047V",
|
52
|
+
:request_date => Date.today, :name=>"GOOGLE IRELAND LIMITED",
|
53
|
+
:address=>"1ST & 2ND FLOOR ,GORDON HOUSE ,BARROW STREET ,DUBLIN 4"
|
54
|
+
} or false or nil
|
55
|
+
|
56
|
+
According to EU law, or at least as Austria sees it, it's mandatory to verify the UID number of every new customer, but also to check the UID Number periodicaly. To prove that you have checked the UID number, the VIES Web service can return a requestIdentifier.
|
57
|
+
|
58
|
+
To receive a requestIdentifier 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)
|
59
|
+
|
60
|
+
Valvat.new("LU21416127").exists?(:my_vat => "IE6388047V")
|
61
|
+
=> {
|
62
|
+
:country_code=>"LU", :vat_number => "21416127",
|
63
|
+
:request_date => Date.today, :name=>"EBAY EUROPE S.A R.L.",
|
64
|
+
:address => "22, BOULEVARD ROYAL\nL-2449 LUXEMBOURG",
|
65
|
+
:company_type => nil, :request_identifier => "some_uniq_string"
|
66
|
+
} or false or nil
|
44
67
|
|
45
68
|
## ActiveModel/Rails3 Usage
|
46
69
|
|
@@ -133,6 +156,14 @@ This basically just removes trailing spaces and ensures all chars are uppercase.
|
|
133
156
|
* [European vat number formats (german)](http://bzst.de/DE/Steuern_International/USt_Identifikationsnummer/Merkblaetter/Aufbau_USt_IdNr.html)
|
134
157
|
* [European vat number formats on Wikipedia](http://en.wikipedia.org/wiki/European_Union_Value_Added_Tax)
|
135
158
|
|
159
|
+
## Contributions by
|
160
|
+
|
161
|
+
* [lcx](https://github.com/lcx)
|
162
|
+
* [opsidao](https://github.com/opsidao)
|
163
|
+
* [henrik](https://github.com/henrik)
|
164
|
+
* [SpoBo](https://github.com/SpoBo)
|
165
|
+
* [Deb Bassett](https://github.com/urbanwide)
|
166
|
+
|
136
167
|
## BlaBla
|
137
168
|
|
138
169
|
Copyright (c) 2011 Yolk Sebastian Munz & Julia Soergel GbR
|
data/lib/valvat.rb
CHANGED
@@ -10,8 +10,8 @@ class Valvat
|
|
10
10
|
Valvat::Syntax.validate(self)
|
11
11
|
end
|
12
12
|
|
13
|
-
def exists?
|
14
|
-
Valvat::Lookup.validate(self)
|
13
|
+
def exists?(options={})
|
14
|
+
Valvat::Lookup.validate(self, options)
|
15
15
|
end
|
16
16
|
alias_method :exist?, :exists?
|
17
17
|
|
@@ -43,5 +43,7 @@ end
|
|
43
43
|
require 'valvat/utils'
|
44
44
|
require 'valvat/syntax'
|
45
45
|
require 'valvat/lookup'
|
46
|
+
require 'valvat/lookup/request'
|
47
|
+
require 'valvat/lookup/request_with_id'
|
46
48
|
require 'valvat/version'
|
47
49
|
require 'valvat/active_model' if defined?(ActiveModel)
|
data/lib/valvat/lookup.rb
CHANGED
@@ -5,16 +5,20 @@ require 'yaml'
|
|
5
5
|
class Valvat
|
6
6
|
module Lookup
|
7
7
|
|
8
|
-
def self.validate(vat)
|
8
|
+
def self.validate(vat, options={})
|
9
9
|
vat = Valvat(vat)
|
10
10
|
return false unless vat.european?
|
11
11
|
|
12
|
+
request = options[:requester_vat] ?
|
13
|
+
Valvat::Lookup::RequestWithId.new(vat, Valvat(options[:requester_vat])) :
|
14
|
+
Valvat::Lookup::Request.new(vat)
|
15
|
+
|
12
16
|
begin
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end.to_hash[:check_vat_response][:valid]
|
17
|
+
response = request.perform(self.client)
|
18
|
+
response[:valid] && (options[:detail] || options[:requester_vat]) ?
|
19
|
+
filter_detail(response) : response[:valid]
|
17
20
|
rescue => err
|
21
|
+
@last_error = err
|
18
22
|
if err.respond_to?(:to_hash) && err.to_hash[:fault] && err.to_hash[:fault][:faultstring] == "{ 'INVALID_INPUT' }"
|
19
23
|
return false
|
20
24
|
end
|
@@ -36,5 +40,23 @@ class Valvat
|
|
36
40
|
end
|
37
41
|
end
|
38
42
|
end
|
43
|
+
|
44
|
+
def self.last_error
|
45
|
+
@last_error
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
REMOVE_KEYS = [:valid, :@xmlns]
|
51
|
+
|
52
|
+
def self.filter_detail(response)
|
53
|
+
response.inject({}) do |hash, kv|
|
54
|
+
key, value = kv
|
55
|
+
unless REMOVE_KEYS.include?(key)
|
56
|
+
hash[key.to_s.sub(/^trader_/, "").to_sym] = (value == "---" ? nil : value)
|
57
|
+
end
|
58
|
+
hash
|
59
|
+
end
|
60
|
+
end
|
39
61
|
end
|
40
62
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class Valvat
|
2
|
+
module Lookup
|
3
|
+
class Request
|
4
|
+
def initialize(vat)
|
5
|
+
@vat = vat
|
6
|
+
end
|
7
|
+
|
8
|
+
def perform(client)
|
9
|
+
client.request("n1", action) do
|
10
|
+
soap.body = body
|
11
|
+
soap.namespaces["xmlns:n1"] = "urn:ec.europa.eu:taxud:vies:services:checkVat:types"
|
12
|
+
end.to_hash[response_key]
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def body
|
18
|
+
{"n1:countryCode" => @vat.vat_country_code, "n1:vatNumber" => @vat.to_s_wo_country}
|
19
|
+
end
|
20
|
+
|
21
|
+
def action
|
22
|
+
"checkVat"
|
23
|
+
end
|
24
|
+
|
25
|
+
def response_key
|
26
|
+
:check_vat_response
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Valvat
|
2
|
+
module Lookup
|
3
|
+
class RequestWithId < Request
|
4
|
+
def initialize(vat, requester_vat)
|
5
|
+
@vat = vat
|
6
|
+
@requester_vat = requester_vat
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def body
|
12
|
+
super.merge(
|
13
|
+
"n1:requesterCountryCode" => @requester_vat.vat_country_code,
|
14
|
+
"n1:requesterVatNumber" => @requester_vat.to_s_wo_country
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def action
|
19
|
+
"checkVatApprox"
|
20
|
+
end
|
21
|
+
|
22
|
+
def response_key
|
23
|
+
:check_vat_approx_response
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/valvat/version.rb
CHANGED
data/spec/valvat/lookup_spec.rb
CHANGED
@@ -27,6 +27,47 @@ describe Valvat::Lookup do
|
|
27
27
|
Valvat::Lookup.validate("").should eql(false)
|
28
28
|
end
|
29
29
|
end
|
30
|
+
|
31
|
+
context "with details" do
|
32
|
+
it "returns hash of details instead of true" do
|
33
|
+
Valvat::Lookup.validate("IE6388047V", :detail => true).should eql({
|
34
|
+
:country_code=>"IE",
|
35
|
+
:vat_number=>"6388047V",
|
36
|
+
:request_date=> Date.today,
|
37
|
+
:name=>"GOOGLE IRELAND LIMITED",
|
38
|
+
:address=>"1ST & 2ND FLOOR ,GORDON HOUSE ,BARROW STREET ,DUBLIN 4"
|
39
|
+
})
|
40
|
+
|
41
|
+
Valvat::Lookup.validate("LU21416127", :detail => true).should eql({
|
42
|
+
:country_code=>"LU",
|
43
|
+
:vat_number=>"21416127",
|
44
|
+
:request_date=> Date.today,
|
45
|
+
:name=>"EBAY EUROPE S.A R.L.",
|
46
|
+
:address=>"22, BOULEVARD ROYAL\nL-2449 LUXEMBOURG"
|
47
|
+
})
|
48
|
+
end
|
49
|
+
|
50
|
+
it "still returns false on not existing vat number" do
|
51
|
+
Valvat::Lookup.validate("BE08173319921", :detail => true).should eql(false)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "with request identifier" do
|
56
|
+
it "returns hash of details instead of true" do
|
57
|
+
response = Valvat::Lookup.validate("LU21416127", :requester_vat => "IE6388047V")
|
58
|
+
response[:request_identifier].size.should eql(16)
|
59
|
+
response[:request_identifier] = "some_uniq_string"
|
60
|
+
response.should eql({
|
61
|
+
:country_code=>"LU",
|
62
|
+
:vat_number=>"21416127",
|
63
|
+
:request_date=> Date.today,
|
64
|
+
:name => "EBAY EUROPE S.A R.L.",
|
65
|
+
:address => "22, BOULEVARD ROYAL\nL-2449 LUXEMBOURG",
|
66
|
+
:company_type => nil,
|
67
|
+
:request_identifier => "some_uniq_string"
|
68
|
+
})
|
69
|
+
end
|
70
|
+
end
|
30
71
|
|
31
72
|
# TODO : Reactivate with coorect "down" response
|
32
73
|
# context "country web service down" do
|
data/spec/valvat_spec.rb
CHANGED
@@ -68,6 +68,13 @@ describe Valvat do
|
|
68
68
|
at_vat.exist?.should eql(false)
|
69
69
|
end
|
70
70
|
end
|
71
|
+
|
72
|
+
context "with options" do
|
73
|
+
it "calls Valvat::Lookup.validate with options" do
|
74
|
+
Valvat::Lookup.should_receive(:validate).once.with(de_vat, :detail => true, :bla => 'blupp').and_return(true)
|
75
|
+
de_vat.exists?(:detail => true, :bla => 'blupp').should eql(true)
|
76
|
+
end
|
77
|
+
end
|
71
78
|
end
|
72
79
|
|
73
80
|
context "#iso_country_code" do
|
data/valvat.gemspec
CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
s.add_development_dependency 'rspec', '>= 2.4.0'
|
33
33
|
s.add_development_dependency 'guard-rspec', '>=0.1.9'
|
34
34
|
s.add_development_dependency 'growl', '>=1.0.3'
|
35
|
-
s.add_development_dependency 'rb-fsevent', '>=0.
|
35
|
+
s.add_development_dependency 'rb-fsevent', '>=0.9.1'
|
36
36
|
s.add_development_dependency 'activemodel', '>=3.0'
|
37
37
|
s.add_development_dependency 'fakeweb', '>= 1.3.0'
|
38
38
|
end
|
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: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: savon
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: 0.8.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.8.2
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: rspec
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: 2.4.0
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.4.0
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: guard-rspec
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ! '>='
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: 0.1.9
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.1.9
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: growl
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ! '>='
|
@@ -54,21 +69,31 @@ dependencies:
|
|
54
69
|
version: 1.0.3
|
55
70
|
type: :development
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.0.3
|
58
78
|
- !ruby/object:Gem::Dependency
|
59
79
|
name: rb-fsevent
|
60
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
61
81
|
none: false
|
62
82
|
requirements:
|
63
83
|
- - ! '>='
|
64
84
|
- !ruby/object:Gem::Version
|
65
|
-
version: 0.
|
85
|
+
version: 0.9.1
|
66
86
|
type: :development
|
67
87
|
prerelease: false
|
68
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 0.9.1
|
69
94
|
- !ruby/object:Gem::Dependency
|
70
95
|
name: activemodel
|
71
|
-
requirement:
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
72
97
|
none: false
|
73
98
|
requirements:
|
74
99
|
- - ! '>='
|
@@ -76,10 +101,15 @@ dependencies:
|
|
76
101
|
version: '3.0'
|
77
102
|
type: :development
|
78
103
|
prerelease: false
|
79
|
-
version_requirements:
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '3.0'
|
80
110
|
- !ruby/object:Gem::Dependency
|
81
111
|
name: fakeweb
|
82
|
-
requirement:
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
83
113
|
none: false
|
84
114
|
requirements:
|
85
115
|
- - ! '>='
|
@@ -87,7 +117,12 @@ dependencies:
|
|
87
117
|
version: 1.3.0
|
88
118
|
type: :development
|
89
119
|
prerelease: false
|
90
|
-
version_requirements:
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 1.3.0
|
91
126
|
description: ! " Validates european vat numbers. Standalone or as a ActiveModel validator.\n\n
|
92
127
|
\ * Simple syntax verification\n * Lookup via the VIES web service\n * Works standalone
|
93
128
|
without any gem dependencies\n * (Optional) ActiveModel/Rails3 integration\n *
|
@@ -112,6 +147,8 @@ files:
|
|
112
147
|
- lib/valvat/locales/en.yml
|
113
148
|
- lib/valvat/locales/sv.yml
|
114
149
|
- lib/valvat/lookup.rb
|
150
|
+
- lib/valvat/lookup/request.rb
|
151
|
+
- lib/valvat/lookup/request_with_id.rb
|
115
152
|
- lib/valvat/syntax.rb
|
116
153
|
- lib/valvat/utils.rb
|
117
154
|
- lib/valvat/version.rb
|
@@ -134,15 +171,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
134
171
|
- - ! '>='
|
135
172
|
- !ruby/object:Gem::Version
|
136
173
|
version: '0'
|
174
|
+
segments:
|
175
|
+
- 0
|
176
|
+
hash: 674123835255991256
|
137
177
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
178
|
none: false
|
139
179
|
requirements:
|
140
180
|
- - ! '>='
|
141
181
|
- !ruby/object:Gem::Version
|
142
182
|
version: '0'
|
183
|
+
segments:
|
184
|
+
- 0
|
185
|
+
hash: 674123835255991256
|
143
186
|
requirements: []
|
144
187
|
rubyforge_project:
|
145
|
-
rubygems_version: 1.8.
|
188
|
+
rubygems_version: 1.8.24
|
146
189
|
signing_key:
|
147
190
|
specification_version: 3
|
148
191
|
summary: Validates european vat numbers. Standalone or as a ActiveModel validator.
|