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.

Archive an existing offer. Please provide an ‘offer_id` in order to archive the correct item. offer



110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/advanced_billing/controllers/offers_controller.rb', line 110

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

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. description here



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

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

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



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

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

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



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

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.

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



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

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