Class: Vatsense::Resources::Invoice::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/vatsense/resources/invoice/item.rb

Overview

VAT-compliant invoice management

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Item

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Item.

Parameters:



127
128
129
# File 'lib/vatsense/resources/invoice/item.rb', line 127

def initialize(client:)
  @client = client
end

Instance Method Details

#add(invoice_id, items:, request_options: {}) ⇒ Vatsense::Models::InvoiceResponse

Add one or more line items to an existing invoice.

Parameters:

Returns:

See Also:



113
114
115
116
117
118
119
120
121
122
# File 'lib/vatsense/resources/invoice/item.rb', line 113

def add(invoice_id, params)
  parsed, options = Vatsense::Invoice::ItemAddParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["invoice/%1$s/item", invoice_id],
    body: parsed,
    model: Vatsense::InvoiceResponse,
    options: options
  )
end

#delete(item_id, invoice_id:, request_options: {}) ⇒ Vatsense::Models::InvoiceResponse

Remove a specific line item from an invoice.

Parameters:

  • item_id (String)

    The unique identifier of the invoice item.

  • invoice_id (String)

    The unique identifier of the invoice.

  • request_options (Vatsense::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/vatsense/resources/invoice/item.rb', line 86

def delete(item_id, params)
  parsed, options = Vatsense::Invoice::ItemDeleteParams.dump_request(params)
  invoice_id =
    parsed.delete(:invoice_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :delete,
    path: ["invoice/%1$s/item/%2$s", invoice_id, item_id],
    model: Vatsense::InvoiceResponse,
    options: options
  )
end

#retrieve(item_id, invoice_id:, request_options: {}) ⇒ Vatsense::Models::Invoice::ItemRetrieveResponse

Retrieve a specific line item from an invoice.

Parameters:

  • item_id (String)

    The unique identifier of the invoice item.

  • invoice_id (String)

    The unique identifier of the invoice.

  • request_options (Vatsense::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/vatsense/resources/invoice/item.rb', line 21

def retrieve(item_id, params)
  parsed, options = Vatsense::Invoice::ItemRetrieveParams.dump_request(params)
  invoice_id =
    parsed.delete(:invoice_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :get,
    path: ["invoice/%1$s/item/%2$s", invoice_id, item_id],
    model: Vatsense::Models::Invoice::ItemRetrieveResponse,
    options: options
  )
end

#update(item_id, invoice_id:, item:, price_each:, quantity:, vat_rate:, discount_rate: nil, request_options: {}) ⇒ Vatsense::Models::InvoiceResponse

Update a specific line item on an invoice.

Parameters:

  • item_id (String)

    Path param: The unique identifier of the invoice item.

  • invoice_id (String)

    Path param: The unique identifier of the invoice.

  • item (String)

    Body param: The description of the line item.

  • price_each (Float)

    Body param: The price per item. Must be a decimal with 2 decimal places.

  • quantity (Float)

    Body param: The quantity of the item.

  • vat_rate (Float)

    Body param: A percentage VAT rate for this item.

  • discount_rate (Float)

    Body param: A percentage discount to apply to the price.

  • request_options (Vatsense::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/vatsense/resources/invoice/item.rb', line 58

def update(item_id, params)
  parsed, options = Vatsense::Invoice::ItemUpdateParams.dump_request(params)
  invoice_id =
    parsed.delete(:invoice_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :patch,
    path: ["invoice/%1$s/item/%2$s", invoice_id, item_id],
    body: parsed,
    model: Vatsense::InvoiceResponse,
    options: options
  )
end