Class: AdvancedBilling::ProductsController

Inherits:
BaseController show all
Defined in:
lib/advanced_billing/controllers/products_controller.rb

Overview

ProductsController

Constant Summary

Constants inherited from BaseController

BaseController::GLOBAL_ERRORS

Instance Attribute Summary

Attributes inherited from BaseController

#config, #http_call_back

Instance Method Summary collapse

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_product(product_id) ⇒ ProductResponse

Archives the product. All current subscribers will be unaffected; their subscription/purchase will continue to be charged monthly. This will restrict the option to chose the product for purchase via the Billing Portal, as well as disable Public Signup Pages for the product. the product

Parameters:

  • product_id (Integer)

    Required parameter: The Advanced Billing id of

Returns:



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/advanced_billing/controllers/products_controller.rb', line 115

def archive_product(product_id)
  @api_call
    .request(new_request_builder(HttpMethodEnum::DELETE,
                                 '/products/{product_id}.json',
                                 Server::PRODUCTION)
               .template_param(new_parameter(product_id, key: 'product_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(ProductResponse.method(:from_hash))
                .local_error_template('422',
                                      'HTTP Response Not OK. Status code: {$statusCode}.'\
                                       ' Response: \'{$response.body}\'.',
                                      ErrorListResponseException))
    .execute
end

#create_product(product_family_id, body: nil) ⇒ ProductResponse

Creates a product in your site. If you have the new [Catalog experience](page:help/announcements/2026-announcements#new-catalog-experie nce-and-terminology) enabled, the auto_create_signup_page parameter is not supported. If auto_create_signup_page is included (with any value) an error is returned. For more information, see:

Parameters:

  • product_family_id (String)

    Required parameter: Either the product

  • body (CreateOrUpdateProductRequest) (defaults to: nil)

    Optional parameter: TODO: type

Returns:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/advanced_billing/controllers/products_controller.rb', line 27

def create_product(product_family_id,
                   body: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/product_families/{product_family_id}/products.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(ProductResponse.method(:from_hash))
                .local_error_template('422',
                                      'HTTP Response Not OK. Status code: {$statusCode}.'\
                                       ' Response: \'{$response.body}\'.',
                                      ErrorListResponseException))
    .execute
end

#list_products(options = {}) ⇒ Array[ProductResponse]

Lists products belonging to a site. you would like to apply to your search. Use in query: date_field=created_at. List Products operations YYYY-MM-DD) with which to filter the date_field. Returns products 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 products 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 products with a timestamp at or after midnight (12:00:00 AM) in your site’s time zone on the date specified. time (format YYYY-MM-DD HH:MM:SS) with which to filter the date_field. Returns products 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. 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. Include archived products. Use in query: include_archived=true. additional data in the response. Use in query include=prepaid_product_price_point.

Parameters:

  • date_field (BasicDateField)

    Optional parameter: The type of filter

  • filter (ListProductsFilter)

    Optional parameter: Filter to use for

  • end_date (Date)

    Optional parameter: The end date (format

  • end_datetime (DateTime)

    Optional parameter: The end date and time

  • start_date (Date)

    Optional parameter: The start date (format

  • start_datetime (DateTime)

    Optional parameter: The start date and

  • page (Integer)

    Optional parameter: Result records are organized in

  • per_page (Integer)

    Optional parameter: This parameter indicates how

  • include_archived (TrueClass | FalseClass)

    Optional parameter:

  • include (ListProductsInclude)

    Optional parameter: Allows including

Returns:



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/advanced_billing/controllers/products_controller.rb', line 196

def list_products(options = {})
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/products.json',
                                 Server::PRODUCTION)
               .query_param(new_parameter(options['date_field'], key: 'date_field'))
               .query_param(new_parameter(options['filter'], key: 'filter'))
               .query_param(new_parameter(options['end_date'], key: 'end_date'))
               .query_param(new_parameter(options['end_datetime'], key: 'end_datetime'))
               .query_param(new_parameter(options['start_date'], key: 'start_date'))
               .query_param(new_parameter(options['start_datetime'], key: 'start_datetime'))
               .query_param(new_parameter(options['page'], key: 'page'))
               .query_param(new_parameter(options['per_page'], key: 'per_page'))
               .query_param(new_parameter(options['include_archived'], key: 'include_archived'))
               .query_param(new_parameter(options['include'], key: 'include'))
               .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(ProductResponse.method(:from_hash))
                .is_response_array(true))
    .execute
end

#read_product(product_id) ⇒ ProductResponse

Reads the current details of a product. the product

Parameters:

  • product_id (Integer)

    Required parameter: The Advanced Billing id of

Returns:



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/advanced_billing/controllers/products_controller.rb', line 55

def read_product(product_id)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/products/{product_id}.json',
                                 Server::PRODUCTION)
               .template_param(new_parameter(product_id, key: 'product_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(ProductResponse.method(:from_hash)))
    .execute
end

#read_product_by_handle(api_handle) ⇒ ProductResponse

Retrieves a Product object by its api_handle.

Parameters:

  • api_handle (String)

    Required parameter: The handle of the product

Returns:



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/advanced_billing/controllers/products_controller.rb', line 138

def read_product_by_handle(api_handle)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/products/handle/{api_handle}.json',
                                 Server::PRODUCTION)
               .template_param(new_parameter(api_handle, key: 'api_handle')
                                .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(ProductResponse.method(:from_hash)))
    .execute
end

#update_product(product_id, body: nil) ⇒ ProductResponse

Updates aspects of an existing product.

Input Attributes Update Notes

  • update_return_params The parameters we will append to your update_return_url. See Return URLs and Parameters

Product Price Point

Updating a product using this endpoint will create a new price point and set it as the default price point for this product. If you should like to update an existing product price point, that must be done separately. the product description here

Parameters:

  • product_id (Integer)

    Required parameter: The Advanced Billing id of

  • body (CreateOrUpdateProductRequest) (defaults to: nil)

    Optional parameter: TODO: type

Returns:



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

def update_product(product_id,
                   body: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/products/{product_id}.json',
                                 Server::PRODUCTION)
               .template_param(new_parameter(product_id, key: 'product_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(ProductResponse.method(:from_hash))
                .local_error_template('422',
                                      'HTTP Response Not OK. Status code: {$statusCode}.'\
                                       ' Response: \'{$response.body}\'.',
                                      ErrorListResponseException))
    .execute
end