Class: Payabli::Invoice::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/payabli/invoice/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



9
10
11
# File 'lib/payabli/invoice/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#add_invoice(request_options: {}, **params) ⇒ Payabli::Types::InvoiceResponseWithoutData

Creates an invoice in an entrypoint.

Examples:

client.invoice.add_invoice(
  entry: "8cfec329267",
  customer_data: {
    first_name: "Tamara",
    last_name: "Bagratoni",
    customer_number: "C-90010"
  },
  invoice_data: {
    items: [{
      item_product_name: "Adventure Consult",
      item_description: "Consultation for Georgian tours",
      item_cost: 100,
      item_qty: 2,
      item_mode: 2,
      item_total_amount: 200
    }, {
      item_product_name: "Deposit ",
      item_description: "Deposit for trip planning",
      item_cost: 882.37,
      item_qty: 1,
      item_mode: 2,
      item_total_amount: 882.37
    }],
    invoice_date: "2025-10-19",
    invoice_type: 0,
    invoice_status: 1,
    frequency: "onetime",
    invoice_amount: 1082.37,
    discount: 10,
    invoice_number: "INV-2345"
  }
)

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :entry (String)
  • :force_customer_creation (Boolean, nil)
  • :idempotency_key (String, nil)

Returns:



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/payabli/invoice/client.rb', line 61

