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

Methods inherited from Provider

#config, #initialize

Constructor Details

This class inherits a constructor from Einvoice::Provider

Instance Method Details

#issue(payload, options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/einvoice/neweb/provider.rb', line 19

def issue(payload, options = {})
  case options[:type]
  when :seller_invoice
    action = "IN_SellerInvoiceS.action"
    invoice = Einvoice::Neweb::Model::SellerInvoice.new
  else
    action = "IN_PreInvoiceS.action"
    invoice = Einvoice::Neweb::Model::PreInvoice.new
  end

  invoice.from_json(payload.to_json)

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

    Einvoice::Neweb::Result.new(response)
  else
    Einvoice::Neweb::Result.new(invoice.errors)
  end
end

#query(payload, options = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/einvoice/neweb/provider.rb', line 46

def query(payload, options = {})
  action = "IN_InvoiceMapS.action"
  query = Einvoice::Neweb::Model::Query.new
  query.from_json(payload.to_json)

  if query.valid?
    response = connection.post do |request|
      request.url endpoint_url || endpoint + action
      request.body = {
        storecode: client_id,
        xmldata: encode_xml(camelize(query.wrapped_payload))
      }
    end.body

    Einvoice::Neweb::Result.new(response)
  else
    Einvoice::Neweb::Result.new(query.errors)
  end
end