Class: EInvoiceAPI::Resources::Documents

Inherits:
Object
  • Object
show all
Defined in:
lib/e_invoice_api/resources/documents.rb,
lib/e_invoice_api/resources/documents/ubl.rb,
lib/e_invoice_api/resources/documents/attachments.rb

Defined Under Namespace

Classes: Attachments, Ubl

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Documents

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

Parameters:



264
265
266
267
268
# File 'lib/e_invoice_api/resources/documents.rb', line 264

def initialize(client:)
  @client = client
  @attachments = EInvoiceAPI::Resources::Documents::Attachments.new(client: client)
  @ubl = EInvoiceAPI::Resources::Documents::Ubl.new(client: client)
end

Instance Attribute Details

#attachmentsEInvoiceAPI::Resources::Documents::Attachments (readonly)



7
8
9
# File 'lib/e_invoice_api/resources/documents.rb', line 7

def attachments
  @attachments
end

#ublEInvoiceAPI::Resources::Documents::Ubl (readonly)



10
11
12
# File 'lib/e_invoice_api/resources/documents.rb', line 10

def ubl
  @ubl
end

Instance Method Details

#create(construct_pdf: nil, allowances: nil, amount_due: nil, attachments: nil, billing_address: nil, billing_address_recipient: nil, charges: nil, currency: nil, customer_address: nil, customer_address_recipient: nil, customer_company_id: nil, customer_email: nil, customer_id: nil, customer_name: nil, customer_peppol_id: nil, customer_tax_id: nil, direction: nil, document_type: nil, due_date: nil, invoice_date: nil, invoice_id: nil, invoice_total: nil, items: nil, note: nil, payment_details: nil, payment_term: nil, previous_unpaid_balance: nil, purchase_order: nil, remittance_address: nil, remittance_address_recipient: nil, service_address: nil, service_address_recipient: nil, service_end_date: nil, service_start_date: nil, shipping_address: nil, shipping_address_recipient: nil, state: nil, subtotal: nil, tax_code: nil, tax_details: nil, total_discount: nil, total_tax: nil, vatex: nil, vatex_note: nil, vendor_address: nil, vendor_address_recipient: nil, vendor_company_id: nil, vendor_email: nil, vendor_name: nil, vendor_tax_id: nil, request_options: {}) ⇒ EInvoiceAPI::Models::DocumentResponse

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

Create a new invoice or credit note

