valvat 1.0.0 → 1.0.1
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 +4 -4
- data.tar.gz.sig +0 -0
- data/CHANGES.md +9 -1
- data/README.md +5 -1
- data/certs/yolk.pem +21 -21
- data/lib/valvat/error.rb +2 -2
- data/lib/valvat/local.rb +2 -1
- data/lib/valvat/locales/pt.yml +28 -28
- data/lib/valvat/utils.rb +10 -2
- data/lib/valvat/version.rb +1 -1
- data/spec/active_model/validations/valvat_validator_spec.rb +26 -0
- data/spec/valvat/utils_spec.rb +20 -2
- metadata +22 -22
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c35eea0081e4df97219ee215ea3321c8add02bc130c5b28488f1dca676765dc
|
4
|
+
data.tar.gz: 4ba7b89f223d26d1ac9d967944d6c2e0dbea74c3c6066f1d69d0e2f42ba204c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab9623bd1d680546ca7978751b6536b626d2d5cb9ae35240b5152d4e7c9512e99e025481bf0a844254e6ad14d3f1f320dbf54ab6901387e354b7682c45cb3c3c
|
7
|
+
data.tar.gz: 79a69d5d148b86282f609d66bf053a1b14d4bd86621d7277a5f17d1d1df6c6fd5c9731cff4eca8c8bb9dde9f1265eef7ea03c60d2d66876b0f255d97a9596a6b
|
checksums.yaml.gz.sig
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
p���:��:�Bӻ�7���-�8���A1��
|
2
|
+
�L��W3,��Z��@\��ϳbć�P,DJ�������X���ݧ�8Ըҋ�L�$s�8��o�?>��K��""J��C͒8�W����δ����!��6Ϝ3����&n�qP�P�u�W��������D�<&S��������d#Z��K���n��Y+Jw�`r;I&=�Ў'丌X<���ws�˶�
|
3
|
+
mk��c�k��qk�rh$��:C����ZIƈ��Y��@����/U�
|
4
|
+
���&s��W
|
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGES.md
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
|
2
2
|
### dev
|
3
3
|
|
4
|
-
[full changelog](http://github.com/yolk/valvat/compare/
|
4
|
+
[full changelog](http://github.com/yolk/valvat/compare/v1.0.1...master)
|
5
|
+
|
6
|
+
### 1.0.1 / 2020-12-06
|
7
|
+
|
8
|
+
[full changelog](http://github.com/yolk/valvat/compare/v1.0.0...v1.0.1)
|
9
|
+
|
10
|
+
* Added missing spaces to malformatted portuegese locale file
|
11
|
+
* Removed GB from EU_COUNTRIES / EU_MEMBER_STATES but kept support
|
12
|
+
* Fixed typo in error message: UNK(N)OWN (by [Igor Gonchar](https://github.com/gigorok))
|
5
13
|
|
6
14
|
### 1.0.0 / 2020-11-06
|
7
15
|
|
data/README.md
CHANGED
@@ -5,6 +5,10 @@ valvat
|
|
5
5
|
|
6
6
|
Validates european vat numbers. Standalone or as a ActiveModel validator.
|
7
7
|
|
8
|
+
## A note on Brexit
|
9
|
+
|
10
|
+
Valvat supports validating VAT-IDs from the UK by syntax & checksum for now. Validation against the VIES web service will probably stop working (and return `false`) in 2021.
|
11
|
+
|
8
12
|
## Features
|
9
13
|
|
10
14
|
* Simple syntax verification
|
@@ -201,7 +205,7 @@ To allow vat numbers from outside of europe, add something like this to your mod
|
|
201
205
|
validates :vat_number, valvat: true, if: :eu?
|
202
206
|
|
203
207
|
def eu?
|
204
|
-
Valvat::Utils::
|
208
|
+
Valvat::Utils::EU_MEMBER_STATES.include?(country_code)
|
205
209
|
end
|
206
210
|
end
|
207
211
|
|
data/certs/yolk.pem
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
-----BEGIN CERTIFICATE-----
|
2
2
|
MIIELDCCApSgAwIBAgIBATANBgkqhkiG9w0BAQsFADAgMR4wHAYDVQQDDBVzZWJh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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
-----END CERTIFICATE-----
|
16
|
+
KoZIhvcNAQELBQADggGBAIky67U9hnB8d4qMKwXHGb3Ne7JLvEigtEhjqGlDVecb
|
17
|
+
C94vQ8Jg7lYB3kKVjvFN2drptq/JUpxmAxPQIqfx39gKcKyv0BjkroVFE8MS1324
|
18
|
+
khMOZFOoSPMd9pkpm7oJ1M+sCYcUM+tPKnU8Ojq6r9j5b5XrbxG8YSpwahva3Vap
|
19
|
+
1g0+3KzuWPpFjFen1VbS/Sb1cyE5uQtUj7lVcdhF3EFvzXkUMUUtJ4xsk114znFO
|
20
|
+
986sKab5AjlJ7TnsmPphCv/UXans7rAVB2lnozlt/kw6dcct5JD4kz1tD6AmO5Qd
|
21
|
+
jWRuKNZs66GBglRvseKoypXz1XDCCu1m/uI1IGmKnq8Ry+IeRq9RnlvbfPvSxRIx
|
22
|
+
9aowoL79T9plhcEcEX/KYRp8ht1z+3Vyk2UVZP8Xl5x+K44co5xdhljYi1gtw0w8
|
23
|
+
KzzULF0bF9oNpXwBEamlH2myNb19u1W8ijobQ7Y19ca8UFHr5LI32ZW5Zlmep8je
|
24
|
+
vb+o07oLRx3t2T/EO4DZ1w==
|
25
|
+
-----END CERTIFICATE-----
|
data/lib/valvat/error.rb
CHANGED
@@ -2,7 +2,7 @@ class Valvat
|
|
2
2
|
Error = Class.new(RuntimeError)
|
3
3
|
|
4
4
|
class ViesError < Error
|
5
|
-
def initialize(faultstring='
|
5
|
+
def initialize(faultstring='UNKNOWN')
|
6
6
|
@faultstring = faultstring
|
7
7
|
end
|
8
8
|
|
@@ -25,4 +25,4 @@ class Valvat
|
|
25
25
|
RateLimitError = Class.new(ViesError)
|
26
26
|
|
27
27
|
UnknownViesError = Class.new(ViesError)
|
28
|
-
end
|
28
|
+
end
|
data/lib/valvat/local.rb
CHANGED
@@ -22,8 +22,9 @@ class Valvat
|
|
22
22
|
Valvat::Utils.vat_country_to_iso_country(vat_country_code)
|
23
23
|
end
|
24
24
|
|
25
|
+
# TODO: Remove method / not in use
|
25
26
|
def european?
|
26
|
-
Valvat::Utils::
|
27
|
+
Valvat::Utils::EU_MEMBER_STATES.include?(iso_country_code)
|
27
28
|
end
|
28
29
|
|
29
30
|
def to_a
|
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/utils.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
1
3
|
class Valvat
|
2
4
|
module Utils
|
3
5
|
|
4
|
-
|
6
|
+
EU_MEMBER_STATES = %w(AT BE BG CY CZ DE DK EE ES FI FR GR HR HU IE IT LT LU LV MT NL PL PT RO SE SI SK)
|
7
|
+
SUPPORTED_STATES = EU_MEMBER_STATES + %w(GB)
|
8
|
+
EU_COUNTRIES = EU_MEMBER_STATES # TODO: Remove constant
|
5
9
|
COUNTRY_PATTERN = /\A([A-Z]{2})(.+)\Z/
|
6
10
|
NORMALIZE_PATTERN = /[[:space:][:punct:][:cntrl:]]+/
|
7
11
|
|
@@ -9,7 +13,7 @@ class Valvat
|
|
9
13
|
COUNTRY_PATTERN =~ vat
|
10
14
|
result = [$1, $2]
|
11
15
|
iso_country = vat_country_to_iso_country(result[0])
|
12
|
-
|
16
|
+
country_is_supported?(iso_country) ? result : [nil, nil]
|
13
17
|
end
|
14
18
|
|
15
19
|
def self.normalize(vat)
|
@@ -23,5 +27,9 @@ class Valvat
|
|
23
27
|
def self.iso_country_to_vat_country(iso_country)
|
24
28
|
iso_country == "GR" ? "EL" : iso_country
|
25
29
|
end
|
30
|
+
|
31
|
+
def self.country_is_supported?(iso_country)
|
32
|
+
SUPPORTED_STATES.include?(iso_country)
|
33
|
+
end
|
26
34
|
end
|
27
35
|
end
|
data/lib/valvat/version.rb
CHANGED
@@ -42,6 +42,10 @@ if defined?(ActiveModel)
|
|
42
42
|
end
|
43
43
|
|
44
44
|
describe Invoice do
|
45
|
+
before do
|
46
|
+
I18n.locale = :en
|
47
|
+
end
|
48
|
+
|
45
49
|
context "with valid VAT number" do
|
46
50
|
it "should be valid" do
|
47
51
|
expect(Invoice.new(vat_number: "DE259597697")).to be_valid
|
@@ -60,6 +64,28 @@ if defined?(ActiveModel)
|
|
60
64
|
expect(invoice.errors[:vat_number]).to eql(["is not a valid German VAT number"])
|
61
65
|
end
|
62
66
|
|
67
|
+
context "on DE locale" do
|
68
|
+
before do
|
69
|
+
I18n.locale = :de
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should add translated error message" do
|
73
|
+
invoice.valid?
|
74
|
+
expect(invoice.errors[:vat_number]).to eql(["ist keine gültige deutsche USt-IdNr."])
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context "on PT locale" do
|
79
|
+
before do
|
80
|
+
I18n.locale = :pt
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should add translated error message" do
|
84
|
+
invoice.valid?
|
85
|
+
expect(invoice.errors[:vat_number]).to eql(["O NIF alemão não é válido."])
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
63
89
|
context "with i18n translation in place" do
|
64
90
|
before do
|
65
91
|
I18n.backend.store_translations(:en, activemodel: {
|
data/spec/valvat/utils_spec.rb
CHANGED
@@ -59,7 +59,7 @@ describe Valvat::Utils do
|
|
59
59
|
expect(Valvat::Utils.vat_country_to_iso_country("EL")).to eql("GR")
|
60
60
|
end
|
61
61
|
|
62
|
-
Valvat::Utils::
|
62
|
+
Valvat::Utils::EU_MEMBER_STATES.each do |iso|
|
63
63
|
it "returns unchanged iso country code '#{iso}'" do
|
64
64
|
expect(Valvat::Utils.vat_country_to_iso_country(iso)).to eql(iso)
|
65
65
|
end
|
@@ -71,9 +71,27 @@ describe Valvat::Utils do
|
|
71
71
|
expect(Valvat::Utils.iso_country_to_vat_country("GR")).to eql("EL")
|
72
72
|
end
|
73
73
|
|
74
|
-
Valvat::Utils::
|
74
|
+
Valvat::Utils::EU_MEMBER_STATES.each do |c|
|
75
75
|
it "returns unchanged VAT country code '#{c}'" do
|
76
76
|
expect(Valvat::Utils.iso_country_to_vat_country(c)).to eql(c)
|
77
|
+
end unless c == "GR"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#country_is_supported?" do
|
82
|
+
Valvat::Utils::EU_MEMBER_STATES.each do |code|
|
83
|
+
it "returns true on #{code}" do
|
84
|
+
expect(Valvat::Utils.country_is_supported?(code)).to eql(true)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
it "returns true on GB" do
|
89
|
+
expect(Valvat::Utils.country_is_supported?("GB")).to eql(true)
|
90
|
+
end
|
91
|
+
|
92
|
+
["US", "AE", "CA", "CN", "BR", "AU", "NO", "ML"].each do |code|
|
93
|
+
it "returns false on #{code}" do
|
94
|
+
expect(Valvat::Utils.country_is_supported?(code)).to eql(false)
|
77
95
|
end
|
78
96
|
end
|
79
97
|
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: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Munz
|
@@ -11,30 +11,30 @@ cert_chain:
|
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
13
|
MIIELDCCApSgAwIBAgIBATANBgkqhkiG9w0BAQsFADAgMR4wHAYDVQQDDBVzZWJh
|
14
|
-
|
14
|
+
c3RpYW4vREM9eW8vREM9bGswHhcNMjEwMTA2MTAzMDU3WhcNMjIwMTA2MTAzMDU3
|
15
15
|
WjAgMR4wHAYDVQQDDBVzZWJhc3RpYW4vREM9eW8vREM9bGswggGiMA0GCSqGSIb3
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
16
|
+
DQEBAQUAA4IBjwAwggGKAoIBgQC1KB7VOGa6pr926eaL2xCrnbnTxadpjq+6JoFj
|
17
|
+
6rvDpmgD8wkdfU7aFTwBiEK9JKzhqCoW86Rt/8wOrEJRMXz1QBbpMBSrubtMB+0/
|
18
|
+
N59hKPLwgBkhbxY7BwGnujxnTICgiGzkhjlgBe/MisoabfK5Tn84GWVk5e0/LUp1
|
19
|
+
qTRkSgcaDlnKs2/dAUo1lXHa13TJeemgz76TYx4p4J2w7VGh7WS2ax5SNWKw+J+q
|
20
|
+
HVSHT2Chc+a7As2cJyU/r2jX0oqSfvyg09CmF0inUByk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H2myNb19u1W8ijobQ7Y19ca8UFHr5LI32ZW5Zlmep8je
|
35
|
+
vb+o07oLRx3t2T/EO4DZ1w==
|
36
36
|
-----END CERTIFICATE-----
|
37
|
-
date:
|
37
|
+
date: 2021-01-06 00:00:00.000000000 Z
|
38
38
|
dependencies:
|
39
39
|
- !ruby/object:Gem::Dependency
|
40
40
|
name: savon
|
metadata.gz.sig
CHANGED
Binary file
|