nfse_issnet 0.1.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.
Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/.rspec +3 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +20 -0
  7. data/CODE_OF_CONDUCT.md +75 -0
  8. data/Dockerfile +16 -0
  9. data/Gemfile +6 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +47 -0
  12. data/Rakefile +6 -0
  13. data/bin/console +14 -0
  14. data/bin/setup +8 -0
  15. data/docker-compose.yml +15 -0
  16. data/lib/nfse_issnet.rb +74 -0
  17. data/lib/nfse_issnet/base.rb +72 -0
  18. data/lib/nfse_issnet/configuration.rb +10 -0
  19. data/lib/nfse_issnet/entities/base_entity.rb +11 -0
  20. data/lib/nfse_issnet/entities/nota_fiscal.rb +19 -0
  21. data/lib/nfse_issnet/entities/servico_consultar_lote_rps_envio.rb +8 -0
  22. data/lib/nfse_issnet/entities/servico_consultar_nfse_envio.rb +7 -0
  23. data/lib/nfse_issnet/entities/servico_consultar_nfse_por_rps_envio.rb +8 -0
  24. data/lib/nfse_issnet/entities/servico_enviar_lote_rps_envio.rb +7 -0
  25. data/lib/nfse_issnet/entities/tc_contato.rb +8 -0
  26. data/lib/nfse_issnet/entities/tc_cpf_cnpj.rb +8 -0
  27. data/lib/nfse_issnet/entities/tc_dados_prestador.rb +9 -0
  28. data/lib/nfse_issnet/entities/tc_dados_servico.rb +12 -0
  29. data/lib/nfse_issnet/entities/tc_dados_tomador.rb +10 -0
  30. data/lib/nfse_issnet/entities/tc_endereco.rb +13 -0
  31. data/lib/nfse_issnet/entities/tc_identificacao_intermediario_servico.rb +9 -0
  32. data/lib/nfse_issnet/entities/tc_identificacao_prestador.rb +8 -0
  33. data/lib/nfse_issnet/entities/tc_identificacao_rps.rb +9 -0
  34. data/lib/nfse_issnet/entities/tc_identificacao_tomador.rb +8 -0
  35. data/lib/nfse_issnet/entities/tc_inf_rps.rb +18 -0
  36. data/lib/nfse_issnet/entities/tc_lote_rps.rb +12 -0
  37. data/lib/nfse_issnet/entities/tc_rps.rb +7 -0
  38. data/lib/nfse_issnet/entities/tc_valores.rb +22 -0
  39. data/lib/nfse_issnet/operations/consulta_lote_rps.rb +18 -0
  40. data/lib/nfse_issnet/operations/consulta_nfse.rb +19 -0
  41. data/lib/nfse_issnet/operations/consulta_nfse_por_rps.rb +18 -0
  42. data/lib/nfse_issnet/operations/envia_lote_rps.rb +18 -0
  43. data/lib/nfse_issnet/responses/base.rb +53 -0
  44. data/lib/nfse_issnet/responses/consulta_lote_rps.rb +19 -0
  45. data/lib/nfse_issnet/responses/consulta_nfse.rb +19 -0
  46. data/lib/nfse_issnet/responses/consulta_nfse_por_rps.rb +19 -0
  47. data/lib/nfse_issnet/responses/envia_lote_rps.rb +32 -0
  48. data/lib/nfse_issnet/utils/assinatura.rb +36 -0
  49. data/lib/nfse_issnet/utils/utils.rb +19 -0
  50. data/lib/nfse_issnet/utils/xml.rb +32 -0
  51. data/lib/nfse_issnet/version.rb +3 -0
  52. data/lib/nfse_issnet/xml/_signed_info_sh1.xml.slim +8 -0
  53. data/lib/nfse_issnet/xml/_tc_contato.xml.slim +7 -0
  54. data/lib/nfse_issnet/xml/_tc_cpf_cnpj.xml.slim +4 -0
  55. data/lib/nfse_issnet/xml/_tc_dados_prestador.xml.slim +15 -0
  56. data/lib/nfse_issnet/xml/_tc_dados_servico.xml.slim +12 -0
  57. data/lib/nfse_issnet/xml/_tc_dados_tomador.xml.slim +15 -0
  58. data/lib/nfse_issnet/xml/_tc_endereco.xml.slim +16 -0
  59. data/lib/nfse_issnet/xml/_tc_identificacao_intermediario_servico.xml.slim +7 -0
  60. data/lib/nfse_issnet/xml/_tc_identificacao_prestador.xml.slim +4 -0
  61. data/lib/nfse_issnet/xml/_tc_identificacao_rps.xml.slim +3 -0
  62. data/lib/nfse_issnet/xml/_tc_identificacao_tomador.xml.slim +4 -0
  63. data/lib/nfse_issnet/xml/_tc_inf_rps.xml.slim +43 -0
  64. data/lib/nfse_issnet/xml/_tc_lote_rps.xml.slim +9 -0
  65. data/lib/nfse_issnet/xml/_tc_rps.xml.slim +7 -0
  66. data/lib/nfse_issnet/xml/_tc_valores.xml.slim +48 -0
  67. data/lib/nfse_issnet/xml/servico_consultar_lote_rps_envio.xml.slim +5 -0
  68. data/lib/nfse_issnet/xml/servico_consultar_nfse_envio.xml.slim +4 -0
  69. data/lib/nfse_issnet/xml/servico_consultar_nfse_por_rps_envio.xml.slim +6 -0
  70. data/lib/nfse_issnet/xml/servico_enviar_lote_rps_envio.xml.slim +9 -0
  71. data/lib/nfse_issnet/xml/signature_sh1.xml.slim +10 -0
  72. data/nfse_issnet.gemspec +55 -0
  73. metadata +299 -0
