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

This method returns an undefined value.

Archive 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



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

def archive_offer(offer_id)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/offers/{offer_id}/archive.json',
                                 Server::DEFAULT)
               .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

Create an offer within your Advanced Billing site by sending a POST request. ## Documentation 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. Full documentation on how to use offers in the Advanced Billing UI can be located [here](maxio.zendesk.com/hc/en-us/articles/24261295098637-Offers-O verview). ## 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.

Parameters:

Returns:



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

def create_offer(body: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/offers.json',
                                 Server::DEFAULT)
               .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

This endpoint will list 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:



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

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

#read_offer(offer_id) ⇒ OfferResponse

This method allows you to list a specific offer’s attributes. This is different than list all offers for a site, as it requires an ‘offer_id`. offer

Parameters:

  • offer_id (Integer)

    Required parameter: The Chargify id of the

Returns:



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

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

Unarchive a previously archived offer. Please provide an ‘offer_id` in order to un-archive the correct item. offer

Parameters:

  • offer_id (Integer)

    Required parameter: The Chargify id of the



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

def unarchive_offer(offer_id)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/offers/{offer_id}/unarchive.json',
                                 Server::DEFAULT)
               .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