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_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

#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 subcription 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.

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/reason_codes_controller.rb', line 26

def create_reason_code(body: nil)
  new_api_call_builder
    .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 reversable. id of the reason code

Parameters:

  • reason_code_id (Integer)

    Required parameter: The Advanced Billing

Returns:



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

def delete_reason_code(reason_code_id)
  new_api_call_builder
    .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`.

Parameters:

  • page (Integer)

    Optional parameter: Result records are organized in

  • per_page (Integer)

    Optional parameter: This parameter indicates how

Returns:



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

def list_reason_codes(options = {})
  new_api_call_builder
    .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

Parameters:

  • reason_code_id (Integer)

    Required parameter: The Advanced Billing

Returns:



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

def read_reason_code(reason_code_id)
  new_api_call_builder
    .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

Parameters:

  • reason_code_id (Integer)

    Required parameter: The Advanced Billing

  • body (UpdateReasonCodeRequest) (defaults to: nil)

    Optional parameter: Example:

Returns:



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

def update_reason_code(reason_code_id,
                       body: nil)
  new_api_call_builder
    .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