Class: Payabli::PayoutSubscription::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



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

def initialize(client:)
  @client = client
end

Instance Method Details

#create_payout_subscription(request_options: {}, **params) ⇒ Payabli::Types::AddPayoutSubscriptionResponse

Creates a payout subscription to automatically send payouts to a vendor on a recurring schedule. See Manage payout subscriptions for a step-by-step guide.

Examples:

client.payout_subscription.create_payout_subscription(
  entry_point: "8cfec329267",
  payment_method: {
    method_: "ach",
    ach_holder: "Herman Coatings",
    ach_routing: "021000021",
    ach_account: "3453445666",
    ach_account_type: "checking"
  },
  payment_details: {
    total_amount: 500,
    service_fee: 0,
    currency: "USD"
  },
  vendor_data: {
    vendor_id: 456
  },
  bill_data: [{
    invoice_number: "INV-2345",
    net_amount: "500",
    invoice_date: "2025-08-01",
    due_date: "2025-08-15"
  }],
  schedule_details: {
    start_date: "09/01/2027",
    end_date: "09/01/2026",
    frequency: "monthly"
  }
)

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:



57
58
59
60
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
# File 'lib/payabli/payout_subscription/client.rb', line 57

def create_payout_subscription(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  request_data = Payabli::PayoutSubscription::Types::RequestPayoutSchedule.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: "PayoutSubscription",
    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::AddPayoutSubscriptionResponse.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#delete_payout_subscription(request_options: {}, **params) ⇒ Payabli::Types::DeletePayoutSubscriptionResponse

Deletes a payout subscription and prevents future payouts. See Manage payout subscriptions for more information.

Examples:

client.payout_subscription.delete_payout_subscription(id: 42)

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 (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/payout_subscription/client.rb', line 193

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

#get_payout_subscription(request_options: {}, **params) ⇒ Payabli::Types::GetPayoutSubscriptionResponse

Retrieves a single payout subscription's details. See Manage payout subscriptions for more information.

Examples:

client.payout_subscription.get_payout_subscription(id: 42)

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

Returns:



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/payabli/payout_subscription/client.rb', line 105

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

#update_payout_subscription(request_options: {}, **params) ⇒ Payabli::Types::UpdatePayoutSubscriptionResponse

Updates a payout subscription's details. See Manage payout subscriptions for more information.

Examples:

client.payout_subscription.update_payout_subscription(
  id: 42,
  set_pause: true
)

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

Returns:



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

def update_payout_subscription(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  request_data = Payabli::PayoutSubscription::Types::UpdatePayoutSubscriptionBody.new(params).to_h
  non_body_param_names = %w[id]
  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: "PayoutSubscription/#{URI.encode_uri_component(params[: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::UpdatePayoutSubscriptionResponse.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end