Class: Schematic::Checkout::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/schematic/checkout/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void



9
10
11
# File 'lib/schematic/checkout/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#cancel_subscription(request_options: {}, **params) ⇒ Schematic::Checkout::Types::CancelSubscriptionResponse

Examples:

client.checkout.cancel_subscription(company_id: "company_id")

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)

Returns:



363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
# File 'lib/schematic/checkout/client.rb', line 363

def cancel_subscription(request_options: {}, **params)
  params = Schematic::Internal::Types::Utils.normalize_keys(params)
  request = Schematic::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "manage-plan/subscription/cancel",
    body: Schematic::Checkout::Types::CancelSubscriptionRequest.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Schematic::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Schematic::Checkout::Types::CancelSubscriptionResponse.load(response.body)
  else
    error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#get_checkout_data(request_options: {}, **params) ⇒ Schematic::Checkout::Types::GetCheckoutDataResponse

Examples:

client.checkout.get_checkout_data(company_id: "company_id")

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)

Returns:



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/schematic/checkout/client.rb', line 84

def get_checkout_data(request_options: {}, **params)
  params = Schematic::Internal::Types::Utils.normalize_keys(params)
  request = Schematic::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "checkout-internal/data",
    body: Schematic::Checkout::Types::CheckoutDataRequestBody.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Schematic::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Schematic::Checkout::Types::GetCheckoutDataResponse.load(response.body)
  else
    error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#get_company_billing_details(request_options: {}, **params) ⇒ Schematic::Checkout::Types::GetCompanyBillingDetailsResponse

Examples:

client.checkout.get_company_billing_details(company_id: "company_id")

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

  • :company_id (String)

Returns:



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/schematic/checkout/client.rb', line 179

def get_company_billing_details(request_options: {}, **params)
  params = Schematic::Internal::Types::Utils.normalize_keys(params)
  request = Schematic::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "companies/#{URI.encode_uri_component(params[:company_id].to_s)}/billing-details",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Schematic::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Schematic::Checkout::Types::GetCompanyBillingDetailsResponse.load(response.body)
  else
    error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#internal(request_options: {}, **params) ⇒ Schematic::Checkout::Types::CheckoutInternalResponse

Examples:

client.checkout.internal(
  add_on_ids: [{
    add_on_id: "add_on_id",
    price_id: "price_id"
  }],
  auto_topup_overrides: [{
    plan_credit_grant_id: "plan_credit_grant_id"
  }],
  company_id: "company_id",
  credit_bundles: [{
    bundle_id: "bundle_id",
    quantity: 1000000
  }],
  custom_field_values: [{
    id: "id",
    value: "value"
  }],
  new_plan_id: "new_plan_id",
  new_price_id: "new_price_id",
  pay_in_advance: [{
    price_id: "price_id",
    quantity: 1000000
  }],
  skip_trial: 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)

Returns:



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/schematic/checkout/client.rb', line 49

def internal(request_options: {}, **params)
  params = Schematic::Internal::Types::Utils.normalize_keys(params)
  request = Schematic::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "checkout-internal",
    body: Schematic::Types::ChangeSubscriptionInternalRequestBody.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Schematic::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Schematic::Checkout::Types::CheckoutInternalResponse.load(response.body)
  else
    error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#manage_plan(request_options: {}, **params) ⇒ Schematic::Checkout::Types::ManagePlanResponse

Examples:

client.checkout.manage_plan(
  add_on_selections: [{
    plan_id: "plan_id"
  }],
  company_id: "company_id",
  credit_bundles: [{
    bundle_id: "bundle_id",
    quantity: 1000000
  }],
  custom_field_values: [{
    id: "id",
    value: "value"
  }],
  pay_in_advance_entitlements: [{
    price_id: "price_id",
    quantity: 1000000
  }]
)

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)

Returns:



276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/schematic/checkout/client.rb', line 276

def manage_plan(request_options: {}, **params)
  params = Schematic::Internal::Types::Utils.normalize_keys(params)
  request = Schematic::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "manage-plan",
    body: Schematic::Types::ManagePlanRequest.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Schematic::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Schematic::Checkout::Types::ManagePlanResponse.load(response.body)
  else
    error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#preview_checkout_internal(request_options: {}, **params) ⇒ Schematic::Checkout::Types::PreviewCheckoutInternalResponse