@@ -0,0 +1,11 @@
1
+ module NfseIssnet
2
+ module Entities
3
+ module Types
4
+ include Dry.Types
5
+
6
+ LeituraSimNao = Bool.enum(true => '1', false => '2')
7
+ end
8
+ class BaseEntity < Dry::Struct
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ module NfseIssnet
2
+ module Entities
3
+ class NotaFiscal < BaseEntity
4
+ attribute :numero, Types::Coercible::Integer
5
+ attribute :servico, NfseIssnet::Entities::TcDadosServico
6
+ attribute :tomador_servico, NfseIssnet::Entities::TcDadosTomador
7
+ attribute :prestador_servico, NfseIssnet::Entities::TcDadosPrestador
8
+ attribute? :codigo_verificacao, Types::Coercible::String
9
+ attribute? :data_emissao, Types::Params::DateTime
10
+ attribute? :competencia, Types::Params::Date
11
+ attribute? :natureza_operacao, Types::Coercible::Integer
12
+ attribute? :regime_especial_tributacao, Types::Coercible::Integer
13
+ attribute? :optante_simples_nacional, Types::LeituraSimNao
14
+ attribute? :incentivador_cultural, Types::LeituraSimNao
15
+ attribute? :nfse_substituida, Types::Coercible::Integer
16
+ attribute? :outras_informacoes, Types::String
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ module NfseIssnet
2
+ module Entities
3
+ class ServicoConsultarLoteRpsEnvio < BaseEntity
4
+ attribute :prestador, NfseIssnet::Entities::TcIdentificacaoPrestador
5
+ attribute :protocolo, Types::String
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module NfseIssnet
2
+ module Entities
3
+ class ServicoConsultarNfseEnvio < BaseEntity
4
+ attribute :prestador, NfseIssnet::Entities::TcIdentificacaoPrestador
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ module NfseIssnet
2
+ module Entities
3
+ class ServicoConsultarNfsePorRpsEnvio < BaseEntity
4
+ attribute :prestador, NfseIssnet::Entities::TcIdentificacaoPrestador
5
+ attribute :identificacao_rps, NfseIssnet::Entities::TcIdentificacaoRps
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module NfseIssnet
2
+ module Entities
3
+ class ServicoEnviarLoteRpsEnvio < BaseEntity
4
+ attribute :lote_rps, NfseIssnet::Entities::TcLoteRps
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ module NfseIssnet
2
+ module Entities
3
+ class TcContato < BaseEntity
4
+ attribute :telefone, Types::String.constrained(max_size: 11)
5
+ attribute :email, Types::String.constrained(max_size: 80)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module NfseIssnet
2
+ module Entities
3
+ class TcCpfCnpj < BaseEntity
4
+ attribute? :cpf, Types::String.constrained(size: 11)
5
+ attribute? :cnpj, Types::String.constrained(size: 14)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ module NfseIssnet
2
+ module Entities
3
+ class TcDadosPrestador < BaseEntity
4
+ attribute :identificacao_prestador, NfseIssnet::Entities::TcIdentificacaoPrestador
5
+ attribute? :razao_social, Types::String.constrained(max_size: 115)
6
+ attribute? :endereco, NfseIssnet::Entities::TcEndereco
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ module NfseIssnet
2
+ module Entities
3
+ class TcDadosServico < BaseEntity
4
+ attribute :valores, NfseIssnet::Entities::TcValores
5
+ attribute :item_lista_servico, Types::Coercible::String.constrained(max_size: 5)
6
+ attribute :codigo_cnae, Types::Coercible::Integer.constrained(lteq: ('9' * 7).to_i)
7
+ attribute :codigo_tributacao_municipio, Types::String.constrained(max_size: 20)
8
+ attribute :discriminacao, Types::String.constrained(max_size: 2000)
9
+ attribute :municipio_prestacao_servico, Types::String
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ module NfseIssnet
2
+ module Entities
3
+ class TcDadosTomador < BaseEntity
4
+ attribute :identificacao_tomador, NfseIssnet::Entities::TcIdentificacaoTomador
5
+ attribute :razao_social, Types::String.constrained(max_size: 115)
6
+ attribute :endereco, NfseIssnet::Entities::TcEndereco
7
+ attribute? :contato, NfseIssnet::Entities::TcContato.optional
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ module NfseIssnet
2
+ module Entities
3
+ class TcEndereco < BaseEntity
4
+ attribute? :endereco, Types::String.constrained(max_size: 125)
5
+ attribute? :cep, Types::Coercible::Integer.constrained(lteq: ('9' * 8).to_i)
6
+ attribute? :numero, Types::String.constrained(max_size: 10)
7
+ attribute? :complemento, Types::String.constrained(max_size: 60)
8
+ attribute? :bairro, Types::String.constrained(max_size: 60)
9
+ attribute? :cidade, Types::String.constrained(max_size: 7)
10
+ attribute? :estado, Types::String.constrained(max_size: 2)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ module NfseIssnet
2
+ module Entities
3
+ class TcIdentificacaoIntermediarioServico < BaseEntity
4
+ attribute :cpf_cnpj, NfseIssnet::Entities::TcCpfCnpj
5
+ attribute :razao_social, Types::String.constrained(max_size: 115)
6
+ attribute? :inscricao_municipal, Types::String.constrained(max_size: 15)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ module NfseIssnet
2
+ module Entities
3
+ class TcIdentificacaoPrestador < BaseEntity
4
+ attribute :cpf_cnpj, NfseIssnet::Entities::TcCpfCnpj
5
+ attribute :inscricao_municipal, Types::String.constrained(max_size: 15)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ module NfseIssnet
2
+ module Entities
3
+ class TcIdentificacaoRps < BaseEntity
4
+ attribute :numero, Types::Coercible::Integer.constrained(lteq: ('9' * 15).to_i)
5
+ attribute :serie, Types::Coercible::String.constrained(max_size: 5)
6
+ attribute :tipo, Types::Coercible::Integer.enum(1, 2, 3)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ module NfseIssnet
2
+ module Entities
3
+ class TcIdentificacaoTomador < BaseEntity
4
+ attribute :cpf_cnpj, NfseIssnet::Entities::TcCpfCnpj
5
+ attribute? :inscricao_municipal, Types::String.constrained(max_size: 15)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,18 @@
1
+ module NfseIssnet
2
+ module Entities
3
+ class TcInfRps < BaseEntity
4
+ attribute :identificacao_rps, NfseIssnet::Entities::TcIdentificacaoRps
5
+ attribute :data_emissao, Types::DateTime
6
+ attribute :natureza_operacao, Types::Integer.enum(1,2,3,4,5,6)
7
+ attribute? :regime_especial_tributacao, Types::Integer.enum(1,2,3,4)
8
+ attribute :optante_simples_nacional, Types::Integer.enum(1,2)
9
+ attribute :incentivador_cultural, Types::Integer.enum(1,2)
10
+ attribute :status, Types::Integer.enum(1,2)
11
+ attribute? :rps_substituido, NfseIssnet::Entities::TcIdentificacaoRps
12
+ attribute :servico, NfseIssnet::Entities::TcDadosServico
13
+ attribute :prestador, NfseIssnet::Entities::TcIdentificacaoPrestador
14
+ attribute :tomador, NfseIssnet::Entities::TcDadosTomador
15
+ attribute? :intermediario_servico, NfseIssnet::Entities::TcIdentificacaoIntermediarioServico
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ module NfseIssnet
2
+ module Entities
3
+ class TcLoteRps < BaseEntity
4
+ attribute :numero_lote, Types::Integer.constrained(lteq: ('9' * 15).to_i)
5
+ attribute :cpf_cnpj, NfseIssnet::Entities::TcCpfCnpj
6
+ attribute :inscricao_municipal, Types::String.constrained(max_size: 15)
7
+ attribute :quantidade_rps, Types::Integer.constrained(lteq: ('9' * 4).to_i)
8
+ attribute :lista_rps, Types::Array.of(NfseIssnet::Entities::TcRps)
9
+
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ module NfseIssnet
2
+ module Entities
3
+ class TcRps < BaseEntity
4
+ attribute :inf_rps, NfseIssnet::Entities::TcInfRps
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,22 @@
1
+ module NfseIssnet
2
+ module Entities
3
+ class TcValores < BaseEntity
4
+ attribute :base_calculo, Types::Coercible::Float
5
+ attribute :valor_servicos, Types::Coercible::Float
6
+ attribute :iss_retido, Types::Coercible::Integer.enum(1,2)
7
+ attribute :aliquota, Types::Coercible::Float
8
+ attribute :valor_iss, Types::Coercible::Float
9
+ attribute? :outras_retencoes, Types::Coercible::Decimal
10
+ attribute? :valor_deducoes, Types::Coercible::Decimal
11
+ attribute? :valor_pis, Types::Coercible::Decimal
12
+ attribute? :valor_cofins, Types::Coercible::Decimal
13
+ attribute? :valor_inss, Types::Coercible::Decimal
14
+ attribute? :valor_ir, Types::Coercible::Decimal
15
+ attribute? :valor_csll, Types::Coercible::Decimal
16
+ attribute? :valor_liquido_nfse, Types::Coercible::Decimal
17
+ attribute? :valor_iss_retido, Types::Coercible::Decimal
18
+ attribute? :desconto_condicionado, Types::Coercible::Decimal
19
+ attribute? :desconto_incondicionado, Types::Coercible::Decimal
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ module NfseIssnet
2
+ module Operations
3
+ class ConsultaLoteRps < NfseIssnet::Base
4
+ private
5
+
6
+ def configure
7
+ self.method_wsdl = :consultar_lote_rps
8
+ self.default_namespace = 'http://www.issnetonline.com.br/webserviceabrasf/vsd/servico_consultar_lote_rps_envio.xsd'
9
+ self.template_xml = :servico_consultar_lote_rps_envio
10
+ self.entity = NfseIssnet::Entities::ServicoConsultarLoteRpsEnvio
11
+ end
12
+
13
+ def set_response
14
+ @response = NfseIssnet::Responses::ConsultaLoteRps.new(savon_response: @original_response).response
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ module NfseIssnet
2
+ module Operations
3
+ class ConsultaNfse < NfseIssnet::Base
4
+ private
5
+
6
+ def configure
7
+ self.method_wsdl = :consultar_nfse
8
+ self.default_namespace = 'http://www.issnetonline.com.br/webserviceabrasf/vsd/servico_consultar_nfse_envio.xsd'
9
+ self.template_xml = :servico_consultar_nfse_envio
10
+ self.entity = NfseIssnet::Entities::ServicoConsultarNfseEnvio
11
+ end
12
+
13
+ def set_response
14
+ @response = NfseIssnet::Responses::ConsultaNfse.new(savon_response: @original_response).response
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ module NfseIssnet
2
+ module Operations
3
+ class ConsultaNfsePorRps < NfseIssnet::Base
4
+ private
5
+
6
+ def configure
7
+ self.method_wsdl = :consulta_nf_se_por_rps
8
+ self.default_namespace = 'http://www.issnetonline.com.br/webserviceabrasf/vsd/servico_consultar_nfse_rps_envio.xsd'
9
+ self.template_xml = :servico_consultar_nfse_por_rps_envio
10
+ self.entity = NfseIssnet::Entities::ServicoConsultarNfsePorRpsEnvio
11
+ end
12
+
13
+ def set_response
14
+ @response = NfseIssnet::Responses::ConsultaNfsePorRps.new(savon_response: @original_response).response
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module NfseIssnet
2
+ module Operations
3
+ class EnviaLoteRps < NfseIssnet::Base
4
+ private
5
+
6
+ def configure
7
+ self.method_wsdl = :recepcionar_lote_rps
8
+ self.default_namespace = 'http://www.issnetonline.com.br/webserviceabrasf/vsd/servico_enviar_lote_rps_envio.xsd'
9
+ self.template_xml = :servico_enviar_lote_rps_envio
10
+ self.entity = NfseIssnet::Entities::ServicoEnviarLoteRpsEnvio
11
+ end
12
+
13
+ def set_response
14
+ @response = NfseIssnet::Responses::EnviaLoteRps.new(savon_response: @original_response).response
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,53 @@
1
+ module NfseIssnet
2
+ module Responses
3
+ class Base
4
+ attr_accessor :savon_response,:savon_body
5
+ attr_accessor :keys_root_path, :notas_fiscais_path, :errors_path
6
+
7
+ def initialize(attributes = {})
8
+ attributes = default_values.merge!(attributes)
9
+ assign_attributes(attributes)
10
+ convert_body_to_hash
11
+ end
12
+
13
+ protected
14
+
15
+ def default_values
16
+ {}
17
+ end
18
+
19
+ def notas_fiscais
20
+ @notas_fiscais ||= pega_itens(notas_fiscais_path).map { |nfs| NfseIssnet::Entities::NotaFiscal.new(nfs[:nfse][:inf_nfse]) }
21
+ end
22
+
23
+ def erros
24
+ @erros ||= pega_itens(errors_path).map { |erro| erro[:mensagem_retorno] }
25
+ end
26
+
27
+ def pega_itens(path)
28
+ itens = []
29
+ _itens= savon_body.dig(*path)
30
+ if _itens.is_a?(Hash)
31
+ itens << _itens
32
+ elsif _itens.is_a?(Array)
33
+ _itens.map{|inv| itens << inv }
34
+ end
35
+ itens
36
+ end
37
+
38
+ private
39
+
40
+ def assign_attributes(attributes)
41
+ attributes ||= {}
42
+ attributes.each do |name, value|
43
+ send("#{name}=", value)
44
+ end
45
+ end
46
+
47
+ def convert_body_to_hash
48
+ ep = lambda { |key| Utils::Utils.snakecase(key).to_sym }
49
+ self.savon_body ||= Ox.load(savon_response.body.dig(*keys_root_path), mode: :hash_no_attrs, strip_namespace: true, element_key_mod: ep)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,19 @@
1
+ module NfseIssnet
2
+ module Responses
3
+ class ConsultaLoteRps < Base
4
+ def response
5
+ OpenStruct.new(notas_fiscais: notas_fiscais, erros: erros)
6
+ end
7
+
8
+ private
9
+
10
+ def default_values
11
+ super.merge({
12
+ keys_root_path: [:consultar_lote_rps_response, :consultar_lote_rps_result],
13
+ errors_path: [:consultar_lote_rps_resposta, :lista_mensagem_retorno],
14
+ notas_fiscais_path: [:consultar_lote_rps_resposta, :lista_nfse, :comp_nfse],
15
+ })
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module NfseIssnet
2
+ module Responses
3
+ class ConsultaNfse < Base
4
+ def response
5
+ OpenStruct.new(notas_fiscais: notas_fiscais, error_messages: erros)
6
+ end
7
+
8
+ protected
9
+
10
+ def default_values
11
+ super.merge({
12
+ keys_root_path: [:consultar_nfse_response, :consultar_nfse_result],
13
+ errors_path: [:consultar_nfse_rps_resposta, :lista_mensagem_retorno],
14
+ notas_fiscais_path: [:consultar_nfse_resposta, :lista_nfse, :comp_nfse],
15
+ })
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module NfseIssnet
2
+ module Responses
3
+ class ConsultaNfsePorRps < Base
4
+ def response
5
+ OpenStruct.new(notas_fiscais: notas_fiscais, error_messages: erros)
6
+ end
7
+
8
+ protected
9
+
10
+ def default_values
11
+ super.merge({
12
+ keys_root_path: [:consulta_nf_se_por_rps_response, :consulta_nf_se_por_rps_result],
13
+ errors_path: [:consultar_nfse_rps_resposta, :lista_mensagem_retorno],
14
+ notas_fiscais_path: [:consultar_nfse_rps_resposta, :comp_nfse],
15
+ })
16
+ end
17
+ end
18
+ end
19
+ end