Class: AdvancedBilling::OffersController

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

Overview

OffersController

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_offer(offer_id) ⇒ void

This method returns an undefined value.

Archives an existing offer. Please provide an offer_id in order to archive the correct item. offer

Parameters:

  • offer_id (Integer)

    Required parameter: The Chargify id of the



107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/advanced_billing/controllers/offers_controller.rb', line 107

def archive_offer(offer_id)
  @api_call
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/offers/{offer_id}/archive.json',
                                 Server::PRODUCTION)
               .template_param(new_parameter(offer_id, key: 'offer_id')
                                .is_required(true)
                                .should_encode(true))
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .is_response_void(true))
    .execute
end

#create_offer(body: nil) ⇒ OfferResponse

Creates an offer within your site. Offers allow you to package complicated combinations of products, components and coupons into a convenient package which can then be subscribed to just like products. Once an offer is defined it can be used as an alternative to the product when creating subscriptions. For more information, see [Offers](https://maxio.zendesk.com/hc/en-us/articles/24261295098637-Offers -Overview) in the product documentation.

Using a Product Price Point

You can optionally pass in a product_price_point_id that corresponds with the product_id and the offer will use that price point. If a product_price_point_id is not passed in, the product's default price point will be used. description here

Parameters:

Returns:



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/advanced_billing/controllers/offers_controller.rb', line 26

def create_offer(body: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/offers.json',
                                 Server::PRODUCTION)
               .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(OfferResponse.method(:from_hash))
                .local_error_template('422',
                                      'HTTP Response Not OK. Status code: {$statusCode}.'\
                                       ' Response: \'{$response.body}\'.',
                                      ErrorArrayMapResponseException))
    .execute
end

#list_offers(options = {}) ⇒ ListOffersResponse

Lists offers for a site. 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.

Parameters:

  • page (Integer)

    Optional parameter: Result records are organized in

  • per_page (Integer)

    Optional parameter: This parameter indicates how

  • include_archived (TrueClass | FalseClass)

    Optional parameter:

Returns:



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/advanced_billing/controllers/offers_controller.rb', line 61

def list_offers(options = {})
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/offers.json',
                                 Server::PRODUCTION)
               .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'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(ListOffersResponse.method(:from_hash))
                .local_error_template('422',
                                      'HTTP Response Not OK. Status code: {$statusCode}.'\
                                       ' Response: \'{$response.body}\'.',
                                      ErrorListResponseException))
    .execute
end

#read_offer(offer_id) ⇒ OfferResponse

Returns a specific offer's attributes. This is different from listing all offers for a site, as it requires an offer_id. offer

Parameters:

  • offer_id (Integer)

    Required parameter: The Chargify id of the

Returns:



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/advanced_billing/controllers/offers_controller.rb', line 86

def read_offer(offer_id)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/offers/{offer_id}.json',
                                 Server::PRODUCTION)
               .template_param(new_parameter(offer_id, key: 'offer_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(OfferResponse.method(:from_hash)))
    .execute
end

#unarchive_offer(offer_id) ⇒ void

This method returns an undefined value.

Unarchives a previously archived offer. Please provide an offer_id in order to unarchive the correct item. offer

Parameters:

  • offer_id (Integer)

    Required parameter: The Chargify id of the



126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/advanced_billing/controllers/offers_controller.rb', line 126

def unarchive_offer(offer_id)
  @api_call
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/offers/{offer_id}/unarchive.json',
                                 Server::PRODUCTION)
               .template_param(new_parameter(offer_id, key: 'offer_id')
                                .is_required(true)
                                .should_encode(true))
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .is_response_void(true))
    .execute
end