Class: Orb::Resources::Customers::Credits::TopUps

Inherits:
Object
  • Object
show all
Defined in:
lib/orb/resources/customers/credits/top_ups.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ TopUps

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of TopUps.

Parameters:



222
223
224
# File 'lib/orb/resources/customers/credits/top_ups.rb', line 222

def initialize(client:)
  @client = client
end

Instance Method Details

#create(customer_id, amount: , currency: , invoice_settings: , per_unit_cost_basis: , threshold: , active_from: nil, expires_after: nil, expires_after_unit: nil, request_options: {}) ⇒ Orb::Models::Customers::Credits::TopUpCreateResponse

Some parameter documentations has been truncated, see Models::Customers::Credits::TopUpCreateParams for more details.

This endpoint allows you to create a new top-up for a specified customer’s balance. While this top-up is active, the customer’s balance will added in increments of the specified amount whenever the balance reaches the specified threshold.

If a top-up already exists for this customer in the same currency, the existing top-up will be replaced.

Parameters:

  • customer_id (String)
  • amount (String)

    The amount to increment when the threshold is reached.

  • currency (String)

    The currency or custom pricing unit to use for this top-up. If this is a real-wo

  • invoice_settings (Orb::Models::Customers::Credits::TopUpCreateParams::InvoiceSettings)

    Settings for invoices generated by triggered top-ups.

  • per_unit_cost_basis (String)

    How much, in the customer’s currency, to charge for each unit.

  • threshold (String)

    The threshold at which to trigger the top-up. If the balance is at or below this

  • active_from (Time, nil)

    The date from which the top-up is active. If unspecified, the top-up is active i

  • expires_after (Integer, nil)

    The number of days or months after which the top-up expires. If unspecified, it

  • expires_after_unit (Symbol, Orb::Models::Customers::Credits::TopUpCreateParams::ExpiresAfterUnit, nil)

    The unit of expires_after.

  • request_options (Orb::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



44
45
46
47
48
49
50
51
52
53
# File 'lib/orb/resources/customers/credits/top_ups.rb', line 44

def create(customer_id, params)
  parsed, options = Orb::Customers::Credits::TopUpCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["customers/%1$s/credits/top_ups", customer_id],
    body: parsed,
    model: Orb::Models::Customers::Credits::TopUpCreateResponse,
    options: options
  )
end

#create_by_external_id(external_customer_id, amount: , currency: , invoice_settings: , per_unit_cost_basis: , threshold: , active_from: nil, expires_after: nil, expires_after_unit: nil, request_options: {}) ⇒ Orb::Models::Customers::Credits::TopUpCreateByExternalIDResponse

Some parameter documentations has been truncated, see Models::Customers::Credits::TopUpCreateByExternalIDParams for more details.

This endpoint allows you to create a new top-up for a specified customer’s balance. While this top-up is active, the customer’s balance will added in increments of the specified amount whenever the balance reaches the specified threshold.

If a top-up already exists for this customer in the same currency, the existing top-up will be replaced.

Parameters:

  • external_customer_id (String)
  • amount (String)

    The amount to increment when the threshold is reached.

  • currency (String)

    The currency or custom pricing unit to use for this top-up. If this is a real-wo

  • invoice_settings (Orb::Models::Customers::Credits::TopUpCreateByExternalIDParams::InvoiceSettings)

    Settings for invoices generated by triggered top-ups.

  • per_unit_cost_basis (String)

    How much, in the customer’s currency, to charge for each unit.

  • threshold (String)

    The threshold at which to trigger the top-up. If the balance is at or below this

  • active_from (Time, nil)

    The date from which the top-up is active. If unspecified, the top-up is active i

  • expires_after (Integer, nil)

    The number of days or months after which the top-up expires. If unspecified, it

  • expires_after_unit (Symbol, Orb::Models::Customers::Credits::TopUpCreateByExternalIDParams::ExpiresAfterUnit, nil)

    The unit of expires_after.

  • request_options (Orb::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



148
149
150
151
152
153
154
155
156
157
# File 'lib/orb/resources/customers/credits/top_ups.rb', line 148

def create_by_external_id(external_customer_id, params)
  parsed, options = Orb::Customers::Credits::TopUpCreateByExternalIDParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["customers/external_customer_id/%1$s/credits/top_ups", external_customer_id],
    body: parsed,
    model: Orb::Models::Customers::Credits::TopUpCreateByExternalIDResponse,
    options: options
  )
