vat_check 0.0.5 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.editorconfig +12 -0
- data/.gitignore +17 -0
- data/.travis.yml +10 -0
- data/Gemfile +3 -0
- data/README.md +129 -0
- data/lib/vat_check.rb +6 -5
- data/lib/vat_check/requests.rb +2 -2
- data/lib/vat_check/version.rb +3 -0
- data/vat_check.gemspec +37 -0
- metadata +27 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d2b59db2a077b774b3a45f9ef3e56ccf07e3880d04629720e02956f3c0c86db6
|
4
|
+
data.tar.gz: 74f27a5c342b028fc5e2cf263b74b15645a8573c0b209204b2c35fd1721f04b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ad491dc114a787d8953a24e655d8d5ebbc84c365c2d78669c60c3387b7e16f69f154d8865f57f3f8d0f42124b6778d543b5cd50f7d0bef13a0e08bd2160c2e6
|
7
|
+
data.tar.gz: 333eeb1ebfa7e53ae6db4d377d7e75e770e302b10c88349f8b327a5a8d1a35e3f67eca5dc0b38041c575e0b169d44f946e3af16b42dd36209eabe7152a1a2deb
|
data/.editorconfig
ADDED
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
# VatCheck [![RubyGems](http://img.shields.io/gem/v/vat_check.svg?style=flat-square)](https://rubygems.org/gems/vat_check) [![Build Status](http://img.shields.io/travis/taxjar/vat_check.svg?style=flat-square)](https://travis-ci.org/taxjar/vat_check)
|
2
|
+
|
3
|
+
Need to verify VAT identification numbers in Ruby? VatCheck makes it easy and simple:
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
vat = VatCheck.new('GB333289454')
|
7
|
+
puts 'Legit' if vat.valid?
|
8
|
+
```
|
9
|
+
|
10
|
+
That's it. VatCheck first performs a regex validation. If it passes, it attempts to verify on VIES. [Sometimes it's up, sometimes it's down](http://ec.europa.eu/taxation_customs/vies/help.html). When it's down `valid?` gracefully falls back to regex.
|
11
|
+
|
12
|
+
## Getting Started
|
13
|
+
|
14
|
+
Install it via RubyGems in your terminal:
|
15
|
+
|
16
|
+
```
|
17
|
+
gem install vat_check
|
18
|
+
```
|
19
|
+
|
20
|
+
Or in your Gemfile:
|
21
|
+
|
22
|
+
```
|
23
|
+
gem 'vat_check', '~> 1.0'
|
24
|
+
```
|
25
|
+
|
26
|
+
**Note:** VatCheck requires Ruby 2.3 or greater.
|
27
|
+
|
28
|
+
## Basic Usage
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
require 'vat_check'
|
32
|
+
vat = VatCheck.new('VATIN')
|
33
|
+
```
|
34
|
+
|
35
|
+
This returns some nifty helper methods and attributes for all your VAT needs:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
vat.regex # True if regex validated
|
39
|
+
vat.vies # True if VIES response is valid
|
40
|
+
vat.vies_available # True if VIES available
|
41
|
+
vat.response # Hash if VIES available
|
42
|
+
|
43
|
+
vat.valid? # True if regex and VIES validated (if available)
|
44
|
+
vat.exists? # True if VIES available and VATIN exists
|
45
|
+
```
|
46
|
+
|
47
|
+
`valid?` will be your goto method for quick verification. If VIES is currently available, you'll get a response hash:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
{
|
51
|
+
:country_code => "GB",
|
52
|
+
:vat_number => "333289454",
|
53
|
+
:request_date => Date.today,
|
54
|
+
:valid => true,
|
55
|
+
:name => "BRITISH BROADCASTING CORPORATION",
|
56
|
+
:address => "FAO ALEX FITZPATRICK\nBBC GROUP VAT MANAGER\nTHE LIGHT HOUSE (1ST FLOOR)\nMEDIA VILLAGE, 201 WOOD LANE\nLONDON\nW127TQ"
|
57
|
+
}
|
58
|
+
```
|
59
|
+
|
60
|
+
If you'd like to expose that info, go ahead and use `exists?`:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
if vat.exists?
|
64
|
+
puts vat.response.name
|
65
|
+
puts vat.response.address
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
69
|
+
## Examples
|
70
|
+
|
71
|
+
VIES is available, the VAT is formatted correctly, and the VAT is registered to a business:
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
vat = VatCheck.new('GB333289454')
|
75
|
+
vat.regex # true
|
76
|
+
vat.vies_available # true
|
77
|
+
vat.vies # true
|
78
|
+
vat.response # {:country_code=>"GB", :vat_number=>"333289454", :request_date=>#<Date: 2016-01-13 ((2457401j,0s,0n),+0s,2299161j)>, :valid=>true, :name=>"BRITISH BROADCASTING CORPORATION", :address=>"FAO ALEX FITZPATRICK\nBBC GROUP VAT MANAGER\nTHE LIGHT HOUSE (1ST FLOOR)\nMEDIA VILLAGE, 201 WOOD LANE\nLONDON\nW12 7TQ"}
|
79
|
+
vat.valid? # true
|
80
|
+
vat.exists? # true
|
81
|
+
```
|
82
|
+
|
83
|
+
VIES is available, the VAT ID is formatted correctly, but the VAT ID is not registered to a business:
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
vat = VatCheck.new('GB999999999')
|
87
|
+
vat.regex # true
|
88
|
+
vat.vies_available # true
|
89
|
+
vat.vies # false
|
90
|
+
vat.response # {:country_code=>"GB", :vat_number=>"999999999", :request_date=>#<Date: 2016-01-13 ((2457401j,0s,0n),+0s,2299161j)>, :valid=>false, :name=>"---", :address=>"---"}
|
91
|
+
vat.valid? # false
|
92
|
+
vat.exists? # false
|
93
|
+
```
|
94
|
+
|
95
|
+
VAT is not formatted correctly:
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
vat = VatCheck.new('XX123456789')
|
99
|
+
vat.regex # false
|
100
|
+
vat.vies # false
|
101
|
+
vat.vies_available # false
|
102
|
+
vat.response # {}
|
103
|
+
vat.valid? # false
|
104
|
+
vat.exists? # false
|
105
|
+
```
|
106
|
+
|
107
|
+
VAT is formatted correctly but VIES is unavailable:
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
vat = VatCheck.new('GB333289454')
|
111
|
+
vat.regex # true
|
112
|
+
vat.vies_available # false
|
113
|
+
vat.vies # false
|
114
|
+
vat.response # {:error=>"Service unavailable"}
|
115
|
+
vat.valid? # true
|
116
|
+
vat.exists? # false
|
117
|
+
```
|
118
|
+
|
119
|
+
VAT is formatted correctly but VIES times out:
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
vat = VatCheck.new('GB333289454')
|
123
|
+
vat.regex # true
|
124
|
+
vat.vies_available # false
|
125
|
+
vat.vies # false
|
126
|
+
vat.response # {:error=>"Service timed out"}
|
127
|
+
vat.valid? # true
|
128
|
+
vat.exists? # false
|
129
|
+
```
|
data/lib/vat_check.rb
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
require 'vat_check/utility'
|
2
|
+
require 'vat_check/format'
|
3
|
+
require 'vat_check/requests'
|
4
|
+
require 'vat_check/version'
|
5
|
+
|
1
6
|
class VatCheck
|
2
7
|
attr_reader :regex, :vies, :vies_available, :response
|
3
8
|
|
@@ -18,8 +23,4 @@ class VatCheck
|
|
18
23
|
def exists?
|
19
24
|
return @vies
|
20
25
|
end
|
21
|
-
end
|
22
|
-
|
23
|
-
require 'vat_check/utility'
|
24
|
-
require 'vat_check/format'
|
25
|
-
require 'vat_check/requests'
|
26
|
+
end
|
data/lib/vat_check/requests.rb
CHANGED
@@ -3,7 +3,7 @@ require 'savon'
|
|
3
3
|
class VatCheck
|
4
4
|
module Request
|
5
5
|
def self.lookup(vat)
|
6
|
-
client = Savon.client(wsdl: '
|
6
|
+
client = Savon.client(wsdl: 'https://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl', follow_redirects: true, log: false, log_level: :debug, pretty_print_xml: false)
|
7
7
|
country_code, vat_number = VatCheck::Utility.split(vat)
|
8
8
|
begin
|
9
9
|
response = client.call(:check_vat, message: {country_code: country_code, vat_number: vat_number}, message_tag: :checkVat)
|
@@ -19,4 +19,4 @@ class VatCheck
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
22
|
-
end
|
22
|
+
end
|
data/vat_check.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'vat_check/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'vat_check'
|
7
|
+
s.version = VatCheck::VERSION
|
8
|
+
s.authors = ['TaxJar']
|
9
|
+
s.email = 'support@taxjar.com'
|
10
|
+
|
11
|
+
s.summary = 'Validate VAT IDs'
|
12
|
+
s.description = 'A gem by TaxJar that can be used to validate VAT IDs'
|
13
|
+
s.homepage = 'https://taxjar.com'
|
14
|
+
s.license = 'MIT'
|
15
|
+
|
16
|
+
if s.respond_to?(:metadata)
|
17
|
+
s.metadata['source_code_uri'] = 'https://github.com/taxjar/vat_check'
|
18
|
+
s.metadata['bug_tracker_uri'] = 'https://github.com/taxjar/vat_check/issues'
|
19
|
+
else
|
20
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
21
|
+
'public gem pushes.'
|
22
|
+
end
|
23
|
+
|
24
|
+
s.require_paths = ['lib']
|
25
|
+
s.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
|
29
|
+
s.required_ruby_version = '>= 2.3'
|
30
|
+
|
31
|
+
s.add_runtime_dependency 'savon', '~> 2.12', '>= 2.12.0'
|
32
|
+
|
33
|
+
s.add_development_dependency 'rspec', '~> 3.4'
|
34
|
+
s.add_development_dependency 'vcr', '~> 5.1', '>= 5.1.0'
|
35
|
+
s.add_development_dependency 'webmock', '~> 3.8', '>= 3.8.3'
|
36
|
+
s.add_development_dependency 'mocha', '~> 1.1', '>= 1.1.0'
|
37
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vat_check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TaxJar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: savon
|
@@ -16,20 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2.
|
19
|
+
version: '2.12'
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 2.
|
22
|
+
version: 2.12.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '2.
|
29
|
+
version: '2.12'
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 2.
|
32
|
+
version: 2.12.0
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: rspec
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -50,40 +50,40 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
53
|
+
version: '5.1'
|
54
54
|
- - ">="
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version:
|
56
|
+
version: 5.1.0
|
57
57
|
type: :development
|
58
58
|
prerelease: false
|
59
59
|
version_requirements: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
61
|
- - "~>"
|
62
62
|
- !ruby/object:Gem::Version
|
63
|
-
version: '
|
63
|
+
version: '5.1'
|
64
64
|
- - ">="
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version:
|
66
|
+
version: 5.1.0
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
68
|
name: webmock
|
69
69
|
requirement: !ruby/object:Gem::Requirement
|
70
70
|
requirements:
|
71
71
|
- - "~>"
|
72
72
|
- !ruby/object:Gem::Version
|
73
|
-
version: '
|
73
|
+
version: '3.8'
|
74
74
|
- - ">="
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
76
|
+
version: 3.8.3
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
81
|
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version: '
|
83
|
+
version: '3.8'
|
84
84
|
- - ">="
|
85
85
|
- !ruby/object:Gem::Version
|
86
|
-
version:
|
86
|
+
version: 3.8.3
|
87
87
|
- !ruby/object:Gem::Dependency
|
88
88
|
name: mocha
|
89
89
|
requirement: !ruby/object:Gem::Requirement
|
@@ -110,14 +110,23 @@ executables: []
|
|
110
110
|
extensions: []
|
111
111
|
extra_rdoc_files: []
|
112
112
|
files:
|
113
|
+
- ".editorconfig"
|
114
|
+
- ".gitignore"
|
115
|
+
- ".travis.yml"
|
116
|
+
- Gemfile
|
117
|
+
- README.md
|
113
118
|
- lib/vat_check.rb
|
114
119
|
- lib/vat_check/format.rb
|
115
120
|
- lib/vat_check/requests.rb
|
116
121
|
- lib/vat_check/utility.rb
|
117
|
-
|
122
|
+
- lib/vat_check/version.rb
|
123
|
+
- vat_check.gemspec
|
124
|
+
homepage: https://taxjar.com
|
118
125
|
licenses:
|
119
126
|
- MIT
|
120
|
-
metadata:
|
127
|
+
metadata:
|
128
|
+
source_code_uri: https://github.com/taxjar/vat_check
|
129
|
+
bug_tracker_uri: https://github.com/taxjar/vat_check/issues
|
121
130
|
post_install_message:
|
122
131
|
rdoc_options: []
|
123
132
|
require_paths:
|
@@ -126,7 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
135
|
requirements:
|
127
136
|
- - ">="
|
128
137
|
- !ruby/object:Gem::Version
|
129
|
-
version: 2.
|
138
|
+
version: '2.3'
|
130
139
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
140
|
requirements:
|
132
141
|
- - ">="
|
@@ -134,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
143
|
version: '0'
|
135
144
|
requirements: []
|
136
145
|
rubyforge_project:
|
137
|
-
rubygems_version: 2.
|
146
|
+
rubygems_version: 2.7.6.2
|
138
147
|
signing_key:
|
139
148
|
specification_version: 4
|
140
149
|
summary: Validate VAT IDs
|