Sha256: 3a22649d85b3f8878760cc01d408eff89af55806b3544a1c0ba150a122076b55

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 KB

Contents

module NfseGyn
  class ConsultarNfse
    attr_reader :invoice_number
    attr_reader :invoice_serie
    attr_reader :invoice_type

    def initialize(invoice_number, invoice_serie, invoice_type)
      @client = NfseGyn::SoapClient.new
      @invoice_number = invoice_number
      @invoice_serie = invoice_serie
      @invoice_type = invoice_type
    end

    def execute!
      if NfseGyn.configuration.mock_mode
        NfseGyn::MockConsultarNfseResponse.new(invoice_number, invoice_serie, invoice_type)
      else
        @client.call(:consultar_nfse_rps, self)
      end
    end

    def to_xml
      Gyoku.xml(
        'ConsultarNfseRpsEnvio' => {
          '@xmlns' => 'http://nfse.goiania.go.gov.br/xsd/nfse_gyn_v02.xsd',

          'IdentificacaoRps' => {
            'Numero' => invoice_number,
            'Serie' => invoice_serie,
            'Tipo' => invoice_type
          },
          'Prestador' => {
            'CpfCnpj' => {
              'Cnpj' => NfseGyn.configuration.cnpj
            },
            'InscricaoMunicipal' => NfseGyn.configuration.inscricao_municipal
          }
        }
      )
    end

    private

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

      def body
        content['CompNfse']
      end

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

Version data entries

3 entries across 3 versions & 1 rubygems

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