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:`
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
# File 'lib/advanced_billing/controllers/components_controller.rb', line 331 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 on components, see our documentation [here](maxio.zendesk.com/hc/en-us/articles/24261141522189-Componen ts-Overview). family’s id or its handle prefixed with ‘handle:` description here
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/advanced_billing/controllers/components_controller.rb', line 207 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. For more information on components, see our documentation [here](maxio.zendesk.com/hc/en-us/articles/24261141522189-Componen ts-Overview). family’s id or its handle prefixed with ‘handle:` description here
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/advanced_billing/controllers/components_controller.rb', line 27 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](maxio.zendesk.com/hc/en-us/articles/24261141522189-Componen ts-Overview). family’s id or its handle prefixed with ‘handle:` description here
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/advanced_billing/controllers/components_controller.rb', line 116 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 we subsequently keep track of the usage against the amount purchased. For more information on components, see our documentation [here](maxio.zendesk.com/hc/en-us/articles/24261141522189-Componen ts-Overview). family’s id or its handle prefixed with ‘handle:` description here
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/advanced_billing/controllers/components_controller.rb', line 160 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 2 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 on components, see our documentation [here](maxio.zendesk.com/hc/en-us/articles/24261141522189-Componen ts-Overview). family’s id or its handle prefixed with ‘handle:` description here
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/advanced_billing/controllers/components_controller.rb', line 77 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
240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/advanced_billing/controllers/components_controller.rb', line 240 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. optional 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
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
# File 'lib/advanced_billing/controllers/components_controller.rb', line 393 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. optional. 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.
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 |
# File 'lib/advanced_billing/controllers/components_controller.rb', line 490 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:`
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/advanced_billing/controllers/components_controller.rb', line 264 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:`. component description here
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 |
# File 'lib/advanced_billing/controllers/components_controller.rb', line 425 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:`. 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
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/advanced_billing/controllers/components_controller.rb', line 295 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 |