Class: AdvancedBilling::ReasonCodesController

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

Overview

ReasonCodesController

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

#create_reason_code(body: nil) ⇒ ReasonCodeResponse

# Reason Codes Intro ReasonCodes are a way to gain a high level view of why your customers are cancelling the subscription to your product or service. Add a set of churn reason codes to be displayed in-app and/or the Maxio Billing Portal. As your subscribers decide to cancel their subscription, learn why they decided to cancel. ## Reason Code Documentation Full documentation on how Reason Codes operate within Advanced Billing can be located under the following links. [Churn Reason Codes](maxio.zendesk.com/hc/en-us/articles/24286647554701-Churn-Re ason-Codes) ## Create Reason Code This method gives a merchant the option to create a reason codes for a given Site. description here



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

def create_reason_code(body: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/reason_codes.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(ReasonCodeResponse.method(:from_hash))
                .local_error_template('422',
                                      'HTTP Response Not OK. Status code: {$statusCode}.'\
                                       ' Response: \'{$response.body}\'.',
                                      ErrorListResponseException))
    .execute
end

#delete_reason_code(reason_code_id) ⇒ OkResponse

This method gives a merchant the option to delete one reason code from the Churn Reason Codes. This code will be immediately removed. This action is not reversible. id of the reason code



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/advanced_billing/controllers/reason_codes_controller.rb', line 145

def delete_reason_code(reason_code_id)
  @api_call
    .request(new_request_builder(HttpMethodEnum::DELETE,
                                 '/reason_codes/{reason_code_id}.json',
                                 Server::PRODUCTION)
               .template_param(new_parameter(reason_code_id, key: 'reason_code_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(OkResponse.method(:from_hash))
                .local_error_template('404',
                                      'Not Found:\'{$response.body}\'',
                                      APIException))
    .execute
end

#list_reason_codes(options = {}) ⇒ Array[ReasonCodeResponse]

This method gives a merchant the option to retrieve a list of all of the current churn codes for a given 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`.



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

def list_reason_codes(options = {})
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/reason_codes.json',
                                 Server::PRODUCTION)
               .query_param(new_parameter(options['page'], key: 'page'))
               .query_param(new_parameter(options['per_page'], key: 'per_page'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(ReasonCodeResponse.method(:from_hash))
                .is_response_array(true)
                .local_error_template('422',
                                      'HTTP Response Not OK. Status code: {$statusCode}.'\
                                       ' Response: \'{$response.body}\'.',
                                      ErrorListResponseException))
    .execute
end

#read_reason_code(reason_code_id) ⇒ ReasonCodeResponse

This method gives a merchant the option to retrieve a list of a particular code for a given Site by providing the unique numerical ID of the code. id of the reason code



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

def read_reason_code(reason_code_id)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/reason_codes/{reason_code_id}.json',
                                 Server::PRODUCTION)
               .template_param(new_parameter(reason_code_id, key: 'reason_code_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(ReasonCodeResponse.method(:from_hash))
                .local_error_template('404',
                                      'Not Found:\'{$response.body}\'',
                                      APIException))
    .execute
end

#update_reason_code(reason_code_id, body: nil) ⇒ ReasonCodeResponse

This method gives a merchant the option to update an existing reason code for a given site. id of the reason code description here



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/advanced_billing/controllers/reason_codes_controller.rb', line 112

def update_reason_code(reason_code_id,
                       body: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/reason_codes/{reason_code_id}.json',
                                 Server::PRODUCTION)
               .template_param(new_parameter(reason_code_id, key: 'reason_code_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(ReasonCodeResponse.method(:from_hash))
                .local_error_template('404',
                                      'Not Found:\'{$response.body}\'',
                                      APIException)
                .local_error_template('422',
                                      'HTTP Response Not OK. Status code: {$statusCode}.'\
                                       ' Response: \'{$response.body}\'.',
                                      ErrorListResponseException))
    .execute
end