Sha256: 66c38191cd6bfb96830f1e35c6b27630b9c56f981cd629f09c4befa90156bfc0

Contents?: true

Size: 1005 Bytes

Versions: 3

Compression:

Stored size: 1005 Bytes

Contents

require 'nfse_gyn/gerar_nfse_xml'

module NfseGyn
  class GerarNfse
    def initialize(invoice)
      @invoice = invoice
      @client = NfseGyn::SoapClient.new
    end

    def execute!
      if NfseGyn.configuration.mock_mode
        NfseGyn::MockGerarNfseResponse.new(@invoice)
      else
        @client.call(:gerar_nfse, self)
      end
    end

    def to_xml
      GerarNfseXML.new(@invoice).to_xml
    end

    private

    class Response < NfseGyn::Response
      def content
        @content ||= output['GerarNfseResposta']
      end

      def body
        content['ListaNfse']['CompNfse']
      end

      def error?
        !content['ListaNfse'] || content['ListaMensagemRetorno']['MensagemRetorno']['Codigo'] != 'L000'
      end

      def errors
        if error?
          message = content['ListaMensagemRetorno']['MensagemRetorno']
          message = [message] if message.is_a?(Hash)

          message
        end
      rescue StandardError
        content
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nfse_gyn-0.3.0 lib/nfse_gyn/gerar_nfse.rb
nfse_gyn-0.2.0 lib/nfse_gyn/gerar_nfse.rb
nfse_gyn-0.1.2 lib/nfse_gyn/gerar_nfse.rb