Class: Einvoice::Neweb::Provider

Inherits:
Provider
  • Object
show all
Includes:
Utils
Defined in:
lib/einvoice/neweb/provider.rb

Instance Attribute Summary

Attributes inherited from Provider

#provider

Instance Method Summary collapse

Methods included from Utils

#camelize, #encode_xml, #serialize, #wrap

Methods inherited from Provider

#config, #initialize

Constructor Details

This class inherits a constructor from Einvoice::Provider

Instance Method Details

#issue(payload) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/einvoice/neweb/provider.rb', line 14

def issue(payload)
  invoice = Einvoice::Neweb::Model::Invoice.new
  invoice.from_json(payload.to_json)

  if invoice.valid?
    action = "IN_PreInvoiceS.action"
    response = connection.post do |request|
      request.url endpoint + action
      request.body = {
        storecode: client_id,
        xmldata: encode_xml(wrap(serialize(invoice)))
      }
    end.body

    Einvoice::Result.new(Einvoice::NewebResponse.new(response))
  else
    Einvoice::Result.new(Einvoice::NewebResponse.new(response))
  end
end