Class: Nfse::EnviaLote
Instance Attribute Summary collapse
-
#code_ibge ⇒ Object
Returns the value of attribute code_ibge.
-
#lote ⇒ Object
Returns the value of attribute lote.
-
#xml_lote ⇒ Object
Returns the value of attribute xml_lote.
Instance Method Summary collapse
- #assinar_xml(xml_original, certificado) ⇒ Object
- #enviar_lote_rps ⇒ Object
-
#initialize(code_ibge, lote) ⇒ EnviaLote
constructor
A new instance of EnviaLote.
Methods inherited from Base
Constructor Details
#initialize(code_ibge, lote) ⇒ EnviaLote
Returns a new instance of EnviaLote.
8 9 10 11 12 13 |
# File 'lib/nfse/envialote.rb', line 8 def initialize(code_ibge, lote) self.template_path = File.("../../templates/", __FILE__) @code_ibge = code_ibge @lote = lote end |
Instance Attribute Details
#code_ibge ⇒ Object
Returns the value of attribute code_ibge.
6 7 8 |
# File 'lib/nfse/envialote.rb', line 6 def code_ibge @code_ibge end |
#lote ⇒ Object
Returns the value of attribute lote.
6 7 8 |
# File 'lib/nfse/envialote.rb', line 6 def lote @lote end |
#xml_lote ⇒ Object
Returns the value of attribute xml_lote.
6 7 8 |
# File 'lib/nfse/envialote.rb', line 6 def xml_lote @xml_lote end |
Instance Method Details
#assinar_xml(xml_original, certificado) ⇒ Object
36 37 38 39 40 |
# File 'lib/nfse/envialote.rb', line 36 def assinar_xml(xml_original, certificado) xml = sign_xml(xml_original, certificado) xml = add_cert_to_xml(xml, certificado, "//ds:Signature/ds:KeyInfo/ds:X509Data/ds:X509Certificate") return xml end |
#enviar_lote_rps ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/nfse/envialote.rb', line 15 def enviar_lote_rps() wsdl = get_wsdl[@code_ibge] client = Savon.client( wsdl: wsdl, ssl_cert: OpenSSL::X509::Certificate.new(File.read('cert.pem')), ssl_cert_key: OpenSSL::PKey::RSA.new(File.read('cert.pem')) ) @xml_lote = self.assinar_xml(@lote.render, 'cert.pem').gsub('<?xml version="1.0"?>', '') #export_xml(self.render, 'teste-signed.xml') response = client.call(:gerar_nfse, xml: self.render) data = response.body[:gerar_nfse_response][:output_xml] #Tratar retorno com erros xml = Nokogiri::XML(data) if xml.xpath('//xmlns:MensagemRetorno').empty? return data else puts data return nil end end |