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_api_call_builder, #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

Sending a DELETE request to this endpoint will archive the product. All current subscribers will be unffected; 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:



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/advanced_billing/controllers/products_controller.rb', line 109

def archive_product(product_id)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::DELETE,
                                 '/products/{product_id}.json',
                                 Server::DEFAULT)
               .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

Use this method to create a product within your Advanced Billing site. + [Products Documentation](maxio.zendesk.com/hc/en-us/articles/24261090117645- Products-Overview) + [Changing a Subscription’s Product](maxio.zendesk.com/hc/en-us/articles/24252069837581-Produc t-Changes-and-Migrations) family’s id or its handle prefixed with ‘handle:`

Parameters:

  • product_family_id (String)

    Required parameter: Either the product

  • body (CreateOrUpdateProductRequest) (defaults to: nil)

    Optional parameter: Example:

Returns:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/advanced_billing/controllers/products_controller.rb', line 20

def create_product(product_family_id,
                   body: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/product_families/{product_family_id}/products.json',
                                 Server::DEFAULT)
               .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]

This method allows to retrieve a list of 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:



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/advanced_billing/controllers/products_controller.rb', line 190

def list_products(options = {})
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/products.json',
                                 Server::DEFAULT)
               .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

This endpoint allows you to read the current details of a product that you’ve created in Advanced Billing. the product

Parameters:

  • product_id (Integer)

    Required parameter: The Advanced Billing id of

Returns:



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/advanced_billing/controllers/products_controller.rb', line 49

def read_product(product_id)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/products/{product_id}.json',
                                 Server::DEFAULT)
               .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

This method allows to retrieve a Product object by its ‘api_handle`.

Parameters:

  • api_handle (String)

    Required parameter: The handle of the product

Returns:



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/advanced_billing/controllers/products_controller.rb', line 132

def read_product_by_handle(api_handle)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/products/handle/{api_handle}.json',
                                 Server::DEFAULT)
               .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

Use this method to change 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

Parameters:

  • product_id (Integer)

    Required parameter: The Advanced Billing id of

  • body (CreateOrUpdateProductRequest) (defaults to: nil)

    Optional parameter: Example:

Returns:



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/advanced_billing/controllers/products_controller.rb', line 77

def update_product(product_id,
                   body: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/products/{product_id}.json',
                                 Server::DEFAULT)
               .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