Class: Vatsense::Resources::Invoice

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

Overview

VAT-compliant invoice management

Defined Under Namespace

Classes: Item

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Invoice

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 Invoice.

Parameters:



200
201
202
203
# File 'lib/vatsense/resources/invoice.rb', line 200

def initialize(client:)
  @client = client
  @item = Vatsense::Resources::Invoice::Item.new(client: client)
end

Instance Attribute Details

#itemVatsense::Resources::Invoice::Item (readonly)

VAT-compliant invoice management



9
10
11
# File 'lib/vatsense/resources/invoice.rb', line 9

def item
  @item
end

Instance Method Details

#create(business:, currency_code:, date:, items:, tax_point:, conversion: nil, customer: nil, has_vat: nil, invoice_number: nil, is_copy: nil, is_reverse_charge: nil, notes: nil, pad_invoice_number: nil, serial: nil, tax_type: nil, type: nil, zero_rated: nil, request_options: {}) ⇒ Vatsense::Models::InvoiceResponse

Some parameter documentations has been truncated, see Models::InvoiceCreateParams for more details.

Create a new VAT-compliant invoice. VAT Sense will automatically calculate the totals based on the items provided.

Not available with sandbox API keys.

Parameters:

  • business (Vatsense::Models::InvoiceBusinessInput)
  • currency_code (String)

    The 3-character currency code the invoice is billed in.

  • date (String)

    The date the invoice was issued (YYYY-MM-DD or YYYY-MM-DD HH:MM:SS).

  • items (Array<Vatsense::Models::Invoice::InvoiceItemInput>)
  • tax_point (String)

    The tax point or “time of supply” (YYYY-MM-DD or YYYY-MM-DD HH:MM:SS).

  • conversion (Vatsense::Models::InvoiceConversionInput)
  • customer (Vatsense::Models::InvoiceCustomerInput)
  • has_vat (Boolean)

    Whether the invoice is subject to VAT.

  • invoice_number (String)

    A unique invoice number. If not provided, defaults to an auto-incremented number

  • is_copy (Boolean)

    Whether the invoice is a copy of a primary invoice.

  • is_reverse_charge (Boolean)

    Whether the invoice is zero-rated due to reverse charge.

  • notes (String)

    Any additional notes for the invoice.

  • pad_invoice_number (Integer)

    Pad the auto-generated invoice number with leading zeros to this length.

  • serial (String)

    A serial prepended to the auto-generated invoice number. Each unique serial has

  • tax_type (Symbol, Vatsense::Models::CreateInvoice::TaxType)

    Whether item prices include or exclude VAT.

  • type (Symbol, Vatsense::Models::CreateInvoice::Type)

    The type of invoice.

  • zero_rated (Boolean)

    Whether the invoice has been zero-rated.

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

Returns:

See Also:



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

def create(params)
  parsed, options = Vatsense::InvoiceCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "invoice",
    body: parsed,
    model: Vatsense::InvoiceResponse,
    options: options
  )
end

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

Permanently delete an invoice.

Parameters:

  • invoice_id (String)

    The unique identifier of the invoice.

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

Returns:

See Also:



188
189
190
191
192
193
194
195
# File 'lib/vatsense/resources/invoice.rb', line 188

def delete(invoice_id, params = {})
  @client.request(
    method: :delete,
    path: ["invoice/%1$s", invoice_id],
    model: Vatsense::Models::InvoiceDeleteResponse,
    options: params[:request_options]
  )
end

#list(limit: nil, offset: nil, search: nil, request_options: {}) ⇒ Vatsense::Models::InvoiceListResponse

Retrieve a paginated list of all invoices.

Parameters:

  • limit (Integer)

    Number of invoices to return (default 10, max 100).

  • offset (Integer)

    Number of invoices to skip (default 0).

  • search (String)

    Search query to filter invoices.

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

Returns:

See Also:



165
166
167
168
169
170
171
172
173
174
175
# File 'lib/vatsense/resources/invoice.rb', line 165

def list(params = {})
  parsed, options = Vatsense::InvoiceListParams.dump_request(params)
  query = Vatsense::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "invoice",
    query: query,
    model: Vatsense::Models::InvoiceListResponse,
    options: options
  )
end

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

Retrieve a specific invoice by its ID.

Parameters:

  • invoice_id (String)

    The unique identifier of the invoice.

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

Returns:

See Also:



82
83
84
85
86
87
88
89
# File 'lib/vatsense/resources/invoice.rb', line 82

def retrieve(invoice_id, params = {})
  @client.request(
    method: :get,
    path: ["invoice/%1$s", invoice_id],
    model: Vatsense::InvoiceResponse,
    options: params[:request_options]
  )
end

#update(invoice_id, business:, currency_code:, date:, items:, tax_point:, conversion: nil, customer: nil, has_vat: nil, invoice_number: nil, is_copy: nil, is_reverse_charge: nil, notes: nil, pad_invoice_number: nil, serial: nil, tax_type: nil, type: nil, zero_rated: nil, request_options: {}) ⇒ Vatsense::Models::InvoiceResponse

Some parameter documentations has been truncated, see Models::InvoiceUpdateParams for more details.

Update an existing invoice. Only the fields provided will be updated.

Parameters:

  • invoice_id (String)

    The unique identifier of the invoice.

  • business (Vatsense::Models::InvoiceBusinessInput)
  • currency_code (String)

    The 3-character currency code the invoice is billed in.

  • date (String)

    The date the invoice was issued (YYYY-MM-DD or YYYY-MM-DD HH:MM:SS).

  • items (Array<Vatsense::Models::Invoice::InvoiceItemInput>)
  • tax_point (String)

    The tax point or “time of supply” (YYYY-MM-DD or YYYY-MM-DD HH:MM:SS).

  • conversion (Vatsense::Models::InvoiceConversionInput)
  • customer (Vatsense::Models::InvoiceCustomerInput)
  • has_vat (Boolean)

    Whether the invoice is subject to VAT.

  • invoice_number (String)

    A unique invoice number. If not provided, defaults to an auto-incremented number

  • is_copy (Boolean)

    Whether the invoice is a copy of a primary invoice.

  • is_reverse_charge (Boolean)

    Whether the invoice is zero-rated due to reverse charge.

  • notes (String)

    Any additional notes for the invoice.

  • pad_invoice_number (Integer)

    Pad the auto-generated invoice number with leading zeros to this length.

  • serial (String)

    A serial prepended to the auto-generated invoice number. Each unique serial has

  • tax_type (Symbol, Vatsense::Models::CreateInvoice::TaxType)

    Whether item prices include or exclude VAT.

  • type (Symbol, Vatsense::Models::CreateInvoice::Type)

    The type of invoice.

  • zero_rated (Boolean)

    Whether the invoice has been zero-rated.

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

Returns:

See Also:



139
140
141
142
143
144
145
146
147
148
# File 'lib/vatsense/resources/invoice.rb', line 139

def update(invoice_id, params)
  parsed, options = Vatsense::InvoiceUpdateParams.dump_request(params)
  @client.request(
    method: :patch,
    path: ["invoice/%1$s", invoice_id],
    body: parsed,
    model: Vatsense::InvoiceResponse,
    options: options
  )
end