nfse_issnet 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 112fe9e344ce587de1ebb8560397ea8018d70de504c9227b4b0110d9cc8758cd
4
+ data.tar.gz: db319b077e627bee21a1e84a1cb533b8b1d8ccad3fb6c57fdda2cd0fbebee8ce
5
+ SHA512:
6
+ metadata.gz: 15e81388bc6e78ae807a2c2869f054fea70a91dc7fe79e64aeb28e6288af1e337737bcbe4c05de19fe075a414409332325d053656d544f8920d292a2bfc60abe
7
+ data.tar.gz: bb4d3fe6a77ff4b954918d12eab3cce720f94c2142fc69e6427631287483cd2948b8c09d3172a5825f5cb5b60959e1abd1ff98d04b696f73626a13a353726b5e
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ /coverage
13
+
14
+ # IDE
15
+ /.idea
16
+ /lib/cert.p12
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ nfse
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.8
data/.travis.yml ADDED
@@ -0,0 +1,20 @@
1
+ ---
2
+ sudo: false
3
+ env:
4
+ global:
5
+ - CC_TEST_REPORTER_ID=b3afb9e08d066d2a45e9b4c0577851b520acccc34c4ffa730a1db929c883a3f5
6
+ language: ruby
7
+ cache: bundler
8
+ rvm:
9
+ - 2.3.8
10
+ notifications:
11
+ - false
12
+ before_install: gem install bundler
13
+ before_script:
14
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
15
+ - chmod +x ./cc-test-reporter
16
+ - ./cc-test-reporter before-build
17
+ scripts:
18
+ - bundle exec rspec spec
19
+ after_script:
20
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
@@ -0,0 +1,75 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at eduardo.scottini@gmail.com
59
+ . All
60
+ complaints will be reviewed and investigated and will result in a response that
61
+ is deemed necessary and appropriate to the circumstances. The project team is
62
+ obligated to maintain confidentiality with regard to the reporter of an incident.
63
+ Further details of specific enforcement policies may be posted separately.
64
+
65
+ Project maintainers who do not follow or enforce the Code of Conduct in good
66
+ faith may face temporary or permanent repercussions as determined by other
67
+ members of the project's leadership.
68
+
69
+ ## Attribution
70
+
71
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
72
+ available at [http://contributor-covenant.org/version/1/4][version]
73
+
74
+ [homepage]: http://contributor-covenant.org
75
+ [version]: http://contributor-covenant.org/version/1/4/
data/Dockerfile ADDED
@@ -0,0 +1,16 @@
1
+ FROM ruby:2.3.8
2
+
3
+ RUN apt-get update -qq && apt-get install -y build-essential
4
+
5
+ # for nokogiri
6
+ RUN apt-get install -y libxml2-dev libxslt1-dev
7
+
8
+ ENV APP_HOME /myapp
9
+ RUN mkdir $APP_HOME
10
+ WORKDIR $APP_HOME
11
+
12
+ ADD Gemfile* $APP_HOME/
13
+
14
+ ADD . $APP_HOME
15
+
16
+ RUN gem install bundler && bundle install
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in nfse.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Eduardo Scottini
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # Nfse Issnet
2
+
3
+ [![Build Status](https://travis-ci.org/eduardoscottini/nfse_issnet.svg?branch=master)](https://travis-ci.org/eduardoscottini/nfse_issnet)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/f53b3ab25175f4bf5a5b/maintainability)](https://codeclimate.com/github/eduardoscottini/nfse_issnet/maintainability)
5
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/f53b3ab25175f4bf5a5b/test_coverage)](https://codeclimate.com/github/eduardoscottini/nfse_issnet/test_coverage)
6
+
7
+ Integração simples para geração de nota fiscal de serviço(NFS-e) através do sistema ISSNET.
8
+
9
+ ## Instalação
10
+
11
+ ```ruby
12
+ gem 'nfse_issnet', '~> 0.1.1'
13
+ ```
14
+
15
+ E então execute:
16
+
17
+ $ bundle
18
+
19
+ Ou
20
+
21
+ ```
22
+ gem install nfse_issnet
23
+ ```
24
+
25
+
26
+
27
+ ## Requisitos:
28
+
29
+ Necessário um certificado do tipo A1 contendo o CNPJ em que é desejado realizar a integração.
30
+
31
+ ## Configuração
32
+ ```
33
+ # config/initializers/nfse_issnet.rb
34
+
35
+ NfseIssnet.configure do |config|
36
+ config.certificate_pkcs12_path = './cert.p12'
37
+ config.certificate_pkcs12_password = Senha123
38
+ end
39
+ ```
40
+
41
+ ## Uso
42
+
43
+ TODO: escrever instruções de uso para geração e consulta de RPS's e NFSe
44
+
45
+ ## Licença
46
+
47
+ A gem está disponível como open source sob os termos da [Licença MIT](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "nfse"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,15 @@
1
+ version: '3'
2
+ services:
3
+ web:
4
+ build: .
5
+ tty: true
6
+ stdin_open: true
7
+ ports:
8
+ - "3000:3000"
9
+ volumes:
10
+ - .:/myapp
11
+ - bundle-cache:/bundle
12
+ command: bundle console
13
+ volumes:
14
+ postgresql-data: {}
15
+ bundle-cache: {}
@@ -0,0 +1,74 @@
1
+ require "nfse_issnet/version"
2
+ require 'nfse_issnet/configuration'
3
+ require "dry-validation"
4
+ require 'dry-struct'
5
+ require 'pry'
6
+ require 'nfse_issnet/entities/base_entity'
7
+ require "nfse_issnet/entities/tc_cpf_cnpj"
8
+ require "nfse_issnet/entities/tc_identificacao_prestador"
9
+ require "nfse_issnet/entities/servico_consultar_nfse_envio"
10
+ require "nfse_issnet/entities/tc_endereco"
11
+ require "nfse_issnet/entities/tc_contato"
12
+ require "nfse_issnet/entities/tc_valores"
13
+ require "nfse_issnet/entities/tc_identificacao_intermediario_servico"
14
+ require "nfse_issnet/entities/tc_identificacao_tomador"
15
+ require "nfse_issnet/entities/tc_dados_servico"
16
+ require "nfse_issnet/entities/tc_dados_tomador"
17
+ require "nfse_issnet/entities/tc_dados_prestador"
18
+ require "nfse_issnet/entities/tc_identificacao_rps"
19
+ require "nfse_issnet/entities/tc_inf_rps"
20
+ require "nfse_issnet/entities/tc_rps"
21
+ require "nfse_issnet/entities/tc_lote_rps"
22
+ require "nfse_issnet/entities/nota_fiscal"
23
+ require "nfse_issnet/entities/servico_enviar_lote_rps_envio"
24
+ require "nfse_issnet/entities/servico_consultar_nfse_por_rps_envio"
25
+ require "nfse_issnet/entities/servico_consultar_lote_rps_envio"
26
+
27
+ require "nfse_issnet/utils/utils"
28
+ require "nfse_issnet/utils/xml"
29
+ require "nfse_issnet/utils/assinatura"
30
+
31
+
32
+ require "nfse_issnet/base"
33
+ require "nfse_issnet/operations/consulta_nfse"
34
+ require "nfse_issnet/operations/envia_lote_rps"
35
+ require "nfse_issnet/operations/consulta_nfse_por_rps"
36
+ require "nfse_issnet/operations/consulta_lote_rps"
37
+
38
+ require "nfse_issnet/responses/base"
39
+ require "nfse_issnet/responses/consulta_nfse"
40
+ require "nfse_issnet/responses/consulta_nfse_por_rps"
41
+ require "nfse_issnet/responses/consulta_lote_rps"
42
+ require "nfse_issnet/responses/envia_lote_rps"
43
+
44
+ require 'gyoku'
45
+ require 'savon'
46
+ require 'slim'
47
+ require 'ox'
48
+ require 'xmldsig'
49
+
50
+ module NfseIssnet
51
+ class Error < StandardError; end
52
+
53
+ class << self
54
+ attr_accessor :configuration
55
+
56
+ def configuration
57
+ @configuration ||= Configuration.new
58
+ end
59
+
60
+ def reset
61
+ @configuration = Configuration.new
62
+ end
63
+
64
+ def configure
65
+ yield(configuration)
66
+ end
67
+
68
+ def root
69
+ File.expand_path '../..', __FILE__
70
+ end
71
+ end
72
+
73
+
74
+ end
@@ -0,0 +1,72 @@
1
+ module NfseIssnet
2
+ class Base
3
+ def initialize(xml)
4
+ configure
5
+ validate_configuration
6
+
7
+ self.content_xml = entity.new(xml)
8
+ end
9
+
10
+ def request
11
+ @original_response = cliente.call(method_wsdl, message: RequisicaoAbrasf.new(xml_builder))
12
+ set_response
13
+ end
14
+
15
+ def monta_xml_completo
16
+ cliente.build_request method_wsdl, message: RequisicaoAbrasf.new(xml_builder)
17
+ end
18
+
19
+ private
20
+
21
+ attr_accessor :content_xml, :method_wsdl, :default_namespace, :entity, :template_xml
22
+
23
+ def configure
24
+ self.method_wsdl = nil
25
+ self.default_namespace = nil
26
+ self.entity = nil
27
+ self.template_xml = nil
28
+ end
29
+
30
+ def validate_configuration
31
+ method_wsdl or raise NfseIssnet::Error, 'Método wsdl é obrigatório'
32
+ default_namespace or raise NfseIssnet::Error, 'Caminho para schema xml é obrigatório'
33
+ entity or raise NfseIssnet::Error, 'Entidade é obrigatório'
34
+ template_xml or raise NfseIssnet::Error, 'Template XML é obrigatório'
35
+ end
36
+
37
+ def cliente
38
+ @cliente ||= Savon.client(wsdl: 'http://www.issnetonline.com.br/webserviceabrasf/homologacao/servicos.asmx?wsdl',
39
+ soap_version: 2,
40
+ namespace_identifier: :nfd)
41
+ end
42
+
43
+ def message_namespaces
44
+ {
45
+ xmlns: default_namespace,
46
+ 'xmlns:tc': 'http://www.issnetonline.com.br/webserviceabrasf/vsd/tipos_complexos.xsd'
47
+ }
48
+ end
49
+
50
+ def xml_builder
51
+ Utils::XML.render template_xml, message_namespaces: message_namespaces, content_xml: content_xml
52
+ end
53
+
54
+ class RequisicaoAbrasf
55
+ attr_accessor :xml
56
+
57
+ def initialize(xml)
58
+ self.xml = xml
59
+ end
60
+
61
+ def to_s
62
+ builder = Builder::XmlMarkup.new
63
+
64
+ builder.tag!('nfd:xml') { |b|
65
+ b.cdata! xml
66
+ }
67
+
68
+ builder
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,10 @@
1
+ module NfseIssnet
2
+ class Configuration
3
+ attr_accessor :certificate_pkcs12_path, :certificate_pkcs12_password
4
+
5
+ def initialize
6
+ self.certificate_pkcs12_path = nil
7
+ self.certificate_pkcs12_password = nil
8
+ end
9
+ end
10
+ end