Class: AdvancedBilling::CustomersController
- Inherits:
-
BaseController
- Object
- BaseController
- AdvancedBilling::CustomersController
- Defined in:
- lib/advanced_billing/controllers/customers_controller.rb
Overview
CustomersController
Constant Summary
Constants inherited from BaseController
Instance Attribute Summary
Attributes inherited from BaseController
Instance Method Summary collapse
-
#create_customer(body: nil) ⇒ CustomerResponse
Creates a new customer; can also be created alongside a new subscription.
-
#delete_customer(id) ⇒ void
Deletes the customer.
-
#list_customer_subscriptions(customer_id) ⇒ Array[SubscriptionResponse]
Lists all subscriptions that belong to a customer.
-
#list_customers(options = {}) ⇒ Array[CustomerResponse]
Lists all customers associated with your site, or filters results using the search parameter.
-
#read_customer(id) ⇒ CustomerResponse
Retrieves the Customer properties by Advanced Billing-generated Customer ID.
-
#read_customer_by_reference(reference) ⇒ CustomerResponse
Returns a customer by their unique reference ID.
-
#update_customer(id, body: nil) ⇒ CustomerResponse
Updates the customer.
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 may 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 may choose to leave `reference` blank, and store Advanced Billing’s unique ID for the customer, which is in the `id` attribute. Full documentation on how to locate, create and edit Customers in the Advanced Billing UI can be located [here](maxio.zendesk.com/hc/en-us/articles/24252190590093-Customer -Details). ## Required Country Format Advanced Billing requires that you use the ISO Standard Country codes when formatting country attribute of the customer. Countries should be formatted as 2 characters. For more information, see the following wikipedia article on [ISO_3166-1.](en.wikipedia.org/wiki/ISO_3166-1#Current_codes) ## Required State Format Advanced Billing requires that you use the ISO Standard State codes when formatting state attribute of the customer. + US States (2 characters): [ISO_3166-2](en.wikipedia.org/wiki/ISO_3166-2:US) + States Outside the US (2-3 characters): To find the correct state codes outside of the US, go to [ISO_3166-1](en.wikipedia.org/wiki/ISO_3166-1#Current_codes) and click on the link in the “ISO 3166-2 codes” column next to country you wish to populate. ## Locale Advanced Billing allows you to attribute a language/region to your customer to deliver invoices in any required language. For more: [Customer Locale](maxio.zendesk.com/hc/en-us/articles/24286672013709-Custome r-Locale) description here
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/advanced_billing/controllers/customers_controller.rb', line 47 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
199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/advanced_billing/controllers/customers_controller.rb', line 199 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. customer
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/advanced_billing/controllers/customers_controller.rb', line 236 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](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)
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/advanced_billing/controllers/customers_controller.rb', line 118 def list_customers( = {}) @api_call .request(new_request_builder(HttpMethodEnum::GET, '/customers.json', Server::PRODUCTION) .query_param(new_parameter(['direction'], key: 'direction')) .query_param(new_parameter(['page'], key: 'page')) .query_param(new_parameter(['per_page'], key: 'per_page')) .query_param(new_parameter(['date_field'], key: 'date_field')) .query_param(new_parameter(['start_date'], key: 'start_date')) .query_param(new_parameter(['end_date'], key: 'end_date')) .query_param(new_parameter(['start_datetime'], key: 'start_datetime')) .query_param(new_parameter(['end_datetime'], key: 'end_datetime')) .query_param(new_parameter(['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
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/advanced_billing/controllers/customers_controller.rb', line 146 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.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/advanced_billing/controllers/customers_controller.rb', line 217 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
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/advanced_billing/controllers/customers_controller.rb', line 168 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 |