red_tape 1.0.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5afad782530c754f09162af579b7b9746dce23cb
4
+ data.tar.gz: 0ea8304a06a0c6e1d2a7b81e274136b0f44f86d1
5
+ SHA512:
6
+ metadata.gz: 486094c7c50cf92d3e490c724f2b9d3d24fda38787abdb50b9f61fe68ebbadb35b7a82fc0fcbf7858b3b4c6a9c5ce61dc5bb4ad7d74279322f6881a15d20c0b9
7
+ data.tar.gz: c81cbd34179e6063f1796003c3e778bb5caffa8c1b678b935a2e81a99b400e168563c5a3d9ce4a57ebcc962b326c41ef87f1104cfaa5047f63349ddddd6e3326
@@ -0,0 +1,35 @@
1
+ *.rbc
2
+ capybara-*.html
3
+ .rspec
4
+ /log
5
+ /tmp
6
+ /db/*.sqlite3
7
+ /db/*.sqlite3-journal
8
+ /public/system
9
+ /coverage/
10
+ /spec/tmp
11
+ **.orig
12
+ rerun.txt
13
+ pickle-email-*.html
14
+
15
+ # TODO Comment out these rules if you are OK with secrets being uploaded to the repo
16
+ config/initializers/secret_token.rb
17
+ config/secrets.yml
18
+
19
+ ## Environment normalisation:
20
+ /.bundle
21
+ /vendor/bundle
22
+
23
+ # these should all be checked in to normalise the environment:
24
+ # Gemfile.lock, .ruby-version, .ruby-gemset
25
+
26
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
27
+ .rvmrc
28
+
29
+ # if using bower-rails ignore default bower_components path bower.json files
30
+ /vendor/assets/bower_components
31
+ *.bowerrc
32
+ bower.json
33
+
34
+ # Ignore pow environment settings
35
+ .powenv
@@ -0,0 +1 @@
1
+ 2.4.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in red_tape.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Matthias Grosser
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,30 @@
1
+ # RedTape
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/red_tape`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ In your Gemfile:
10
+
11
+ ```ruby
12
+ gem 'red_tape'
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```ruby
18
+
19
+ # quick syntax
20
+ RedTape.valid?('DE123456789', 'ATU33864707') => true
21
+
22
+ # if you want detailed error messages from the Bundeszentralamt
23
+ validator = RedTape.validator('DE123456789', 'FOO', company_name: 'Red Bull GmbH', city: 'Fuschl am See')
24
+
25
+ validator.valid?
26
+ => false
27
+
28
+ validator.status
29
+ => :invalid_country
30
+ ```
@@ -0,0 +1,23 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rdoc/task'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Run all tests'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.test_files = FileList['test/*_test.rb']
12
+ t.verbose = true
13
+ end
14
+
15
+ desc 'Generate documentation'
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'Maybee'
19
+ rdoc.options << '--line-numbers' << '--inline-source'
20
+ rdoc.rdoc_files.include('README')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
23
+
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "red_tape"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,39 @@
1
+ require 'xmlrpc/client'
2
+ require 'rexml/document'
3
+ require 'xmlrpc/parser'
4
+
5
+ require_relative 'red_tape/version'
6
+ require_relative 'red_tape/errors'
7
+ require_relative 'red_tape/support'
8
+ require_relative 'red_tape/validator'
9
+
10
+ module RedTape
11
+ extend Support
12
+
13
+ COUNTRIES = %w[BE BG DK DE EE FI FR EL GB IE IT LV LT LU MT NL AT PL PT RO SE SK SL ES CZ HU CY]
14
+
15
+ class << self
16
+ def validator_for(country)
17
+ Validators.const_get(country.to_sym) if Validators.constants.include?(country.to_sym)
18
+ end
19
+
20
+ def validatable?(own, other)
21
+ !!(COUNTRIES.include?(country(other)) && validator_for(country(own)))
22
+ end
23
+
24
+ def validator(own, other, options = {})
25
+ if klass = validator_for(country(own))
26
+ klass.new(own, other, options)
27
+ end
28
+ end
29
+
30
+ def valid?(own, other)
31
+ if validator = validator_for(country(own))
32
+ validator.new(own, other).valid?
33
+ end
34
+ end
35
+
36
+ end
37
+ end
38
+
39
+ require_relative 'red_tape/validators/de'
@@ -0,0 +1,5 @@
1
+ module RedTape
2
+ class Error < StandardError; end
3
+
4
+ class ValidationError < Error; end
5
+ end
@@ -0,0 +1,9 @@
1
+ module RedTape
2
+ module Support
3
+ private
4
+
5
+ def country(vat_id)
6
+ vat_id.upcase[0..1]
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ module RedTape
2
+ class Validator
3
+ include Support
4
+
5
+ class << self
6
+ def country
7
+ raise NotImplementedError
8
+ end
9
+ end
10
+
11
+ def valid?(own, other)
12
+ raise NotImplementedError
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,76 @@
1
+ module RedTape
2
+ module Validators
3
+ class DE < Validator
4
+
5
+ attr_reader :own, :other, :options, :status
6
+
7
+ def self.country; 'DE'; end
8
+
9
+ def initialize(own, other, options = {})
10
+ @own, @other, @options = own, other, options
11
+ end
12
+
13
+ def result
14
+ @result ||= {}
15
+ end
16
+
17
+ def status_code
18
+ result['ErrorCode']
19
+ end
20
+
21
+ def valid?
22
+ validate
23
+ rescue => e
24
+ raise ValidationError.new(e)
25
+ end
26
+
27
+ private
28
+
29
+ def validate
30
+ uri = URI('https://evatr.bff-online.de/evatrRPC')
31
+ params = { UstId_1: own, UstId_2: other,
32
+ Firmenname: options[:company_name],
33
+ Ort: options[:city],
34
+ PLZ: options[:postal_code],
35
+ Strasse: options[:street],
36
+ Druck: options[:print] ? 'Ja' : 'Nein' }
37
+ uri.query = URI.encode_www_form(params)
38
+ xml = Net::HTTP.get(uri)
39
+ parser = XMLRPC::XMLParser::REXMLStreamParser::StreamListener.new
40
+ parser.parse(xml)
41
+ @result = Hash[parser.params]
42
+ set_status
43
+ return true if '200' == status_code
44
+ false
45
+ end
46
+
47
+ def set_status
48
+ @status =
49
+ { '200' => :valid, #'Die angefragte USt-IdNr. ist gültig.',
50
+ '201' => :invalid, #'Die angefragte USt-IdNr. ist ungültig.',
51
+ '202' => :unregistered, #'Die angefragte USt-IdNr. ist ungültig. Sie ist nicht in der Unternehmerdatei des betreffenden EU-Mitgliedstaates registriert. Hinweis: Ihr Geschäftspartner kann seine gültige USt-IdNr. bei der für ihn zuständigen Finanzbehörde in Erfahrung bringen. Möglicherweise muss er einen Antrag stellen, damit seine USt-IdNr. in die Datenbank aufgenommen wird.',
52
+ '203' => :invalid, #"Die angefragte USt-IdNr. ist ungültig. Sie ist erst ab dem #{result['Gueltig_ab']} gültig",
53
+ '204' => :expired, #"Die angefragte USt-IdNr. ist ungültig. Sie war im Zeitraum von #{result['Gueltig_ab']} bis #{result['Gueltig_bis']} gültig",
54
+ '205' => :unavailable, #'Ihre Anfrage kann derzeit durch den angefragten EU-Mitgliedstaat oder aus anderen Gründen nicht beantwortet werden. Bitte versuchen Sie es später noch einmal. Bei wiederholten Problemen wenden Sie sich bitte an das Bundeszentralamt für Steuern - Dienstsitz Saarlouis.',
55
+ '206' => :own_vat_id_invalid, #'Ihre deutsche USt-IdNr. ist ungültig. Eine Bestätigungsanfrage ist daher nicht möglich. Den Grund hierfür können Sie beim Bundeszentralamt für Steuern - Dienstsitz Saarlouis - erfragen.',
56
+ '207' => :unauthorized, #'Ihnen wurde die deutsche USt-IdNr. ausschliesslich zu Zwecken der Besteuerung des innergemeinschaftlichen Erwerbs erteilt. Sie sind somit nicht berechtigt, Bestätigungsanfragen zu stellen.',
57
+ '208' => :busy, #'Für die von Ihnen angefragte USt-IdNr. läuft gerade eine Anfrage von einem anderen Nutzer. Eine Bearbeitung ist daher nicht möglich. Bitte versuchen Sie es später noch einmal.',
58
+ '209' => :invalid_format, #'Die angefragte USt-IdNr. ist ungültig. Sie entspricht nicht dem Aufbau, der für diesen EU-Mitgliedstaat gilt.',
59
+ '210' => :invalid_checksum, #'Die angefragte USt-IdNr. ist ungültig. Sie entspricht nicht den Prüfziffernregeln die für diesen EU-Mitgliedstaat gelten.',
60
+ '211' => :invalid_characters, #'Die angefragte USt-IdNr. ist ungültig. Sie enthält unzulässige Zeichen (wie z.B. Leerzeichen oder Punkt oder Bindestrich usw.).',
61
+ '212' => :invalid_country, #'Die angefragte USt-IdNr. ist ungültig. Sie enthält ein unzulässiges Länderkennzeichen.',
62
+ '213' => :german, #'Die Abfrage einer deutschen USt-IdNr. ist nicht möglich.',
63
+ '214' => :own_vat_id_invalid, #'Ihre deutsche USt-IdNr. ist fehlerhaft. Sie beginnt mit "DE" gefolgt von 9 Ziffern.',
64
+ '215' => :data_insufficient_for_simple_validation, #'Ihre Anfrage enthält nicht alle notwendigen Angaben für eine einfache Bestätigungsanfrage und kann deshalb nicht bearbeitet werden.',
65
+ '216' => :data_insufficient_for_extended_validation, #'Ihre Anfrage enthält nicht alle notwendigen Angaben für eine qualifizierte Bestätigungsanfrage (Ihre deutsche USt-IdNr., die ausl. USt-IdNr., Firmenname einschl. Rechtsform und Ort). Es wurde eine einfache Bestätigungsanfrage durchgeführt mit folgenden Ergebnis: Die angefragte USt-IdNr. ist gültig.',
66
+ '217' => :query_error, #'Bei der Verarbeitung der Daten aus dem angefragten EU-Mitgliedstaat ist ein Fehler aufgetreten. Ihre Anfrage kann deshalb nicht bearbeitet werden.',
67
+ '218' => :simple_valid, #'Eine qualifizierte Bestätigung ist zur Zeit nicht möglich. Es wurde eine einfache Bestätigungsanfrage mit folgendem Ergebnis durchgeführt: Die angefragte USt-IdNr. ist gültig.',
68
+ '219' => :query_error_simple_valid, #'Bei der Durchführung der qualifizierten Bestätigungsanfrage ist ein Fehler aufgetreten. Es wurde eine einfache Bestätigungsanfrage mit folgendem Ergebnis durchgeführt: Die angefragte USt-IdNr. ist gültig.',
69
+ '220' => :print_error, #'Bei der Anforderung der amtlichen Bestätigungsmitteilung ist ein Fehler aufgetreten. Sie werden kein Schreiben erhalten.',
70
+ '221' => :unprocessable_request, #'Die Anfragedaten enthalten nicht alle notwendigen Parameter oder einen ungültigen Datentyp. Weitere Informationen erhalten Sie bei den Hinweisen zum Schnittstellen-Aufruf.',
71
+ '999' => :service_unavailable #'Eine Bearbeitung Ihrer Anfrage ist zurzeit nicht möglich. Bitte versuchen Sie es später noch einmal.'
72
+ }[status_code]
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,3 @@
1
+ module RedTape
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'red_tape/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "red_tape"
8
+ spec.version = RedTape::VERSION
9
+ spec.authors = ["Matthias Grosser"]
10
+ spec.email = ["mtgrosser@gmx.net"]
11
+
12
+ spec.summary = %q{Finanzamt-compliant VAT ID validation}
13
+ spec.description = %q{Extended validation using the German Bundeszentralamt für Steuern XML RPC API}
14
+ spec.homepage = "https://github.com/mtgrosser/red_tape"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = '>= 2.3.0'
22
+
23
+ spec.add_dependency 'xmlrpc', '~> 0.3.0'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.9"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ #spec.add_development_dependency 'net-http-spy'
28
+ spec.add_development_dependency 'minitest'
29
+ spec.add_development_dependency 'webmock'
30
+ spec.add_development_dependency 'byebug'
31
+ spec.add_development_dependency 'simplecov'
32
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: red_tape
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Matthias Grosser
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-04-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: xmlrpc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.3.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Extended validation using the German Bundeszentralamt für Steuern XML
112
+ RPC API
113
+ email:
114
+ - mtgrosser@gmx.net
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".ruby-version"
121
+ - Gemfile
122
+ - LICENSE
123
+ - README.md
124
+ - Rakefile
125
+ - bin/console
126
+ - bin/setup
127
+ - lib/red_tape.rb
128
+ - lib/red_tape/errors.rb
129
+ - lib/red_tape/support.rb
130
+ - lib/red_tape/validator.rb
131
+ - lib/red_tape/validators/de.rb
132
+ - lib/red_tape/version.rb
133
+ - red_tape.gemspec
134
+ homepage: https://github.com/mtgrosser/red_tape
135
+ licenses: []
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: 2.3.0
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.6.11
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: Finanzamt-compliant VAT ID validation
157
+ test_files: []