def add_invoice(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  path_param_names = %i[entry]
  body_params = params.except(*path_param_names)

  query_param_names = %i[force_customer_creation]
  query_params = {}
  query_params["forceCustomerCreation"] = params[:force_customer_creation] if params.key?(:force_customer_creation)
  params = params.except(*query_param_names)

  headers = {}
  headers["idempotencyKey"] = params[:idempotency_key] if params[:idempotency_key]

  headers = @client.auth_headers_for_endpoint(security: [{ "BearerAuth" => [] }, { "APIKeyAuth" => [] }]).merge(headers)
  request = Payabli::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "Invoice/#{URI.encode_uri_component(params[:entry].to_s)}",
    headers: headers,
    query: query_params,
    body: Payabli::Types::InvoiceDataRequest.new(body_params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Payabli::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Payabli::Types::InvoiceResponseWithoutData.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#delete_attached_from_invoice(request_options: {}, **params) ⇒ Payabli::Types::InvoiceResponseWithoutData

Deletes a file attached to an invoice.

Examples:

client.invoice.delete_attached_from_invoice(
  id_invoice: 23548884,
  filename: "0_Bill.pdf"
)

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :id_invoice (Integer)
  • :filename (String)

Returns:



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/payabli/invoice/client.rb', line 165

def delete_attached_from_invoice(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  headers = @client.auth_headers_for_endpoint(security: [{ "BearerAuth" => [] }, { "APIKeyAuth" => [] }])
  request = Payabli::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "DELETE",
    path: "Invoice/attachedFileFromInvoice/#{URI.encode_uri_component(params[:id_invoice].to_s)}/#{URI.encode_uri_component(params[:filename].to_s)}",
    headers: headers,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Payabli::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Payabli::Types::InvoiceResponseWithoutData.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#delete_invoice(request_options: {}, **params) ⇒ Payabli::Types::InvoiceResponseWithoutData

Deletes a single invoice from an entrypoint.

Examples:

client.invoice.delete_invoice(id_invoice: 23548884)

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :id_invoice (Integer)

Returns:



306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/payabli/invoice/client.rb', line 306

def delete_invoice(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  headers = @client.auth_headers_for_endpoint(security: [{ "BearerAuth" => [] }, { "APIKeyAuth" => [] }])
  request = Payabli::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "DELETE",
    path: "Invoice/#{URI.encode_uri_component(params[:id_invoice].to_s)}",
    headers: headers,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Payabli::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Payabli::Types::InvoiceResponseWithoutData.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#edit_invoice(request_options: {}, **params) ⇒ Payabli::Types::InvoiceResponseWithoutData

Updates details for a single invoice in an entrypoint.

Examples:

client.invoice.edit_invoice(
  id_invoice: 23548884,
  invoice_data: {
    items: [{
      item_product_name: "Deposit",
      item_description: "Deposit for trip planning",
      item_cost: 882.37,
      item_qty: 1
    }],
    invoice_date: "2025-10-19",
    invoice_amount: 982.37,
    invoice_number: "INV-2345"
  }
)

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :id_invoice (Integer)
  • :force_customer_creation (Boolean, nil)

Returns:



257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/payabli/invoice/client.rb', line 257

def edit_invoice(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  path_param_names = %i[id_invoice]
  body_params = params.except(*path_param_names)

  query_param_names = %i[force_customer_creation]
  query_params = {}
  query_params["forceCustomerCreation"] = params[:force_customer_creation] if params.key?(:force_customer_creation)
  params = params.except(*query_param_names)

  headers = @client.auth_headers_for_endpoint(security: [{ "BearerAuth" => [] }, { "APIKeyAuth" => [] }])
  request = Payabli::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "PUT",
    path: "Invoice/#{URI.encode_uri_component(params[:id_invoice].to_s)}",
    headers: headers,
    query: query_params,
    body: Payabli::Types::InvoiceDataRequest.new(body_params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Payabli::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Payabli::Types::InvoiceResponseWithoutData.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#get_attached_file_from_invoice(request_options: {}, **params) ⇒ Payabli::Types::FileContent

Retrieves a file attached to an invoice.

Examples:

client.invoice.get_attached_file_from_invoice(
  id_invoice: 1,
  filename: "filename"
)

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :id_invoice (Integer)
  • :filename (String)
  • :return_object (Boolean, nil)

Returns:



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/payabli/invoice/client.rb', line 118

def get_attached_file_from_invoice(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["returnObject"] = params[:return_object] if params.key?(:return_object)

  headers = @client.auth_headers_for_endpoint(security: [{ "BearerAuth" => [] }, { "APIKeyAuth" => [] }])
  request = Payabli::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "Invoice/attachedFileFromInvoice/#{URI.encode_uri_component(params[:id_invoice].to_s)}/#{URI.encode_uri_component(params[:filename].to_s)}",
    headers: headers,
    query: query_params,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Payabli::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Payabli::Types::FileContent.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#get_invoice(request_options: {}, **params) ⇒ Payabli::Types::GetInvoiceRecord

Retrieves a single invoice by ID.

Examples:

client.invoice.get_invoice(id_invoice: 23548884)

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :id_invoice (Integer)

Returns:



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/payabli/invoice/client.rb', line 204

def get_invoice(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  headers = @client.auth_headers_for_endpoint(security: [{ "BearerAuth" => [] }, { "APIKeyAuth" => [] }])
  request = Payabli::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "Invoice/#{URI.encode_uri_component(params[:id_invoice].to_s)}",
    headers: headers,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Payabli::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Payabli::Types::GetInvoiceRecord.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#get_invoice_number(request_options: {}, **params) ⇒ Payabli::Types::InvoiceNumberResponse

Retrieves the next available invoice number for a paypoint.

Examples:

client.invoice.get_invoice_number(entry: "8cfec329267")

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :entry (String)

Returns:



345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
# File 'lib/payabli/invoice/client.rb', line 345

def get_invoice_number(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  headers = @client.auth_headers_for_endpoint(security: [{ "BearerAuth" => [] }, { "APIKeyAuth" => [] }])
  request = Payabli::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "Invoice/getNumber/#{URI.encode_uri_component(params[:entry].to_s)}",
    headers: headers,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Payabli::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Payabli::Types::InvoiceNumberResponse.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#get_invoice_pdf(request_options: {}, **params) ⇒ Hash[String, Object]

Export a single invoice in PDF format.

Examples:

client.invoice.get_invoice_pdf(id_invoice: 23548884)

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :id_invoice (Integer)

Returns:

  • (Hash[String, Object])


550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
# File 'lib/payabli/invoice/client.rb', line 550

def get_invoice_pdf(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  headers = @client.auth_headers_for_endpoint(security: [{ "BearerAuth" => [] }, { "APIKeyAuth" => [] }])
  request = Payabli::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "Export/invoicePdf/#{URI.encode_uri_component(params[:id_invoice].to_s)}",
    headers: headers,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Payabli::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Payabli::Types::File.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#list_invoices(request_options: {}, **params) ⇒ Payabli::Types::QueryInvoiceResponse

Returns a list of invoices for an entrypoint. Use filters to limit results. Include the exportFormat query parameter to return the results as a file instead of a JSON response.

Examples:

client.invoice.list_invoices(
  entry: "8cfec329267",
  from_record: 251,
  limit_record: 0,
  sort_by: "desc(field_name)"
)

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :entry (String)
  • :export_format (Payabli::Types::ExportFormat, nil)
  • :from_record (Integer, nil)
  • :limit_record (Integer, nil)
  • :parameters (Hash[String, String, nil], nil)
  • :sort_by (String, nil)

Returns:



395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
# File 'lib/payabli/invoice/client.rb', line 395

def list_invoices(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["exportFormat"] = params[:export_format] if params.key?(:export_format)
  query_params["fromRecord"] = params[:from_record] if params.key?(:from_record)
  query_params["limitRecord"] = params[:limit_record] if params.key?(:limit_record)
  query_params["parameters"] = params[:parameters] if params.key?(:parameters)
  query_params["sortBy"] = params[:sort_by] if params.key?(:sort_by)

  headers = @client.auth_headers_for_endpoint(security: [{ "BearerAuth" => [] }, { "APIKeyAuth" => [] }])
  request = Payabli::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "Query/invoices/#{URI.encode_uri_component(params[:entry].to_s)}",
    headers: headers,
    query: query_params,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Payabli::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Payabli::Types::QueryInvoiceResponse.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#list_invoices_org(request_options: {}, **params) ⇒ Payabli::Types::QueryInvoiceResponse

Returns a list of invoices for an org. Use filters to limit results. Include the exportFormat query parameter to return the results as a file instead of a JSON response.

Examples:

client.invoice.list_invoices_org(
  org_id: 123,
  from_record: 251,
  limit_record: 0,
  sort_by: "desc(field_name)"
)

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :org_id (Integer)
  • :export_format (Payabli::Types::ExportFormat, nil)
  • :from_record (Integer, nil)
  • :limit_record (Integer, nil)
  • :parameters (Hash[String, String, nil], nil)
  • :sort_by (String, nil)

Returns:



453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
# File 'lib/payabli/invoice/client.rb', line 453

def list_invoices_org(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["exportFormat"] = params[:export_format] if params.key?(:export_format)
  query_params["fromRecord"] = params[:from_record] if params.key?(:from_record)
  query_params["limitRecord"] = params[:limit_record] if params.key?(:limit_record)
  query_params["parameters"] = params[:parameters] if params.key?(:parameters)
  query_params["sortBy"] = params[:sort_by] if params.key?(:sort_by)

  headers = @client.auth_headers_for_endpoint(security: [{ "BearerAuth" => [] }, { "APIKeyAuth" => [] }])
  request = Payabli::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "Query/invoices/org/#{URI.encode_uri_component(params[:org_id].to_s)}",
    headers: headers,
    query: query_params,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Payabli::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Payabli::Types::QueryInvoiceResponse.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#send_invoice(request_options: {}, **params) ⇒ Payabli::Types::SendInvoiceResponse

Sends an invoice from an entrypoint via email.

Examples:

client.invoice.send_invoice(
  id_invoice: 23548884,
  attachfile: true,
  mail_2: "tamara@example.com"
)

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :id_invoice (Integer)
  • :attachfile (Boolean, nil)
  • :mail_2 (String, nil)

Returns:



506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
# File 'lib/payabli/invoice/client.rb', line 506

def send_invoice(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["attachfile"] = params[:attachfile] if params.key?(:attachfile)
  query_params["mail2"] = params[:mail_2] if params.key?(:mail_2)

  headers = @client.auth_headers_for_endpoint(security: [{ "BearerAuth" => [] }, { "APIKeyAuth" => [] }])
  request = Payabli::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "Invoice/send/#{URI.encode_uri_component(params[:id_invoice].to_s)}",
    headers: headers,
    query: query_params,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Payabli::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Payabli::Types::SendInvoiceResponse.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end