Class: Payabli::Vendor::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



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

def initialize(client:)
  @client = client
end

Instance Method Details

#add_vendor(request_options: {}, **params) ⇒ Payabli::Types::PayabliApiResponseVendors

Creates a vendor in an entrypoint.

Examples:

client.vendor.add_vendor(
  entry: "8cfec329267",
  vendor_number: "VEN-123",
  address_1: "123 Ocean Drive",
  address_2: "Suite 400",
  billing_data: {
    id: 123,
    bank_name: "Country Bank",
    routing_account: "123123123",
    account_number: "123123123",
    type_account: "Checking",
    bank_account_holder_name: "Gruzya Adventure Outfitters LLC",
    bank_account_holder_type: "Business",
    bank_account_function: 0
  },
  city: "Miami",
  contacts: [{
    contact_name: "Herman Martinez",
    contact_email: "example@email.com",
    contact_title: "Owner",
    contact_phone: "3055550000"
  }],
  country: "US",
  customer_vendor_account: "A-37622",
  ein: "12-3456789",
  email: "example@email.com",
  internal_reference_id: 123,
  location_code: "MIA123",
  mcc: "7777",
  name_1: "Herman's Coatings and Masonry",
  name_2: "<string>",
  payee_name_1: "<string>",
  payee_name_2: "<string>",
  payment_method: "managed",
  phone: "5555555555",
  remit_address_1: "123 Walnut Street",
  remit_address_2: "Suite 900",
  remit_city: "Miami",
  remit_country: "US",
  remit_state: "FL",
  remit_zip: "31113",
  state: "FL",
  vendor_status: 1,
  zip: "33139"
)

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)

Returns:



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/payabli/vendor/client.rb', line 72

def add_vendor(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: "POST",
    path: "Vendor/single/#{URI.encode_uri_component(params[:entry].to_s)}",
    headers: headers,
    body: Payabli::Types::VendorData.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::PayabliApiResponseVendors.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#delete_vendor(request_options: {}, **params) ⇒ Payabli::Types::PayabliApiResponseVendors

Delete a vendor.

Examples:

client.vendor.delete_vendor(id_vendor: 1)

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

Returns:



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

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

#edit_vendor(request_options: {}, **params) ⇒ Payabli::Types::PayabliApiResponseVendors

Updates a vendor's information. Send only the fields you need to update.

Examples:

client.vendor.edit_vendor(
  id_vendor: 1,
  name_1: "Theodore's Janitorial"
)

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

Returns:



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

def edit_vendor(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: "Vendor/#{URI.encode_uri_component(params[:id_vendor].to_s)}",
    headers: headers,
    body: Payabli::Types::VendorData.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::PayabliApiResponseVendors.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#enrich_vendor(request_options: {}, **params) ⇒ Payabli::Types::VendorEnrichResponse

Triggers AI-powered vendor enrichment for an existing vendor. Runs one or more enrichment stages (invoice scan, web search) based on the scope parameter. Can automatically apply extracted payment acceptance info and vendor contact information to the vendor record, or return raw results for manual review. Contact Payabli to enable this feature.

Examples:

client.vendor.enrich_vendor(
  entry: "8cfec329267",
  vendor_id: 456,
  scope: ["invoice_scan"],
  apply_enrichment_data: false,
  invoice_file: {
    ftype: "pdf",
    filename: "invoice-2026-001.pdf",
    f_content: "<base64-encoded-pdf>"
  },
  fallback_method: "check"
)

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)

Returns:



247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/payabli/vendor/client.rb', line 247

def enrich_vendor(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  request_data = Payabli::Vendor::Types::VendorEnrichRequest.new(params).to_h
  non_body_param_names = %w[entry]
  body = request_data.except(*non_body_param_names)

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

#get_enrichment_call_status(request_options: {}, **params) ⇒ Payabli::Types::VendorCallStatusResponse

Returns the latest AI outreach call activity for a vendor. The response is a composite object with a state discriminator (none, scheduled, successful, or failed); the block that matches the current state is populated. When the vendor has no call activity, state is none and the response returns HTTP 200.

Examples:

client.vendor.get_enrichment_call_status(id_vendor: 456)

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

Returns:



350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# File 'lib/payabli/vendor/client.rb', line 350

def get_enrichment_call_status(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: "Vendor/#{URI.encode_uri_component(params[:id_vendor].to_s)}/enrichment/call-status",
    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::VendorCallStatusResponse.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#get_vendor(request_options: {}, **params) ⇒ Payabli::Types::VendorQueryRecord

Retrieves a vendor's details, including enrichment status and payment acceptance info when available.

Examples:

client.vendor.get_vendor(id_vendor: 1)

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

Returns:



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

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

#schedule_enrichment_call(request_options: {}, **params) ⇒ Payabli::Types::VendorScheduleCallResponse

Schedules an AI outreach call to a vendor to collect their preferred payment method and contact email. This is the third enrichment stage. Calls are scheduled for the next business day at around 9 AM in the vendor's timezone, with retries on no-answer and a fallback payment method applied when retries are exhausted. This feature is opt-in at the org level. Contact your Payabli representative to enable it, provision a phone number, and discuss pricing.

Examples:

client.vendor.schedule_enrichment_call(
  entry: "8cfec329267",
  vendor_id: 456,
  phone: "5555550200",
  enrichment_id: "enrich-3890-a1b2c3d4",
  bill_id: 54323,
  fallback_method: "check",
  max_retries: 3,
  timezone: "America/New_York"
)

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)

Returns:



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

def schedule_enrichment_call(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  request_data = Payabli::Vendor::Types::ScheduleEnrichmentCallRequest.new(params).to_h
  non_body_param_names = %w[entry]
  body = request_data.except(*non_body_param_names)

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