Class: Lipseys::Invoice

Inherits:
SoapClient show all
Defined in:
lib/lipseys/invoice.rb

Overview

In addition to the ‘:email` and `:password` options, finding invoices requires either an `:order_number` OR a `:purchase_order`.

The response structure will look like this:

{
  invoices_found: 1,
  description: "1 Invoice(s) found.",
  invoices: {
    invoice_detail: {
      invoice_no: "...",
      ship_to_location: "...",
      tracking_no: "...",
      line_items: {
        item_detail: {
          item_no: "...",
          upc: "...",
          qty: "...",
          serialized_item: "...",
          serial_numbers: {
            string: "..."
          }
        }
      }
    }
  }
}

Constant Summary

Constants inherited from SoapClient

SoapClient::API_URL

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Invoice

Returns a new instance of Invoice.

Raises:

  • (ArgumentError)


31
32
33
34
35
36
37
38
39
# File 'lib/lipseys/invoice.rb', line 31

def initialize(options = {})
  requires!(options, :email, :password)
  @email = options[:email]
  @password = options[:password]

  @order_number = options[:order_number]
  @purchase_order = options[:purchase_order]
  raise ArgumentError.new("Either :order_number or :purchase_order is required") if @order_number.nil? && @purchase_order.nil?
end

Class Method Details

.all(*args) ⇒ Object



42
43
44
# File 'lib/lipseys/invoice.rb', line 42

def self.all(*args)
  new(*args).all
end

Instance Method Details

#allObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/lipseys/invoice.rb', line 46

def all
  response = soap_client.call(:get_invoices, message: build_inquiry_data)

  raise Lipseys::NotAuthenticated if not_authenticated?(response)

  invoice_result = response.body[:get_invoices_response][:get_invoices_result]

  {
    invoices_found: Integer(invoice_result[:invoices_found]),
    description: invoice_result[:return_desc],

    invoices: invoice_result[:invoices]
  }
rescue Savon::Error => e
  { success: false, description: e.to_s }
end