Examples:

client.checkout.preview_checkout_internal(
  add_on_ids: [{
    add_on_id: "add_on_id",
    price_id: "price_id"
  }],
  auto_topup_overrides: [{
    plan_credit_grant_id: "plan_credit_grant_id"
  }],
  company_id: "company_id",
  credit_bundles: [{
    bundle_id: "bundle_id",
    quantity: 1000000
  }],
  custom_field_values: [{
    id: "id",
    value: "value"
  }],
  new_plan_id: "new_plan_id",
  new_price_id: "new_price_id",
  pay_in_advance: [{
    price_id: "price_id",
    quantity: 1000000
  }],
  skip_trial: 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)

Returns:



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/schematic/checkout/client.rb', line 143

def preview_checkout_internal(request_options: {}, **params)
  params = Schematic::Internal::Types::Utils.normalize_keys(params)
  request = Schematic::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "checkout-internal/preview",
    body: Schematic::Types::ChangeSubscriptionInternalRequestBody.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Schematic::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Schematic::Checkout::Types::PreviewCheckoutInternalResponse.load(response.body)
  else
    error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#preview_manage_plan(request_options: {}, **params) ⇒ Schematic::Checkout::Types::PreviewManagePlanResponse

Examples:

client.checkout.preview_manage_plan(
  add_on_selections: [{
    plan_id: "plan_id"
  }],
  company_id: "company_id",
  credit_bundles: [{
    bundle_id: "bundle_id",
    quantity: 1000000
  }],
  custom_field_values: [{
    id: "id",
    value: "value"
  }],
  pay_in_advance_entitlements: [{
    price_id: "price_id",
    quantity: 1000000
  }]
)

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)

Returns:



328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/schematic/checkout/client.rb', line 328

def preview_manage_plan(request_options: {}, **params)
  params = Schematic::Internal::Types::Utils.normalize_keys(params)
  request = Schematic::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "manage-plan/preview",
    body: Schematic::Types::ManagePlanRequest.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Schematic::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Schematic::Checkout::Types::PreviewManagePlanResponse.load(response.body)
  else
    error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#update_company_billing_details(request_options: {}, **params) ⇒ Schematic::Checkout::Types::UpdateCompanyBillingDetailsResponse

Examples:

client.checkout.update_company_billing_details(
  company_id: "company_id",
  values: [{
    id: "id",
    value: "value"
  }]
)

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

  • :company_id (String)

Returns:



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/schematic/checkout/client.rb', line 220

def update_company_billing_details(request_options: {}, **params)
  params = Schematic::Internal::Types::Utils.normalize_keys(params)
  request_data = Schematic::Checkout::Types::UpdateCompanyBillingDetailsRequestBody.new(params).to_h
  non_body_param_names = %w[company_id]
  body = request_data.except(*non_body_param_names)

  request = Schematic::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "PUT",
    path: "companies/#{URI.encode_uri_component(params[:company_id].to_s)}/billing-details",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Schematic::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Schematic::Checkout::Types::UpdateCompanyBillingDetailsResponse.load(response.body)
  else
    error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#update_customer_subscription_trial_end(request_options: {}, **params) ⇒ Schematic::Checkout::Types::UpdateCustomerSubscriptionTrialEndResponse

Examples:

client.checkout.update_customer_subscription_trial_end(subscription_id: "subscription_id")

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

  • :subscription_id (String)

Returns:



399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
# File 'lib/schematic/checkout/client.rb', line 399

def update_customer_subscription_trial_end(request_options: {}, **params)
  params = Schematic::Internal::Types::Utils.normalize_keys(params)
  request_data = Schematic::Checkout::Types::UpdateTrialEndRequestBody.new(params).to_h
  non_body_param_names = %w[subscription_id]
  body = request_data.except(*non_body_param_names)

  request = Schematic::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "PUT",
    path: "subscription/#{URI.encode_uri_component(params[:subscription_id].to_s)}/edit-trial-end",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Schematic::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Schematic::Checkout::Types::UpdateCustomerSubscriptionTrialEndResponse.load(response.body)
  else
    error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end