Parameters:

  • construct_pdf (Boolean)

    Query param: If true, generate a constructed PDF from the document and include i

  • allowances (Array<EInvoiceAPI::Models::DocumentCreate::Allowance>, nil)

    Body param

  • amount_due (Float, String, nil)

    Body param: The amount due for payment. Must be positive and rounded to maximum

  • attachments (Array<EInvoiceAPI::Models::DocumentAttachmentCreate>, nil)

    Body param

  • billing_address (String, nil)

    Body param: The billing address (if different from customer address)

  • billing_address_recipient (String, nil)

    Body param: The recipient name at the billing address

  • charges (Array<EInvoiceAPI::Models::DocumentCreate::Charge>, nil)

    Body param

  • currency (Symbol, EInvoiceAPI::Models::CurrencyCode)

    Body param: Currency of the invoice (ISO 4217 currency code)

  • customer_address (String, nil)

    Body param: The address of the customer/buyer

  • customer_address_recipient (String, nil)

    Body param: The recipient name at the customer address

  • customer_company_id (String, nil)

    Body param: Customer company ID. For Belgium this is the CBE number or their EUI

  • customer_email (String, nil)

    Body param: The email address of the customer

  • customer_id (String, nil)

    Body param: The unique identifier for the customer in your system

  • customer_name (String, nil)

    Body param: The company name of the customer/buyer

  • customer_peppol_id (String, nil)

    Body param: Customer Peppol ID

  • customer_tax_id (String, nil)

    Body param: Customer tax ID. For Belgium this is the VAT number. Must include th

  • direction (Symbol, EInvoiceAPI::Models::DocumentDirection)

    Body param: The direction of the document: INBOUND (purchases) or OUTBOUND (sale

  • document_type (Symbol, EInvoiceAPI::Models::DocumentType)

    Body param: The type of document: INVOICE, CREDIT_NOTE, or DEBIT_NOTE

  • due_date (Date, nil)

    Body param: The date when payment is due

  • invoice_date (Date, nil)

    Body param: The date when the invoice was issued

  • invoice_id (String, nil)

    Body param: The unique invoice identifier/number

  • invoice_total (Float, String, nil)

    Body param: The total amount of the invoice including tax (invoice_total = subto

  • items (Array<EInvoiceAPI::Models::DocumentCreate::Item>)

    Body param: At least one line item is required

  • note (String, nil)

    Body param: Additional notes or comments for the invoice

  • payment_details (Array<EInvoiceAPI::Models::PaymentDetailCreate>, nil)

    Body param

  • payment_term (String, nil)

    Body param: The payment terms (e.g., ‘Net 30’, ‘Due on receipt’, ‘2/10 Net 30’)

  • previous_unpaid_balance (Float, String, nil)

    Body param: The previous unpaid balance from prior invoices, if any. Must be pos

  • purchase_order (String, nil)

    Body param: The purchase order reference number

  • remittance_address (String, nil)

    Body param: The address where payment should be sent or remitted to

  • remittance_address_recipient (String, nil)

    Body param: The recipient name at the remittance address

  • service_address (String, nil)

    Body param: The address where services were performed or goods were delivered

  • service_address_recipient (String, nil)

    Body param: The recipient name at the service address

  • service_end_date (Date, nil)

    Body param: The end date of the service period or delivery period

  • service_start_date (Date, nil)

    Body param: The start date of the service period or delivery period

  • shipping_address (String, nil)

    Body param: The shipping/delivery address

  • shipping_address_recipient (String, nil)

    Body param: The recipient name at the shipping address

  • state (Symbol, EInvoiceAPI::Models::DocumentState)

    Body param: The current state of the document: DRAFT, TRANSIT, FAILED, SENT, or

  • subtotal (Float, String, nil)

    Body param: The taxable base of the invoice. Should be the sum of all line items

  • tax_code (Symbol, EInvoiceAPI::Models::DocumentCreate::TaxCode)

    Body param: Tax category code of the invoice (e.g., S for standard rate, Z for z

  • tax_details (Array<EInvoiceAPI::Models::DocumentCreate::TaxDetail>, nil)

    Body param

  • total_discount (Float, String, nil)

    Body param: The net financial discount/charge of the invoice (non-VAT charges mi

  • total_tax (Float, String, nil)

    Body param: The total tax amount of the invoice. Must be positive and rounded to

  • vatex (Symbol, EInvoiceAPI::Models::DocumentCreate::Vatex, nil)

    Body param: VATEX code list for VAT exemption reasons

  • vatex_note (String, nil)

    Body param: Textual explanation for VAT exemption

  • vendor_address (String, nil)

    Body param: The address of the vendor/seller

  • vendor_address_recipient (String, nil)

    Body param: The recipient name at the vendor address

  • vendor_company_id (String, nil)

    Body param: Vendor company ID. For Belgium this is the CBE number or their EUID

  • vendor_email (String, nil)

    Body param: The email address of the vendor

  • vendor_name (String, nil)

    Body param: The name of the vendor/seller/supplier

  • vendor_tax_id (String, nil)

    Body param: Vendor tax ID. For Belgium this is the VAT number. Must include the

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

Returns:

See Also:



124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/e_invoice_api/resources/documents.rb', line 124

def create(params = {})
  query_params = [:construct_pdf]
  parsed, options = EInvoiceAPI::DocumentCreateParams.dump_request(params)
  query = EInvoiceAPI::Internal::Util.encode_query_params(parsed.slice(*query_params))
  @client.request(
    method: :post,
    path: "api/documents/",
    query: query,
    body: parsed.except(*query_params),
    model: EInvoiceAPI::DocumentResponse,
    options: options
  )
end

#create_from_pdf(file:, customer_tax_id: nil, vendor_tax_id: nil, request_options: {}) ⇒ EInvoiceAPI::Models::DocumentCreateFromPdfResponse

Create a new invoice or credit note from a PDF file. If the ‘ubl_document’ field is set in the response, it indicates that sufficient details were extracted from the PDF to automatically generate a valid UBL document ready for sending. If ‘ubl_document’ is not set, human intervention may be required to ensure compliance.

Parameters:

  • file (Pathname, StringIO, IO, String, EInvoiceAPI::FilePart)

    Body param

  • customer_tax_id (String, nil)

    Query param

  • vendor_tax_id (String, nil)

    Query param

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

Returns:

See Also:



195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/e_invoice_api/resources/documents.rb', line 195

def create_from_pdf(params)
  query_params = [:customer_tax_id, :vendor_tax_id]
  parsed, options = EInvoiceAPI::DocumentCreateFromPdfParams.dump_request(params)
  query = EInvoiceAPI::Internal::Util.encode_query_params(parsed.slice(*query_params))
  @client.request(
    method: :post,
    path: "api/documents/pdf",
    query: query,
    headers: {"content-type" => "multipart/form-data"},
    body: parsed.except(*query_params),
    model: EInvoiceAPI::Models::DocumentCreateFromPdfResponse,
    options: options
  )
end

#delete(document_id, request_options: {}) ⇒ EInvoiceAPI::Models::DocumentDeleteResponse

Delete an invoice or credit note

Parameters:

Returns:

See Also:



167
168
169
170
171
172
173
174
# File 'lib/e_invoice_api/resources/documents.rb', line 167

def delete(document_id, params = {})
  @client.request(
    method: :delete,
    path: ["api/documents/%1$s", document_id],
    model: EInvoiceAPI::Models::DocumentDeleteResponse,
    options: params[:request_options]
  )
end

#retrieve(document_id, request_options: {}) ⇒ EInvoiceAPI::Models::DocumentResponse

Get an invoice or credit note by ID

Parameters:

Returns:

See Also:



148
149
150
151
152
153
154
155
# File 'lib/e_invoice_api/resources/documents.rb', line 148

def retrieve(document_id, params = {})
  @client.request(
    method: :get,
    path: ["api/documents/%1$s", document_id],
    model: EInvoiceAPI::DocumentResponse,
    options: params[:request_options]
  )
end

#send_(document_id, email: nil, receiver_peppol_id: nil, receiver_peppol_scheme: nil, sender_peppol_id: nil, sender_peppol_scheme: nil, request_options: {}) ⇒ EInvoiceAPI::Models::DocumentResponse

Send an invoice or credit note via Peppol. By default, the sender and receiver Peppol IDs are derived from the company (tax) IDs in the document, regardless of whether the document was created from a UBL with a different endpoint ID. To explicitly set the sender or receiver Peppol ID, provide them via the query parameters (sender_peppol_scheme, sender_peppol_id, receiver_peppol_scheme, receiver_peppol_id).

Parameters:

  • document_id (String)
  • email (String, nil)
  • receiver_peppol_id (String, nil)
  • receiver_peppol_scheme (String, nil)
  • sender_peppol_id (String, nil)
  • sender_peppol_scheme (String, nil)
  • request_options (EInvoiceAPI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



230
231
232
233
234
235
236
237
238
239
240
# File 'lib/e_invoice_api/resources/documents.rb', line 230

def send_(document_id, params = {})
  parsed, options = EInvoiceAPI::DocumentSendParams.dump_request(params)
  query = EInvoiceAPI::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :post,
    path: ["api/documents/%1$s/send", document_id],
    query: query,
    model: EInvoiceAPI::DocumentResponse,
    options: options
  )
end

#validate(document_id, request_options: {}) ⇒ EInvoiceAPI::Models::UblDocumentValidation

Validate a UBL document according to Peppol BIS Billing 3.0

Parameters:

Returns:

See Also:



252
253
254
255
256
257
258
259
# File 'lib/e_invoice_api/resources/documents.rb', line 252

def validate(document_id, params = {})
  @client.request(
    method: :post,
    path: ["api/documents/%1$s/validate", document_id],
    model: EInvoiceAPI::UblDocumentValidation,
    options: params[:request_options]
  )
end