Class: Payabli::Bill::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



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

def initialize(client:)
  @client = client
end

Instance Method Details

#add_bill(request_options: {}, **params) ⇒ Payabli::Types::BillResponse

Creates a bill in an entrypoint.

Examples:

client.bill.add_bill(
  entry: "8cfec329267",
  accounting_field_1: "MyInternalId",
  attachments: [{
    ftype: "pdf",
    filename: "my-doc.pdf",
    furl: "https://mysite.com/my-doc.pdf"
  }],
  bill_date: "2024-07-01",
  bill_items: [{
    item_product_code: "M-DEPOSIT",
    item_product_name: "Materials deposit",
    item_description: "Deposit for materials",
    item_commodity_code: "010",
    item_unit_of_measure: "SqFt",
    item_cost: 5,
    item_qty: 1,
    item_mode: 0,
    item_categories: ["deposits"],
    item_total_amount: 123,
    item_tax_amount: 7,
    item_tax_rate: 0.075
  }],
  bill_number: "ABC-123",
  comments: "Deposit for materials",
  due_date: "2024-07-01",
  end_date: "2024-07-01",
  frequency: "monthly",
  mode: 0,
  net_amount: 3762.87,
  status: 1,
  terms: "NET30",
  vendor: {
    vendor_number: "VEN-123"
  }
)

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)
  • :idempotency_key (String, nil)

Returns:



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
# File 'lib/payabli/bill/client.rb', line 64

def add_bill(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  path_param_names = %i[entry]
  body_params = params.except(*path_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: "Bill/single/#{URI.encode_uri_component(params[:entry].to_s)}",
    headers: headers,
    body: Payabli::Types::BillOutData.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::BillResponse.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_bill(request_options: {}, **params) ⇒ Payabli::Types::BillResponse

Delete a file attached to a bill.

Examples:

client.bill.delete_attached_from_bill(
  id_bill: 285,
  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_bill (Integer)
  • :filename (String)
  • :return_object (Boolean, nil)

Returns:



286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/payabli/bill/client.rb', line 286

def delete_attached_from_bill(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: "DELETE",
    path: "Bill/attachedFileFromBill/#{URI.encode_uri_component(params[:id_bill].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::BillResponse.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#delete_bill(request_options: {}, **params) ⇒ Payabli::Types::BillResponse

Deletes a bill by ID.

Examples:

client.bill.delete_bill(id_bill: 285)

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_bill (Integer)

Returns:



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/payabli/bill/client.rb', line 193

def delete_bill(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: "Bill/#{URI.encode_uri_component(params[:id_bill].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::BillResponse.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#edit_bill(request_options: {}, **params) ⇒ Payabli::Types::EditBillResponse

Updates a bill by ID.

Examples:

client.bill.edit_bill(
  id_bill: 285,
  bill_date: "2025-07-01",
  net_amount: 3762.87
)

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_bill (Integer)

Returns:



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/payabli/bill/client.rb', line 153

def edit_bill(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: "PUT",
    path: "Bill/#{URI.encode_uri_component(params[:id_bill].to_s)}",
    headers: headers,
    body: Payabli::Types::BillOutData.new(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::EditBillResponse.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_from_bill(request_options: {}, **params) ⇒ Payabli::Types::FileContent

Retrieves a file attached to a bill, either as a binary file or as a Base64-encoded string.

Examples:

client.bill.get_attached_from_bill(
  id_bill: 285,
  filename: "0_Bill.pdf",
  return_object: true
)

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_bill (Integer)
  • :filename (String)
  • :return_object (Boolean, nil)

Returns:



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/payabli/bill/client.rb', line 238

def get_attached_from_bill(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: "Bill/attachedFileFromBill/#{URI.encode_uri_component(params[:id_bill].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_bill(request_options: {}, **params) ⇒ Payabli::Types::GetBillResponse

Retrieves a bill by ID from an entrypoint.

Examples:

client.bill.get_bill(id_bill: 285)

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_bill (Integer)

Returns:



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/payabli/bill/client.rb', line 110

def get_bill(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: "Bill/#{URI.encode_uri_component(params[:id_bill].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::GetBillResponse.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#list_bills(request_options: {}, **params) ⇒ Payabli::Types::BillQueryResponse

Retrieve a list of bills 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.bill.list_bills(
  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:



489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
# File 'lib/payabli/bill/client.rb', line 489

def list_bills(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/bills/#{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::BillQueryResponse.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#list_bills_org(request_options: {}, **params) ⇒ Payabli::Types::BillQueryResponse

Retrieve a list of bills for an organization. Use filters to limit results. Include the exportFormat query parameter to return the results as a file instead of a JSON response.

Examples:

client.bill.list_bills_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:



547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
# File 'lib/payabli/bill/client.rb', line 547

def list_bills_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/bills/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::BillQueryResponse.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#modify_approval_bill(request_options: {}, **params) ⇒ Payabli::Types::ModifyApprovalBillResponse

Modify the list of users the bill is sent to for approval.

Examples:

client.bill.modify_approval_bill(
  id_bill: 285,
  request: %w[approver1@example.com approver2@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_bill (Integer)

Returns:



390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
# File 'lib/payabli/bill/client.rb', line 390

def modify_approval_bill(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: "PUT",
    path: "Bill/approval/#{URI.encode_uri_component(params[:id_bill].to_s)}",
    headers: headers,
    body: 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::ModifyApprovalBillResponse.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#send_to_approval_bill(request_options: {}, **params) ⇒ Payabli::Types::BillResponse

Send a bill to a user or list of users to approve.

Examples:

client.bill.send_to_approval_bill(
  id_bill: 285,
  idempotency_key: "6B29FC40-CA47-1067-B31D-00DD010662DA",
  body: ["approver@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_bill (Integer)
  • :autocreate_user (Boolean, nil)
  • :idempotency_key (String, nil)

Returns:



335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
# File 'lib/payabli/bill/client.rb', line 335

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

  query_param_names = %i[autocreate_user]
  query_params = {}
  query_params["autocreateUser"] = params[:autocreate_user] if params.key?(:autocreate_user)
  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: "Bill/approval/#{URI.encode_uri_component(params[:id_bill].to_s)}",
    headers: headers,
    query: query_params,
    body: body_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::BillResponse.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#set_approved_bill(request_options: {}, **params) ⇒ Payabli::Types::SetApprovedBillResponse

Approve or disapprove a bill by ID.

Examples:

client.bill.set_approved_bill(
  id_bill: 285,
  approved: "true"
)

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_bill (Integer)
  • :approved (String)
  • :email (String, nil)

Returns:



435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
# File 'lib/payabli/bill/client.rb', line 435

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

  headers = @client.auth_headers_for_endpoint(security: [{ "BearerAuth" => [] }, { "APIKeyAuth" => [] }])
  request = Payabli::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "Bill/approval/#{URI.encode_uri_component(params[:id_bill].to_s)}/#{URI.encode_uri_component(params[:approved].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::SetApprovedBillResponse.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end