sigiss 0.1.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,13 @@
1
+ test:
2
+ bauru: https://testebauru.sigiss.com.br/testebauru/ws/sigiss_ws.php
3
+ botucatu: https://testebotucatu.sigiss.com.br/testebotucatu/ws/sigiss_ws.php?wsdl
4
+ marilia: https://testemarilia.sigiss.com.br/testemarilia/ws/sigiss_ws.php?wsdl
5
+ londrina: http://testeiss.londrina.pr.gov.br/ws/v1_03/sigiss_ws.php?wsdl
6
+ riogrande: https://testeriogrande.sigiss.com.br/testeriogrande/ws/sigiss_ws.php?wsdl
7
+
8
+ production:
9
+ bauru: https://bauru.sigiss.com.br/bauru/ws/sigiss_ws.php?wsdl
10
+ botucatu: https://botucatu.sigiss.com.br/botucatu/ws/sigiss_ws.php?wsdl
11
+ londrina: https://iss.londrina.pr.gov.br/ws/v1_03/sigiss_ws.php?wsdl
12
+ marilia: https://marilia.sigiss.com.br/marilia/ws/sigiss_ws.php?wsdl
13
+ riogrande: https://riogrande.sigiss.com.br/riogrande/ws/sigiss_ws.php?wsdl
@@ -0,0 +1,20 @@
1
+ require "sigiss/version"
2
+ require "sigiss/ibge"
3
+ require "sigiss/gateway"
4
+ require "sigiss/provider"
5
+ require "sigiss/taker"
6
+ require "sigiss/invoice"
7
+ require "sigiss/invoice_data/invoice_data"
8
+ require "sigiss/invoice_data/issue_data"
9
+ require "sigiss/invoice_data/fetch_data"
10
+ require "sigiss/invoice_data/cancel_data"
11
+ require "sigiss/extension"
12
+ require "sigiss/integration"
13
+
14
+ module Sigiss
15
+
16
+ def self.root
17
+ File.dirname __dir__
18
+ end
19
+
20
+ end
@@ -0,0 +1,10 @@
1
+ module Sigiss
2
+ module Extension
3
+ def to_hash
4
+ hash = {}
5
+ instance_variables.each { |var| hash[var.to_s.delete("@").to_sym] = instance_variable_get(var) }
6
+ hash
7
+ end
8
+ end
9
+ end
10
+
@@ -0,0 +1,17 @@
1
+ require 'yaml'
2
+ module Sigiss
3
+ class Gateway
4
+ attr_accessor :name, :url, :environment
5
+
6
+ def initialize(name, environment)
7
+ @name = name
8
+ @url = get_url(name, environment)
9
+ @environment = environment
10
+ end
11
+
12
+ def get_url(name, environment)
13
+ YAML.load_file(File.join(Sigiss.root, 'configs.yml'))[environment.to_s][name.to_s]
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ module Sigiss
2
+ class IBGE
3
+
4
+ class << self
5
+
6
+ def get_code(name)
7
+ cities.each do |city, code|
8
+ return code if city == name.downcase
9
+ end
10
+ nil
11
+ end
12
+
13
+ def cities
14
+ YAML.load_file(File.join(Sigiss.root, 'cities.yml'))
15
+ end
16
+
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,50 @@
1
+ require 'savon'
2
+ module Sigiss
3
+ module Integration
4
+
5
+ def issue!
6
+ send(:gerar_nota, data_issue)
7
+ end
8
+
9
+ def fetch!
10
+ send(:consultar_nota_valida, data_fetch)
11
+ end
12
+
13
+ def cancel!
14
+ send(:cancelar_nota, data_cancel)
15
+ end
16
+
17
+ def data_issue
18
+ { DescricaoRps: provider.to_hash.merge(taker.to_hash).merge(data.to_hash) }
19
+ end
20
+
21
+ def data_fetch
22
+ { DadosConsultaNota: provider.to_fetch.merge(data.to_hash) }
23
+ end
24
+
25
+ def data_cancel
26
+ { DadosCancelaNota: provider.to_cancel.merge(data.to_hash) }
27
+ end
28
+
29
+ protected
30
+
31
+ def send(action, data)
32
+ execute do
33
+ client = Savon.client(wsdl: gateway.url, convert_request_keys_to: :none)
34
+ response = client.call(action, message: data)
35
+ { success: true, body: response.body }
36
+ end
37
+ end
38
+
39
+ def execute(&block)
40
+ yield
41
+ rescue Timeout::Error => e
42
+ { success: false, body: { error: e.message } }
43
+ rescue Savon::SOAPFault => e
44
+ { success: false, body: { error: e.message } }
45
+ rescue Exception => e
46
+ { success: false, body: { error: e.message } }
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,39 @@
1
+ require 'lotus/validations'
2
+ require 'sigiss/integration'
3
+
4
+ module Sigiss
5
+ class Invoice
6
+ include Lotus::Validations
7
+ include Sigiss::Integration
8
+
9
+ attr_accessor :gateway,
10
+ :provider,
11
+ :taker,
12
+ :data
13
+
14
+ validates :gateway, type: Gateway, presence: true
15
+ validates :provider, type: Provider, presence: true
16
+ validates :taker, type: Taker
17
+ validates :data, presence: true
18
+
19
+ def initialize(attributes = {})
20
+ @gateway = attributes[:gateway]
21
+ @provider = attributes[:provider]
22
+ @taker = attributes[:taker]
23
+ end
24
+
25
+ def build(method, params = {})
26
+ case method
27
+ when :issue
28
+ @data = Sigiss::IssueData.new(params)
29
+ when :fetch
30
+ @data = Sigiss::FetchData.new(params)
31
+ when :cancel
32
+ @data = Sigiss::CancelData.new(params)
33
+ else
34
+ @data = {}
35
+ end
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,18 @@
1
+ module Sigiss
2
+ class CancelData < InvoiceData
3
+
4
+ attr_accessor :nota,
5
+ :motivo,
6
+ :email
7
+
8
+ validates :nota, presence: true
9
+ validates :motivo, presence: true
10
+
11
+ def initialize(attributes = {})
12
+ @nota = attributes[:nota]
13
+ @motivo = attributes[:motivo]
14
+ @email = attributes[:email]
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ module Sigiss
2
+ class FetchData < InvoiceData
3
+
4
+ attr_accessor :nota,
5
+ :serie,
6
+ :autenticidade,
7
+ :valor
8
+
9
+ validates :nota, presence: true
10
+ validates :serie, presence: true
11
+ validates :autenticidade, presence: true
12
+ validates :valor, presence: true
13
+
14
+ def initialize(attributes = {})
15
+ @nota = attributes[:nota]
16
+ @serie = attributes[:serie]
17
+ @autenticidade = attributes[:autenticidade]
18
+ @valor = attributes[:valor]
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,9 @@
1
+ require 'lotus/validations'
2
+ require 'sigiss/extension'
3
+ module Sigiss
4
+ class InvoiceData
5
+ include Lotus::Validations
6
+ include Sigiss::Extension
7
+
8
+ end
9
+ end
@@ -0,0 +1,28 @@
1
+ module Sigiss
2
+ class IssueData < InvoiceData
3
+
4
+ attr_accessor :aliquota_simples,
5
+ :id_sis_legado,
6
+ :servico,
7
+ :situacao,
8
+ :valor,
9
+ :base,
10
+ :descricaoNF
11
+
12
+ validates :servico, presence: true
13
+ validates :situacao, presence: true
14
+ validates :valor, presence: true
15
+ validates :base, presence: true
16
+
17
+ def initialize(attributes = {})
18
+ @aliquota_simples = attributes[:aliquota_simples]
19
+ @id_sis_legado = attributes[:id_sis_legado]
20
+ @servico = attributes[:servico]
21
+ @situacao = attributes[:situacao]
22
+ @valor = attributes[:valor]
23
+ @base = attributes[:base]
24
+ @descricaoNF = attributes[:descricaoNF]
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,31 @@
1
+ require 'lotus/validations'
2
+ require 'sigiss/extension'
3
+ module Sigiss
4
+ class Provider
5
+ include Lotus::Validations
6
+ include Sigiss::Extension
7
+
8
+ attr_accessor :ccm, :cnpj, :senha, :crc, :crc_estado
9
+
10
+ validates :ccm, presence: true
11
+ validates :cnpj, presence: true
12
+ validates :senha, presence: true
13
+
14
+ def initialize(attributes = {})
15
+ @ccm = attributes[:ccm]
16
+ @cnpj = attributes[:cnpj]
17
+ @senha = attributes[:senha]
18
+ @crc = attributes[:crc]
19
+ @crc_estado = attributes[:crc_estado]
20
+ end
21
+
22
+ def to_fetch
23
+ { prestador_cnpj: @cnpj, prestador_ccm: @ccm }
24
+ end
25
+
26
+ def to_cancel
27
+ { cnpj: @cnpj, ccm: @ccm, senha: @senha }
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,56 @@
1
+ require 'lotus/validations'
2
+ require 'sigiss/extension'
3
+ module Sigiss
4
+ class Taker
5
+ include Lotus::Validations
6
+ include Sigiss::Extension
7
+
8
+ attr_accessor :tomador_tipo,
9
+ :tomador_cnpj,
10
+ :tomador_email,
11
+ :tomador_im,
12
+ :tomador_ie,
13
+ :tomador_razao,
14
+ :tomador_fantasia,
15
+ :tomador_endereco,
16
+ :tomador_numero,
17
+ :tomador_complemento,
18
+ :tomador_bairro,
19
+ :tomador_CEP,
20
+ :tomador_cod_cidade,
21
+ :tomador_fone,
22
+ :tomador_ramal,
23
+ :tomador_fax,
24
+ :tomador_ramal_fax
25
+
26
+ validates :tomador_tipo, presence: true
27
+ validates :tomador_cnpj, presence: true
28
+ validates :tomador_razao, presence: true
29
+ validates :tomador_endereco, presence: true
30
+ validates :tomador_numero, presence: true
31
+ validates :tomador_bairro, presence: true
32
+ validates :tomador_CEP, presence: true
33
+ validates :tomador_cod_cidade, presence: true
34
+
35
+ def initialize(attributes = {})
36
+ @tomador_tipo = attributes[:tomador_tipo]
37
+ @tomador_cnpj = attributes[:tomador_cnpj]
38
+ @tomador_email = attributes[:tomador_email]
39
+ @tomador_im = attributes[:tomador_im]
40
+ @tomador_ie = attributes[:tomador_ie]
41
+ @tomador_razao = attributes[:tomador_razao]
42
+ @tomador_fantasia = attributes[:tomador_fantasia]
43
+ @tomador_endereco = attributes[:tomador_endereco]
44
+ @tomador_numero = attributes[:tomador_numero]
45
+ @tomador_complemento = attributes[:tomador_complemento]
46
+ @tomador_bairro = attributes[:tomador_bairro]
47
+ @tomador_CEP = attributes[:tomador_CEP]
48
+ @tomador_cod_cidade = attributes[:tomador_cod_cidade] || Sigiss::IBGE.get_code(attributes[:cidade])
49
+ @tomador_fone = attributes[:tomador_fone]
50
+ @tomador_ramal = attributes[:tomador_ramal]
51
+ @tomador_fax = attributes[:tomador_fax]
52
+ @tomador_ramal_fax = attributes[:tomador_ramal_fax]
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,3 @@
1
+ module Sigiss
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sigiss/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sigiss"
8
+ spec.version = Sigiss::VERSION
9
+ spec.authors = ["Gabriel Pereira"]
10
+ spec.email = ["gabrielpedepera@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby gem para integração com o sistema SIGISS para emissão de Notas Fiscais Eletrônicas.}
13
+ spec.description = ""
14
+ spec.homepage = "https://github.com/gabrielpedepera/sigiss"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "lotus-validations"
25
+ spec.add_development_dependency "savon"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "pry"
28
+ spec.add_development_dependency "codeclimate-test-reporter"
29
+
30
+ end
@@ -0,0 +1,24 @@
1
+ SIGISS
2
+
3
+ Ruby gem para integração com o sistema SIGISS para emissão de Notas Fiscais Eletrônicas.
4
+
5
+ gateway = Sigiss::Gateway.new(:marilia, :test|:production)
6
+
7
+ provider = Sigiss::Provider.new(params) # Prestador
8
+
9
+ taker = Sigiss::Taker.new(params) # Tomador
10
+
11
+ # Criar
12
+ invoice = Sigiss::Invoice.new(gateway: gateway, provider: provider, taker: taker)
13
+ invoice.build(issue: params)
14
+ invoice.issue!
15
+
16
+ # Consultar
17
+ invoice = Sigiss::Invoice.new(gateway: gateway, provider: provider)
18
+ invoice.build(fetch: params)
19
+ invoice.fetch!
20
+
21
+ # Cancelar
22
+ invoice = Sigiss::Invoice.new(gateway: gateway, provider: provider)
23
+ invoice.build(cancel: params)
24
+ invoice.cancel!
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sigiss
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gabriel Pereira
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: lotus-validations
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: savon
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: rspec
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: pry
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: codeclimate-test-reporter
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: ''
112
+ email:
113
+ - gabrielpedepera@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - bin/console
126
+ - bin/setup
127
+ - cities.yml
128
+ - configs.yml
129
+ - lib/sigiss.rb
130
+ - lib/sigiss/extension.rb
131
+ - lib/sigiss/gateway.rb
132
+ - lib/sigiss/ibge.rb
133
+ - lib/sigiss/integration.rb
134
+ - lib/sigiss/invoice.rb
135
+ - lib/sigiss/invoice_data/cancel_data.rb
136
+ - lib/sigiss/invoice_data/fetch_data.rb
137
+ - lib/sigiss/invoice_data/invoice_data.rb
138
+ - lib/sigiss/invoice_data/issue_data.rb
139
+ - lib/sigiss/provider.rb
140
+ - lib/sigiss/taker.rb
141
+ - lib/sigiss/version.rb
142
+ - sigiss.gemspec
143
+ - sigiss.txt
144
+ homepage: https://github.com/gabrielpedepera/sigiss
145
+ licenses:
146
+ - MIT
147
+ metadata: {}
148
+ post_install_message:
149
+ rdoc_options: []
150
+ require_paths:
151
+ - lib
152
+ required_ruby_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ required_rubygems_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ requirements: []
163
+ rubyforge_project:
164
+ rubygems_version: 2.4.5.1
165
+ signing_key:
166
+ specification_version: 4
167
+ summary: Ruby gem para integração com o sistema SIGISS para emissão de Notas Fiscais
168
+ Eletrônicas.
169
+ test_files: []