Class: AdvancedBilling::ComponentsController
- Inherits:
-
BaseController
- Object
- BaseController
- AdvancedBilling::ComponentsController
- Defined in:
- lib/advanced_billing/controllers/components_controller.rb
Overview
ComponentsController
Constant Summary
Constants inherited from BaseController
Instance Attribute Summary
Attributes inherited from BaseController
Instance Method Summary collapse
-
#archive_component(product_family_id, component_id) ⇒ Component
Archives the component; all current subscribers will continue to be charged as usual.
-
#create_event_based_component(product_family_id, body: nil) ⇒ ComponentResponse
Creates an event-based component definition under the specified product family.
-
#create_metered_component(product_family_id, body: nil) ⇒ ComponentResponse
Creates a metered component definition under the specified product family.
-
#create_on_off_component(product_family_id, body: nil) ⇒ ComponentResponse
Creates an On/Off component definition under the specified product family.
-
#create_prepaid_usage_component(product_family_id, body: nil) ⇒ ComponentResponse
Creates a prepaid usage component definition under the specified product family.
-
#create_quantity_based_component(product_family_id, body: nil) ⇒ ComponentResponse
Creates a Quantity Based component definition under the specified product family.
-
#find_component(handle) ⇒ ComponentResponse
Returns information for a component matching the provided handle.
-
#list_components(options = {}) ⇒ Array[ComponentResponse]
Lists components for a site.
-
#list_components_for_product_family(options = {}) ⇒ Array[ComponentResponse]
Lists components for a particular product family.
-
#read_component(product_family_id, component_id) ⇒ ComponentResponse
Returns information regarding a component from a specific product family.
-
#update_component(component_id, body: nil) ⇒ ComponentResponse
Updates a component.
-
#update_product_family_component(product_family_id, component_id, body: nil) ⇒ ComponentResponse
Updates a component from a specific product family.
Methods inherited from BaseController
#initialize, #new_parameter, #new_request_builder, #new_response_handler, user_agent, user_agent_parameters
Constructor Details
This class inherits a constructor from AdvancedBilling::BaseController
Instance Method Details
#archive_component(product_family_id, component_id) ⇒ Component
Archives the component; all current subscribers will continue to be
charged as usual.
Billing id of the product family to which the component belongs
Billing id of the component or the handle for the component prefixed with
handle:
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
# File 'lib/advanced_billing/controllers/components_controller.rb', line 372 def archive_component(product_family_id, component_id) @api_call .request(new_request_builder(HttpMethodEnum::DELETE, '/product_families/{product_family_id}/components/{component_id}.json', Server::PRODUCTION) .template_param(new_parameter(product_family_id, key: 'product_family_id') .is_required(true) .should_encode(true)) .template_param(new_parameter(component_id, key: 'component_id') .is_required(true) .should_encode(true)) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('BasicAuth'))) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(Component.method(:from_hash)) .local_error_template('422', 'HTTP Response Not OK. Status code: {$statusCode}.'\ ' Response: \'{$response.body}\'.', ErrorListResponseException)) .execute end |
#create_event_based_component(product_family_id, body: nil) ⇒ ComponentResponse
Creates an event-based component definition under the specified product
family. An event-based component can then be added and “allocated” for a
subscription.
Event-based components are similar to other component types, in that you
define the component parameters (such as name and taxability) and the
pricing. A key difference for the event-based component is that it must be
attached to a metric. This is because the metric provides the component
with the actual quantity used in computing what and how much will be
billed each period for each subscription.
So, instead of reporting usage directly for each component (as you would
with metered components), the usage is derived from analysis of your
events.
For more information, see [Components
Overview](https://maxio.zendesk.com/hc/en-us/articles/24261141522189-Compo
nents-Overview).
If you have the new [Catalog
experience](page:help/announcements/2026-announcements#new-catalog-experie
nce-and-terminology) enabled, taxable components must include a non-blank
tax_code; sending a blank value results in a validation error.
family's id or its handle prefixed with handle:
description here
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/advanced_billing/controllers/components_controller.rb', line 244 def create_event_based_component(product_family_id, body: nil) @api_call .request(new_request_builder(HttpMethodEnum::POST, '/product_families/{product_family_id}/event_based_components.json', Server::PRODUCTION) .template_param(new_parameter(product_family_id, key: 'product_family_id') .is_required(true) .should_encode(true)) .header_param(new_parameter('application/json', key: 'Content-Type')) .body_param(new_parameter(body)) .header_param(new_parameter('application/json', key: 'accept')) .body_serializer(proc do |param| param.to_json unless param.nil? end) .auth(Single.new('BasicAuth'))) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(ComponentResponse.method(:from_hash)) .local_error_template('404', 'Not Found:\'{$response.body}\'', APIException) .local_error_template('422', 'HTTP Response Not OK. Status code: {$statusCode}.'\ ' Response: \'{$response.body}\'.', ErrorListResponseException)) .execute end |
#create_metered_component(product_family_id, body: nil) ⇒ ComponentResponse
Creates a metered component definition under the specified product family. A metered component can then be added and “allocated” for a subscription. Metered components are used to bill for any type of unit that resets to 0 at the end of the billing period (think daily Google Ads clicks or monthly cell phone minutes). This is most commonly associated with usage-based billing and many other pricing schemes. Note that this is different from recurring quantity-based components, which DO NOT reset to zero at the start of every billing period. If you want to bill for a quantity of something that does not change unless you change it, then you want quantity components, instead.
Hybrid Pricing
A volume, tiered, or stairstep metered component can combine its
primary pricing with a secondary pricing model (the overage_pricing
parameter) so both bill as a single invoice line item instead of two. This
does not apply to metered components configured for event-based billing
(metric, meter, or formula). See Hybrid
Pricing for requirements
and configuration details.
For more information on components, see our documentation
[here](https://maxio.zendesk.com/hc/en-us/articles/24261141522189-Componen
ts-Overview).
If you have the new [Catalog
experience](page:help/announcements/2026-announcements#new-catalog-experie
nce-and-terminology) enabled, taxable components must include a non-blank
tax_code. Sending "tax_code": "" returns 422.
family's id or its handle prefixed with handle:
description here
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/advanced_billing/controllers/components_controller.rb', line 39 def create_metered_component(product_family_id, body: nil) @api_call .request(new_request_builder(HttpMethodEnum::POST, '/product_families/{product_family_id}/metered_components.json', Server::PRODUCTION) .template_param(new_parameter(product_family_id, key: 'product_family_id') .is_required(true) .should_encode(true)) .header_param(new_parameter('application/json', key: 'Content-Type')) .body_param(new_parameter(body)) .header_param(new_parameter('application/json', key: 'accept')) .body_serializer(proc do |param| param.to_json unless param.nil? end) .auth(Single.new('BasicAuth'))) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(ComponentResponse.method(:from_hash)) .local_error_template('404', 'Not Found:\'{$response.body}\'', APIException) .local_error_template('422', 'HTTP Response Not OK. Status code: {$statusCode}.'\ ' Response: \'{$response.body}\'.', ErrorListResponseException)) .execute end |
#create_on_off_component(product_family_id, body: nil) ⇒ ComponentResponse
Creates an On/Off component definition under the specified product family.
An On/Off component can then be added and “allocated” for a subscription.
On/off components are used for any flat fee, recurring add on (think
$99/month for tech support or a flat add on shipping fee).
For more information on components, see our documentation
[here](https://maxio.zendesk.com/hc/en-us/articles/24261141522189-Componen
ts-Overview).
If you have the new [Catalog
experience](page:help/announcements/2026-announcements#new-catalog-experie
nce-and-terminology) enabled, taxable components must include a non-blank
tax_code. Sending "tax_code": "" returns 422.
family's id or its handle prefixed with handle:
description here
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/advanced_billing/controllers/components_controller.rb', line 145 def create_on_off_component(product_family_id, body: nil) @api_call .request(new_request_builder(HttpMethodEnum::POST, '/product_families/{product_family_id}/on_off_components.json', Server::PRODUCTION) .template_param(new_parameter(product_family_id, key: 'product_family_id') .is_required(true) .should_encode(true)) .header_param(new_parameter('application/json', key: 'Content-Type')) .body_param(new_parameter(body)) .header_param(new_parameter('application/json', key: 'accept')) .body_serializer(proc do |param| param.to_json unless param.nil? end) .auth(Single.new('BasicAuth'))) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(ComponentResponse.method(:from_hash)) .local_error_template('404', 'Not Found:\'{$response.body}\'', APIException) .local_error_template('422', 'HTTP Response Not OK. Status code: {$statusCode}.'\ ' Response: \'{$response.body}\'.', ErrorListResponseException)) .execute end |
#create_prepaid_usage_component(product_family_id, body: nil) ⇒ ComponentResponse
Creates a prepaid usage component definition under the specified product
family. A prepaid component can then be added and “allocated” for a
subscription.
Prepaid components allow customers to pre-purchase units that can be used
up over time on their subscription. In a sense, they are the mirror image
of metered components; while metered components charge at the end of the
period for the amount of units used, prepaid components are charged for at
the time of purchase, and usage is subsequently tracked against the amount
purchased.
For more information, see [Components
Overview](https://maxio.zendesk.com/hc/en-us/articles/24261141522189-Compo
nents-Overview).
If you have the new [Catalog
experience](page:help/announcements/2026-announcements#new-catalog-experie
nce-and-terminology) enabled, taxable components must include a non-blank
tax_code; sending a blank value results in a validation error.
family's id or its handle prefixed with handle:
description here
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/advanced_billing/controllers/components_controller.rb', line 193 def create_prepaid_usage_component(product_family_id, body: nil) @api_call .request(new_request_builder(HttpMethodEnum::POST, '/product_families/{product_family_id}/prepaid_usage_components.json', Server::PRODUCTION) .template_param(new_parameter(product_family_id, key: 'product_family_id') .is_required(true) .should_encode(true)) .header_param(new_parameter('application/json', key: 'Content-Type')) .body_param(new_parameter(body)) .header_param(new_parameter('application/json', key: 'accept')) .body_serializer(proc do |param| param.to_json unless param.nil? end) .auth(Single.new('BasicAuth'))) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(ComponentResponse.method(:from_hash)) .local_error_template('404', 'Not Found:\'{$response.body}\'', APIException) .local_error_template('422', 'HTTP Response Not OK. Status code: {$statusCode}.'\ ' Response: \'{$response.body}\'.', ErrorListResponseException)) .execute end |
#create_quantity_based_component(product_family_id, body: nil) ⇒ ComponentResponse
Creates a Quantity Based component definition under the specified product family. A Quantity Based component can then be added and “allocated” for a subscription. When defining a Quantity Based component, you can choose one of two types:
Recurring
Recurring quantity-based components are used to bill for the number of some unit (think monthly software user licenses or the number of pairs of socks in a box-a-month club). This is most commonly associated with billing for user licenses, number of users, number of employees, etc.
One-time
One-time quantity-based components are used to create ad hoc usage charges that do not recur. For example, at the time of signup, you might want to charge your customer a one-time fee for onboarding or other services. The allocated quantity for one-time quantity-based components immediately gets reset back to zero after the allocation is made. For more information, see [Components Overview](https://maxio.zendesk.com/hc/en-us/articles/24261141522189-Compo nents-Overview).
Hybrid Pricing
A volume, tiered, or stairstep component can combine its primary
pricing with a secondary pricing model (the overage_pricing parameter)
so both bill as a single invoice line item instead of two. See Hybrid
Pricing for requirements
and configuration details.
For more information on components, see our documentation
[here](https://maxio.zendesk.com/hc/en-us/articles/24261141522189-Componen
ts-Overview).
If you have the new [Catalog
experience](page:help/announcements/2026-announcements#new-catalog-experie
nce-and-terminology) enabled, taxable components must include a non-blank
tax_code. Sending "tax_code": "" returns 422.
family's id or its handle prefixed with handle:
description here
102 103 104 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/advanced_billing/controllers/components_controller.rb', line 102 def create_quantity_based_component(product_family_id, body: nil) @api_call .request(new_request_builder(HttpMethodEnum::POST, '/product_families/{product_family_id}/quantity_based_components.json', Server::PRODUCTION) .template_param(new_parameter(product_family_id, key: 'product_family_id') .is_required(true) .should_encode(true)) .header_param(new_parameter('application/json', key: 'Content-Type')) .body_param(new_parameter(body)) .header_param(new_parameter('application/json', key: 'accept')) .body_serializer(proc do |param| param.to_json unless param.nil? end) .auth(Single.new('BasicAuth'))) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(ComponentResponse.method(:from_hash)) .local_error_template('404', 'Not Found:\'{$response.body}\'', APIException) .local_error_template('422', 'HTTP Response Not OK. Status code: {$statusCode}.'\ ' Response: \'{$response.body}\'.', ErrorListResponseException)) .execute end |
#find_component(handle) ⇒ ComponentResponse
Returns information for a component matching the provided handle. You can identify your components with a handle so you don't have to save or reference the IDs we generate. find
277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/advanced_billing/controllers/components_controller.rb', line 277 def find_component(handle) @api_call .request(new_request_builder(HttpMethodEnum::GET, '/components/lookup.json', Server::PRODUCTION) .query_param(new_parameter(handle, key: 'handle') .is_required(true)) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('BasicAuth'))) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(ComponentResponse.method(:from_hash))) .execute end |
#list_components(options = {}) ⇒ Array[ComponentResponse]
Lists components for a site.
you would like to apply to your search.
YYYY-MM-DD) with which to filter the date_field. Returns components with a
timestamp at or after midnight (12:00:00 AM) in your site’s time zone on
the date specified.
YYYY-MM-DD) with which to filter the date_field. Returns components with a
timestamp up to and including 11:59:59PM in your site’s time zone on the
date specified.
(format YYYY-MM-DD HH:MM:SS) with which to filter the date_field. Returns
components with a timestamp at or after exact time provided in query. You
can specify timezone in query - otherwise your site's time zone will be
used. If provided, this parameter will be used instead of start_date.
(format YYYY-MM-DD HH:MM:SS) with which to filter the date_field. Returns
components with a timestamp at or before exact time provided in query. You
can specify timezone in query - otherwise your site's time zone will be
used. If provided, this parameter will be used instead of end_date.
Include archived items.
pages. By default, the first page of results is displayed. The page
parameter specifies a page number of results to fetch. You can start
navigating through the pages to consume the results. You do this by
passing in a page parameter. Retrieve the next page by adding ?page=2 to
the query string. If there are no results to return, then an empty result
set will be returned. Use in query page=1.
many records to fetch in each request. Default value is 20. The maximum
allowed values is 200; any per_page value over 200 will be changed to 200.
Use in query per_page=200.
List Components operations
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 |
# File 'lib/advanced_billing/controllers/components_controller.rb', line 433 def list_components( = {}) @api_call .request(new_request_builder(HttpMethodEnum::GET, '/components.json', Server::PRODUCTION) .query_param(new_parameter(['date_field'], key: 'date_field')) .query_param(new_parameter(['start_date'], key: 'start_date')) .query_param(new_parameter(['end_date'], key: 'end_date')) .query_param(new_parameter(['start_datetime'], key: 'start_datetime')) .query_param(new_parameter(['end_datetime'], key: 'end_datetime')) .query_param(new_parameter(['include_archived'], key: 'include_archived')) .query_param(new_parameter(['page'], key: 'page')) .query_param(new_parameter(['per_page'], key: 'per_page')) .query_param(new_parameter(['filter'], key: 'filter')) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('BasicAuth')) .array_serialization_format(ArraySerializationFormat::CSV)) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(ComponentResponse.method(:from_hash)) .is_response_array(true)) .execute end |
#list_components_for_product_family(options = {}) ⇒ Array[ComponentResponse]
Lists components for a particular product family.
Billing id of the product family
Include archived items.
pages. By default, the first page of results is displayed. The page
parameter specifies a page number of results to fetch. You can start
navigating through the pages to consume the results. You do this by
passing in a page parameter. Retrieve the next page by adding ?page=2 to
the query string. If there are no results to return, then an empty result
set will be returned. Use in query page=1.
many records to fetch in each request. Default value is 20. The maximum
allowed values is 200; any per_page value over 200 will be changed to 200.
Use in query per_page=200.
List Components operations
you would like to apply to your search. Use in query
date_field=created_at.
YYYY-MM-DD) with which to filter the date_field. Returns components with a
timestamp up to and including 11:59:59PM in your site’s time zone on the
date specified.
(format YYYY-MM-DD HH:MM:SS) with which to filter the date_field. Returns
components with a timestamp at or before exact time provided in query. You
can specify timezone in query - otherwise your site's time zone will be
used. If provided, this parameter will be used instead of end_date.
YYYY-MM-DD) with which to filter the date_field. Returns components with a
timestamp at or after midnight (12:00:00 AM) in your site’s time zone on
the date specified.
(format YYYY-MM-DD HH:MM:SS) with which to filter the date_field. Returns
components with a timestamp at or after exact time provided in query. You
can specify timezone in query - otherwise your site's time zone will be
used. If provided, this parameter will be used instead of start_date.
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 |
# File 'lib/advanced_billing/controllers/components_controller.rb', line 533 def list_components_for_product_family( = {}) @api_call .request(new_request_builder(HttpMethodEnum::GET, '/product_families/{product_family_id}/components.json', Server::PRODUCTION) .template_param(new_parameter(['product_family_id'], key: 'product_family_id') .is_required(true) .should_encode(true)) .query_param(new_parameter(['include_archived'], key: 'include_archived')) .query_param(new_parameter(['page'], key: 'page')) .query_param(new_parameter(['per_page'], key: 'per_page')) .query_param(new_parameter(['filter'], key: 'filter')) .query_param(new_parameter(['date_field'], key: 'date_field')) .query_param(new_parameter(['end_date'], key: 'end_date')) .query_param(new_parameter(['end_datetime'], key: 'end_datetime')) .query_param(new_parameter(['start_date'], key: 'start_date')) .query_param(new_parameter(['start_datetime'], key: 'start_datetime')) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('BasicAuth')) .array_serialization_format(ArraySerializationFormat::CSV)) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(ComponentResponse.method(:from_hash)) .is_response_array(true)) .execute end |
#read_component(product_family_id, component_id) ⇒ ComponentResponse
Returns information regarding a component from a specific product family.
You can read the component by either the component's id or handle. When
using the handle, it must be prefixed with handle:.
Billing id of the product family to which the component belongs
Billing id of the component or the handle for the component prefixed with
handle:
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
# File 'lib/advanced_billing/controllers/components_controller.rb', line 301 def read_component(product_family_id, component_id) @api_call .request(new_request_builder(HttpMethodEnum::GET, '/product_families/{product_family_id}/components/{component_id}.json', Server::PRODUCTION) .template_param(new_parameter(product_family_id, key: 'product_family_id') .is_required(true) .should_encode(true)) .template_param(new_parameter(component_id, key: 'component_id') .is_required(true) .should_encode(true)) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('BasicAuth'))) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(ComponentResponse.method(:from_hash))) .execute end |
#update_component(component_id, body: nil) ⇒ ComponentResponse
Updates a component.
You may read the component by either the component's id or handle. When
using the handle, it must be prefixed with handle:.
If you have the new [Catalog
experience](page:help/announcements/2026-announcements#new-catalog-experie
nce-and-terminology) enabled, taxable components must include a non-blank
tax_code. Sending "tax_code": "" returns 422.
component
description here
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 |
# File 'lib/advanced_billing/controllers/components_controller.rb', line 469 def update_component(component_id, body: nil) @api_call .request(new_request_builder(HttpMethodEnum::PUT, '/components/{component_id}.json', Server::PRODUCTION) .template_param(new_parameter(component_id, key: 'component_id') .is_required(true) .should_encode(true)) .header_param(new_parameter('application/json', key: 'Content-Type')) .body_param(new_parameter(body)) .header_param(new_parameter('application/json', key: 'accept')) .body_serializer(proc do |param| param.to_json unless param.nil? end) .auth(Single.new('BasicAuth'))) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(ComponentResponse.method(:from_hash)) .local_error_template('422', 'HTTP Response Not OK. Status code: {$statusCode}.'\ ' Response: \'{$response.body}\'.', ErrorListResponseException)) .execute end |
#update_product_family_component(product_family_id, component_id, body: nil) ⇒ ComponentResponse
Updates a component from a specific product family.
You may read the component by either the component's id or handle. When
using the handle, it must be prefixed with handle:.
If you have the new [Catalog
experience](page:help/announcements/2026-announcements#new-catalog-experie
nce-and-terminology) enabled, taxable components must include a non-blank
tax_code. Sending "tax_code": "" returns 422.
Billing id of the product family to which the component belongs
Billing id of the component or the handle for the component prefixed with
handle:
description here
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
# File 'lib/advanced_billing/controllers/components_controller.rb', line 336 def update_product_family_component(product_family_id, component_id, body: nil) @api_call .request(new_request_builder(HttpMethodEnum::PUT, '/product_families/{product_family_id}/components/{component_id}.json', Server::PRODUCTION) .template_param(new_parameter(product_family_id, key: 'product_family_id') .is_required(true) .should_encode(true)) .template_param(new_parameter(component_id, key: 'component_id') .is_required(true) .should_encode(true)) .header_param(new_parameter('application/json', key: 'Content-Type')) .body_param(new_parameter(body)) .header_param(new_parameter('application/json', key: 'accept')) .body_serializer(proc do |param| param.to_json unless param.nil? end) .auth(Single.new('BasicAuth'))) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(ComponentResponse.method(:from_hash)) .local_error_template('422', 'HTTP Response Not OK. Status code: {$statusCode}.'\ ' Response: \'{$response.body}\'.', ErrorListResponseException)) .execute end |