validates_as_vat_number 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/CHANGELOG +3 -0
- data/README.markdown +2 -1
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/validates_as_vat_number.rb +10 -6
- metadata +4 -3
data/.gitignore
CHANGED
data/CHANGELOG
ADDED
data/README.markdown
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
## validates_as_vat_number
|
2
2
|
|
3
|
-
Now you can validate
|
3
|
+
Now you can validate VAT using the European service called [VIES](http://ec.europa.eu/taxation_customs/vies/viesspec.do), to ensure it exists. Only require this gem and call validate_as_vat_number on your VAT field, in an Active Record object.
|
4
4
|
|
5
5
|
## Install
|
6
6
|
|
@@ -19,6 +19,7 @@ Then install it.
|
|
19
19
|
validates_as_vat_number :vat
|
20
20
|
end
|
21
21
|
|
22
|
+
|
22
23
|
## Note on Patches/Pull Requests
|
23
24
|
|
24
25
|
* Fork the project.
|
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ begin
|
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "validates_as_vat_number"
|
8
8
|
gem.summary = "Permits VAT validation within ActiveRecord using EU VIES Web Service."
|
9
|
-
gem.description = "Now you can validate
|
9
|
+
gem.description = "Now you can validate VAT using the European service called VIES,
|
10
10
|
to ensure it exists. Only require this gem and call validate_as_vat_number
|
11
11
|
on your VAT field, in an Active Record object."
|
12
12
|
gem.email = "lab@develon.com"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.1
|
@@ -21,20 +21,20 @@ module Develon
|
|
21
21
|
'SK' =>/^SK\d{10}$/ }
|
22
22
|
|
23
23
|
validates_each(attr_names,configuration) do |record, attr_name, value|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
24
|
+
country = country_code(value)
|
25
|
+
if iso3661_country_codes.include?(country)
|
26
|
+
message = configuration[:message] unless structures[country].match(value) && check_vat(country, value.gsub(/^\w\w/, ''))
|
28
27
|
else
|
29
|
-
|
28
|
+
message = 'has an invalid country'
|
30
29
|
end
|
30
|
+
record.errors.add(attr_name, :not_valid, :default => message) unless message.nil?
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
protected
|
35
35
|
|
36
36
|
def vies_driver
|
37
|
-
wsdl = "http://ec.europa.eu/taxation_customs/vies/
|
37
|
+
wsdl = "http://ec.europa.eu/taxation_customs/vies/services/checkVatService?wsdl"
|
38
38
|
@driver = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
|
39
39
|
end
|
40
40
|
|
@@ -42,6 +42,10 @@ module Develon
|
|
42
42
|
@driver = vies_driver unless @driver
|
43
43
|
@driver.checkVat(:countryCode => country_code, :vatNumber => vat_number).valid == 'true'
|
44
44
|
end
|
45
|
+
|
46
|
+
def country_code(vat)
|
47
|
+
vat[0,2].upcase
|
48
|
+
end
|
45
49
|
end
|
46
50
|
end
|
47
51
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validates_as_vat_number
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alessandro Dal Grande
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2010-
|
13
|
+
date: 2010-02-19 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
version: 1.2.9
|
25
25
|
version:
|
26
26
|
description: |-
|
27
|
-
Now you can validate
|
27
|
+
Now you can validate VAT using the European service called VIES,
|
28
28
|
to ensure it exists. Only require this gem and call validate_as_vat_number
|
29
29
|
on your VAT field, in an Active Record object.
|
30
30
|
email: lab@develon.com
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- .autotest
|
40
40
|
- .document
|
41
41
|
- .gitignore
|
42
|
+
- CHANGELOG
|
42
43
|
- LICENSE
|
43
44
|
- README.markdown
|
44
45
|
- Rakefile
|