end

#delete(top_up_id, customer_id: , request_options: {}) ⇒ nil

This deactivates the top-up and voids any invoices associated with pending credit blocks purchased through the top-up.

Parameters:

  • top_up_id (String)
  • customer_id (String)
  • request_options (Orb::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/orb/resources/customers/credits/top_ups.rb', line 97

def delete(top_up_id, params)
  parsed, options = Orb::Customers::Credits::TopUpDeleteParams.dump_request(params)
  customer_id =
    parsed.delete(:customer_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :delete,
    path: ["customers/%1$s/credits/top_ups/%2$s", customer_id, top_up_id],
    model: NilClass,
    options: options
  )
end

#delete_by_external_id(top_up_id, external_customer_id: , request_options: {}) ⇒ nil

This deactivates the top-up and voids any invoices associated with pending credit blocks purchased through the top-up.

Parameters:

  • top_up_id (String)
  • external_customer_id (String)
  • request_options (Orb::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/orb/resources/customers/credits/top_ups.rb', line 171

def delete_by_external_id(top_up_id, params)
  parsed, options = Orb::Customers::Credits::TopUpDeleteByExternalIDParams.dump_request(params)
  external_customer_id =
    parsed.delete(:external_customer_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :delete,
    path: [
      "customers/external_customer_id/%1$s/credits/top_ups/%2$s",
      external_customer_id,
      top_up_id
    ],
    model: NilClass,
    options: options
  )
end

#list(customer_id, cursor: nil, limit: nil, request_options: {}) ⇒ Orb::Internal::Page<Orb::Models::Customers::Credits::TopUpListResponse>

Some parameter documentations has been truncated, see Models::Customers::Credits::TopUpListParams for more details.

List top-ups

Parameters:

  • customer_id (String)
  • cursor (String, nil)

    Cursor for pagination. This can be populated by the ‘next_cursor` value returned

  • limit (Integer)

    The number of items to fetch. Defaults to 20.

  • request_options (Orb::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/orb/resources/customers/credits/top_ups.rb', line 73

def list(customer_id, params = {})
  parsed, options = Orb::Customers::Credits::TopUpListParams.dump_request(params)
  @client.request(
    method: :get,
    path: ["customers/%1$s/credits/top_ups", customer_id],
    query: parsed,
    page: Orb::Internal::Page,
    model: Orb::Models::Customers::Credits::TopUpListResponse,
    options: options
  )
end

#list_by_external_id(external_customer_id, cursor: nil, limit: nil, request_options: {}) ⇒ Orb::Internal::Page<Orb::Models::Customers::Credits::TopUpListByExternalIDResponse>

Some parameter documentations has been truncated, see Models::Customers::Credits::TopUpListByExternalIDParams for more details.

List top-ups by external ID

Parameters:

  • external_customer_id (String)
  • cursor (String, nil)

    Cursor for pagination. This can be populated by the ‘next_cursor` value returned

  • limit (Integer)

    The number of items to fetch. Defaults to 20.

  • request_options (Orb::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



207
208
209
210
211
212
213
214
215
216
217
# File 'lib/orb/resources/customers/credits/top_ups.rb', line 207

def list_by_external_id(external_customer_id, params = {})
  parsed, options = Orb::Customers::Credits::TopUpListByExternalIDParams.dump_request(params)
  @client.request(
    method: :get,
    path: ["customers/external_customer_id/%1$s/credits/top_ups", external_customer_id],
    query: parsed,
    page: Orb::Internal::Page,
    model: Orb::Models::Customers::Credits::TopUpListByExternalIDResponse,
    options: options
  )
end