Class: AdvancedBilling::CustomersController

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

Overview

CustomersController

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_customer(body: nil) ⇒ CustomerResponse

Creates a new customer; can also be created alongside a new subscription. The only validation restriction is that you can only create one customer for a given reference value. If provided, the reference value must be unique. It represents a unique identifier for the customer from your own app, i.e. the customer’s ID. This allows you to retrieve a given customer via a piece of shared information. Alternatively, you can choose to leave reference blank, and store the system-assigned unique ID for the customer, which is in the id attribute. For more information, see [Customer Details](https://maxio.zendesk.com/hc/en-us/articles/24252190590093-Custom er-Details).

Required Country Format

Format the country attribute of the customer using the ISO Standard Country codes. Countries should be formatted as two characters. For more information, see ISO 3166-1.

Required State Format

Format the state attribute of the customer using the ISO Standard State codes.

  • US States (two characters): see ISO 3166-2.
  • States Outside the US (two to three characters): To find the correct state codes outside the US, go to ISO 3166-1 and click on the link in the “ISO 3166-2 codes” column next to the country you wish to populate.

Locale

You can attribute a language/region to the customer to deliver invoices in any required language. For more information, see [Customer Locale](https://maxio.zendesk.com/hc/en-us/articles/24286672013709-Custome r-Locale). description here

Parameters:

Returns:



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/advanced_billing/controllers/customers_controller.rb', line 44

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

#delete_customer(id) ⇒ void

This method returns an undefined value.

Deletes the customer. customer

Parameters:

  • id (Integer)

    Required parameter: The Advanced Billing id of the



196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/advanced_billing/controllers/customers_controller.rb', line 196

def delete_customer(id)
  @api_call
    .request(new_request_builder(HttpMethodEnum::DELETE,
                                 '/customers/{id}.json',
                                 Server::PRODUCTION)
               .template_param(new_parameter(id, key: 'id')
                                .is_required(true)
                                .should_encode(true))
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .is_response_void(true))
    .execute
end

#list_customer_subscriptions(customer_id) ⇒ Array[SubscriptionResponse]

Lists all subscriptions that belong to a customer. If you have the new [Catalog experience](page:help/announcements/2026-announcements#new-catalog-experie nce-and-terminology) enabled, subscriptions no longer require an associated product. For subscriptions without an associated product, 'product', 'product_price_point_id', and 'product_price_point_type' are returned as 'null'. customer

Parameters:

  • customer_id (Integer)

    Required parameter: The Chargify id of the

Returns:



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/advanced_billing/controllers/customers_controller.rb', line 239

def list_customer_subscriptions(customer_id)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/customers/{customer_id}/subscriptions.json',
                                 Server::PRODUCTION)
               .template_param(new_parameter(customer_id, key: 'customer_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(SubscriptionResponse.method(:from_hash))
                .is_response_array(true))
    .execute
end

#list_customers(options = {}) ⇒ Array[CustomerResponse]

Lists all customers associated with your site, or filters results using the search parameter.

Find Customer

Use the search feature with the q query parameter to retrieve an array of customers that matches the search query. Common use cases are:

  • Search by an email
  • Search by an Advanced Billing ID
  • Search by an organization
  • Search by a reference value from your application
  • Search by a first or last name To retrieve a single, exact match by reference, use the [lookup endpoint](https://developers.chargify.com/docs/api-docs/b710d8fbef104-read -customer-by-reference). customers by time of creation 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 50. The maximum allowed values is 200; any per_page value over 200 will be changed to 200. Use in query per_page=200. you would like to apply to your search. Use in query: date_field=created_at. YYYY-MM-DD) with which to filter the date_field. Returns subscriptions with a timestamp at or after midnight (12:00:00 AM) in your site’s time zone on the date specified. YYYY-MM-DD) with which to filter the date_field. Returns subscriptions with a timestamp up to and including 11:59:59PM in your site’s time zone on the date specified. (format YYYY-MM-DD HH:MM:SS) with which to filter the date_field. Returns subscriptions with a timestamp at or after exact time provided in query. You can specify timezone in query - otherwise your site's time zone will be used. If provided, this parameter will be used instead of start_date. (format YYYY-MM-DD HH:MM:SS) with which to filter the date_field. Returns subscriptions with a timestamp at or before exact time provided in query. You can specify timezone in query - otherwise your site's time zone will be used. If provided, this parameter will be used instead of end_date. customers (can be an email, an ID, a reference, organization)

Parameters:

  • direction (SortingDirection)

    Optional parameter: Direction to sort

  • page (Integer)

    Optional parameter: Result records are organized in

  • per_page (Integer)

    Optional parameter: This parameter indicates how

  • date_field (BasicDateField)

    Optional parameter: The type of filter

  • start_date (String)

    Optional parameter: The start date (format

  • end_date (String)

    Optional parameter: The end date (format

  • start_datetime (String)

    Optional parameter: The start date and time

  • end_datetime (String)

    Optional parameter: The end date and time

  • q (String)

    Optional parameter: A search query by which to filter

Returns:



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

def list_customers(options = {})
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/customers.json',
                                 Server::PRODUCTION)
               .query_param(new_parameter(options['direction'], key: 'direction'))
               .query_param(new_parameter(options['page'], key: 'page'))
               .query_param(new_parameter(options['per_page'], key: 'per_page'))
               .query_param(new_parameter(options['date_field'], key: 'date_field'))
               .query_param(new_parameter(options['start_date'], key: 'start_date'))
               .query_param(new_parameter(options['end_date'], key: 'end_date'))
               .query_param(new_parameter(options['start_datetime'], key: 'start_datetime'))
               .query_param(new_parameter(options['end_datetime'], key: 'end_datetime'))
               .query_param(new_parameter(options['q'], key: 'q'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(CustomerResponse.method(:from_hash))
                .is_response_array(true))
    .execute
end

#read_customer(id) ⇒ CustomerResponse

Retrieves the Customer properties by Advanced Billing-generated Customer ID. customer

Parameters:

  • id (Integer)

    Required parameter: The Advanced Billing id of the

Returns:



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

def read_customer(id)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/customers/{id}.json',
                                 Server::PRODUCTION)
               .template_param(new_parameter(id, key: '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(CustomerResponse.method(:from_hash)))
    .execute
end

#read_customer_by_reference(reference) ⇒ CustomerResponse

Returns a customer by their unique reference ID. It will return a single match.

Parameters:

  • reference (String)

    Required parameter: Customer reference

Returns:



214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/advanced_billing/controllers/customers_controller.rb', line 214

def read_customer_by_reference(reference)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/customers/lookup.json',
                                 Server::PRODUCTION)
               .query_param(new_parameter(reference, key: 'reference')
                             .is_required(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(CustomerResponse.method(:from_hash)))
    .execute
end

#update_customer(id, body: nil) ⇒ CustomerResponse

Updates the customer. customer description here

Parameters:

  • id (Integer)

    Required parameter: The Advanced Billing id of the

  • body (UpdateCustomerRequest) (defaults to: nil)

    Optional parameter: TODO: type

Returns:



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/advanced_billing/controllers/customers_controller.rb', line 165

def update_customer(id,
                    body: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/customers/{id}.json',
                                 Server::PRODUCTION)
               .template_param(new_parameter(id, key: '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(CustomerResponse.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}\'.',
                                      CustomerErrorResponseException))
    .execute
end