Class: Payabli::Organization::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



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

def initialize(client:)
  @client = client
end

Instance Method Details

#add_organization(request_options: {}, **params) ⇒ Payabli::Types::AddOrganizationResponse

Creates an organization under a parent organization. This is also referred to as a suborganization.

Examples:

client.organization.add_organization(
  idempotency_key: "6B29FC40-CA47-1067-B31D-00DD010662DA",
  billing_info: {
    ach_account: "123123123",
    ach_routing: "123123123",
    billing_address: "123 Walnut Street",
    billing_city: "Johnson City",
    billing_country: "US",
    billing_state: "TN",
    billing_zip: "37615"
  },
  contacts: [{
    contact_email: "herman@hermanscoatings.com",
    contact_name: "Herman Martinez",
    contact_phone: "3055550000",
    contact_title: "Owner"
  }],
  has_billing: true,
  has_residual: true,
  org_address: "123 Walnut Street",
  org_city: "Johnson City",
  org_country: "US",
  org_entry_name: "pilgrim-planner",
  org_id: "123",
  org_logo: {
    f_content: "TXkgdGVzdCBmaWxlHJ==...",
    filename: "my-doc.pdf",
    ftype: "pdf",
    furl: "https://mysite.com/my-doc.pdf"
  },
  org_name: "Pilgrim Planner",
  org_parent_id: 236,
  org_state: "TN",
  org_timezone: -5,
  org_type: 0,
  org_website: "www.pilgrimageplanner.com",
  org_zip: "37615",
  reply_to_email: "email@example.com"
)

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):

  • :idempotency_key (String, nil)

Returns:



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/organization/client.rb', line 66

def add_organization(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  request_data = Payabli::Organization::Types::AddOrganizationRequest.new(params).to_h
  non_body_param_names = %w[idempotencyKey]
  body = request_data.except(*non_body_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: "Organization",
    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::AddOrganizationResponse.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#delete_organization(request_options: {}, **params) ⇒ Payabli::Types::DeleteOrganizationResponse

Delete an organization by ID.

Examples:

client.organization.delete_organization(org_id: 123)

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)

Returns:



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/payabli/organization/client.rb', line 176

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

#edit_organization(request_options: {}, **params) ⇒ Payabli::Types::EditOrganizationResponse

Updates an organization's details by ID.

Examples:

client.organization.edit_organization(
  org_id: 123,
  contacts: [{
    contact_email: "herman@hermanscoatings.com",
    contact_name: "Herman Martinez",
    contact_phone: "3055550000",
    contact_title: "Owner"
  }],
  org_address: "123 Walnut Street",
  org_city: "Johnson City",
  org_country: "US",
  org_entry_name: "pilgrim-planner",
  organization_data_org_id: "123",
  org_name: "Pilgrim Planner",
  org_state: "TN",
  org_timezone: -5,
  org_type: 0,
  org_website: "www.pilgrimageplanner.com",
  org_zip: "37615"
)

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):

  • :org_id (Integer)

Returns:



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/payabli/organization/client.rb', line 132

def edit_organization(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  request_data = Payabli::Organization::Types::OrganizationData.new(params).to_h
  non_body_param_names = %w[orgId]
  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: "PUT",
    path: "Organization/#{URI.encode_uri_component(params[:org_id].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::EditOrganizationResponse.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#get_basic_organization(request_options: {}, **params) ⇒ Payabli::Types::OrganizationQueryRecord

Gets an organization's basic information by entry name (entrypoint identifier).

Examples:

client.organization.get_basic_organization(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:



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/payabli/organization/client.rb', line 215

def get_basic_organization(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: "Organization/basic/#{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::OrganizationQueryRecord.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#get_basic_organization_by_id(request_options: {}, **params) ⇒ Payabli::Types::OrganizationQueryRecord

Gets an organization's basic details by org ID.

Examples:

client.organization.get_basic_organization_by_id(org_id: 123)

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)

Returns:



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/payabli/organization/client.rb', line 254

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

#get_organization(request_options: {}, **params) ⇒ Payabli::Types::OrganizationQueryRecord

Retrieves details for an organization by ID.

Examples:

client.organization.get_organization(org_id: 123)

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)

Returns:



293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/payabli/organization/client.rb', line 293

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

#get_settings_organization(request_options: {}, **params) ⇒ Payabli::Types::SettingsQueryRecord

Retrieves an organization's settings.

Examples:

client.organization.get_settings_organization(org_id: 123)

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)

Returns:



332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# File 'lib/payabli/organization/client.rb', line 332

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