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. product



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/advanced_billing/controllers/products_controller.rb', line 17

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
                .is_nullify404(true)
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(ProductResponse.method(:from_hash)))
    .execute
end

#create_product(product_family_id, body: nil) ⇒ ProductResponse

Use this method to create a product within your Chargify site. + [Products Documentation](maxio-chargify.zendesk.com/hc/en-us/articles/540556 1405709) + [Changing a Subscription’s Product](maxio-chargify.zendesk.com/hc/en-us/articles/540422533466 9-Product-Changes-Migrations) the product family to which the product belongs



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/products_controller.rb', line 45

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
                .is_nullify404(true)
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(ProductResponse.method(:from_hash)))
    .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`. 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. (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`. filter_prepaid_product_price_point_product_price_point_id Optional parameter: Allows fetching products only if a prepaid product price point is present or not. To use this filter you also have to include the following param in the request `include=prepaid_product_price_point`. Use in query `filter[product_price_point_id]=not_null`. parameter: Allows fetching products with matching use_site_exchange_rate based on provided value (refers to default price point). Use in query `filter=true`.



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/products_controller.rb', line 194

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['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'))
               .query_param(new_parameter(options['filter_prepaid_product_price_point_product_price_point_id'], key: 'filter[prepaid_product_price_point][product_price_point_id]'))
               .query_param(new_parameter(options['filter_use_site_exchange_rate'], key: 'filter[use_site_exchange_rate]'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .is_nullify404(true)
                .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 Chargify. product



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/advanced_billing/controllers/products_controller.rb', line 71

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
                .is_nullify404(true)
                .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`.



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/advanced_billing/controllers/products_controller.rb', line 127

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
                .is_nullify404(true)
                .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. product



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/advanced_billing/controllers/products_controller.rb', line 100

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
                .is_nullify404(true)
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(ProductResponse.method(:from_hash))
                .local_error('422',
                             'Unprocessable Entity (WebDAV)',
                             ErrorListResponseException))
    .execute
end