Class: SquareConnect::CustomersApi

Inherits:
Object
  • Object
show all
Defined in:
lib/square_connect/api/customers_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_client = ApiClient.default) ⇒ CustomersApi

Returns a new instance of CustomersApi.



16
17
18
# File 'lib/square_connect/api/customers_api.rb', line 16

def initialize(api_client = ApiClient.default)
  @api_client = api_client
end

Instance Attribute Details

#api_clientObject

Returns the value of attribute api_client.



14
15
16
# File 'lib/square_connect/api/customers_api.rb', line 14

def api_client
  @api_client
end

Instance Method Details

#create_customer(body, opts = {}) ⇒ CreateCustomerResponse

CreateCustomer Creates a new customer for a business, which can have associated cards on file. You must provide __at least one__ of the following values in your request to this endpoint: - ‘given_name` - `family_name` - `company_name` - `email_address` - `phone_number` This endpoint does not accept an idempotency key. If you accidentally create a duplicate customer, you can delete it with the [DeleteCustomer](#endpoint-deletecustomer) endpoint.

Parameters:

  • body

    An object containing the fields to POST for the request. See the corresponding object definition for field details.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



25
26
27
28
# File 'lib/square_connect/api/customers_api.rb', line 25

def create_customer(body, opts = {})
  data, _status_code, _headers = create_customer_with_http_info(body, opts)
  return data
end

#create_customer_card(customer_id, body, opts = {}) ⇒ CreateCustomerCardResponse

CreateCustomerCard Adds a card on file to an existing customer. In the United States Square takes care of automatically updating any cards on file that might have expired since you first attached them to a customer. As with charges, calls to ‘CreateCustomerCard` are idempotent. Multiple calls with the same card nonce return the same card record that was created with the provided nonce during the first call.

Parameters:

  • customer_id

    The ID of the customer to link the card on file to.

  • body

    An object containing the fields to POST for the request. See the corresponding object definition for field details.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



79
80
81
82
# File 'lib/square_connect/api/customers_api.rb', line 79

def create_customer_card(customer_id, body, opts = {})
  data, _status_code, _headers = create_customer_card_with_http_info(customer_id, body, opts)
  return data
end

#create_customer_card_with_http_info(customer_id, body, opts = {}) ⇒ Array<(CreateCustomerCardResponse, Fixnum, Hash)>

CreateCustomerCard Adds a card on file to an existing customer. In the United States Square takes care of automatically updating any cards on file that might have expired since you first attached them to a customer. As with charges, calls to &#x60;CreateCustomerCard&#x60; are idempotent. Multiple calls with the same card nonce return the same card record that was created with the provided nonce during the first call.

Parameters:

  • customer_id

    The ID of the customer to link the card on file to.

  • body

    An object containing the fields to POST for the request. See the corresponding object definition for field details.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(CreateCustomerCardResponse, Fixnum, Hash)>)

    CreateCustomerCardResponse data, response status code and response headers



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/square_connect/api/customers_api.rb', line 90

def create_customer_card_with_http_info(customer_id, body, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug "Calling API: CustomersApi.create_customer_card ..."
  end
  # verify the required parameter 'customer_id' is set
  fail ArgumentError, "Missing the required parameter 'customer_id' when calling CustomersApi.create_customer_card" if customer_id.nil?
  # verify the required parameter 'body' is set
  fail ArgumentError, "Missing the required parameter 'body' when calling CustomersApi.create_customer_card" if body.nil?
  # resource path
  local_var_path = "/v2/customers/{customer_id}/cards".sub('{format}','json').sub('{' + 'customer_id' + '}', customer_id.to_s)

  # query parameters
  query_params = {}

  # header parameters
  header_params = {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  # HTTP header 'Content-Type'
  header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])

  # form parameters
  form_params = {}

  # http body (model)
  post_body = @api_client.object_to_http_body(body)
  auth_names = ['oauth2']
  data, status_code, headers = @api_client.call_api(:POST, local_var_path,
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => 'CreateCustomerCardResponse')
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: CustomersApi#create_customer_card\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#create_customer_with_http_info(body, opts = {}) ⇒ Array<(CreateCustomerResponse, Fixnum, Hash)>

CreateCustomer Creates a new customer for a business, which can have associated cards on file. You must provide __at least one__ of the following values in your request to this endpoint: - &#x60;given_name&#x60; - &#x60;family_name&#x60; - &#x60;company_name&#x60; - &#x60;email_address&#x60; - &#x60;phone_number&#x60; This endpoint does not accept an idempotency key. If you accidentally create a duplicate customer, you can delete it with the [DeleteCustomer](#endpoint-deletecustomer) endpoint.

Parameters:

  • body

    An object containing the fields to POST for the request. See the corresponding object definition for field details.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(CreateCustomerResponse, Fixnum, Hash)>)

    CreateCustomerResponse data, response status code and response headers



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/square_connect/api/customers_api.rb', line 35

def create_customer_with_http_info(body, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug "Calling API: CustomersApi.create_customer ..."
  end
  # verify the required parameter 'body' is set
  fail ArgumentError, "Missing the required parameter 'body' when calling CustomersApi.create_customer" if body.nil?
  # resource path
  local_var_path = "/v2/customers".sub('{format}','json')

  # query parameters
  query_params = {}

  # header parameters
  header_params = {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  # HTTP header 'Content-Type'
  header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])

  # form parameters
  form_params = {}

  # http body (model)
  post_body = @api_client.object_to_http_body(body)
  auth_names = ['oauth2']
  data, status_code, headers = @api_client.call_api(:POST, local_var_path,
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => 'CreateCustomerResponse')
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: CustomersApi#create_customer\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#delete_customer(customer_id, opts = {}) ⇒ DeleteCustomerResponse

DeleteCustomer Deletes a customer from a business, along with any linked cards on file.

Parameters:

  • customer_id

    The ID of the customer to delete.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



135
136
137
138
# File 'lib/square_connect/api/customers_api.rb', line 135

def delete_customer(customer_id, opts = {})
  data, _status_code, _headers = delete_customer_with_http_info(customer_id, opts)
  return data
end

#delete_customer_card(customer_id, card_id, opts = {}) ⇒ DeleteCustomerCardResponse

DeleteCustomerCard Removes a card on file from a customer.

Parameters:

  • customer_id

    The ID of the customer that the card on file belongs to.

  • card_id

    The ID of the card on file to delete.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



189
190
191
192
# File 'lib/square_connect/api/customers_api.rb', line 189

def delete_customer_card(customer_id, card_id, opts = {})
  data, _status_code, _headers = delete_customer_card_with_http_info(customer_id, card_id, opts)
  return data
end

#delete_customer_card_with_http_info(customer_id, card_id, opts = {}) ⇒ Array<(DeleteCustomerCardResponse, Fixnum, Hash)>

DeleteCustomerCard Removes a card on file from a customer.

Parameters:

  • customer_id

    The ID of the customer that the card on file belongs to.

  • card_id

    The ID of the card on file to delete.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(DeleteCustomerCardResponse, Fixnum, Hash)>)

    DeleteCustomerCardResponse data, response status code and response headers



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/square_connect/api/customers_api.rb', line 200

def delete_customer_card_with_http_info(customer_id, card_id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug "Calling API: CustomersApi.delete_customer_card ..."
  end
  # verify the required parameter 'customer_id' is set
  fail ArgumentError, "Missing the required parameter 'customer_id' when calling CustomersApi.delete_customer_card" if customer_id.nil?
  # verify the required parameter 'card_id' is set
  fail ArgumentError, "Missing the required parameter 'card_id' when calling CustomersApi.delete_customer_card" if card_id.nil?
  # resource path
  local_var_path = "/v2/customers/{customer_id}/cards/{card_id}".sub('{format}','json').sub('{' + 'customer_id' + '}', customer_id.to_s).sub('{' + 'card_id' + '}', card_id.to_s)

  # query parameters
  query_params = {}

  # header parameters
  header_params = {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  # HTTP header 'Content-Type'
  header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])

  # form parameters
  form_params = {}

  # http body (model)
  post_body = nil
  auth_names = ['oauth2']
  data, status_code, headers = @api_client.call_api(:DELETE, local_var_path,
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => 'DeleteCustomerCardResponse')
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: CustomersApi#delete_customer_card\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#delete_customer_with_http_info(customer_id, opts = {}) ⇒ Array<(DeleteCustomerResponse, Fixnum, Hash)>

DeleteCustomer Deletes a customer from a business, along with any linked cards on file.

Parameters:

  • customer_id

    The ID of the customer to delete.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(DeleteCustomerResponse, Fixnum, Hash)>)

    DeleteCustomerResponse data, response status code and response headers



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/square_connect/api/customers_api.rb', line 145

def delete_customer_with_http_info(customer_id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug "Calling API: CustomersApi.delete_customer ..."
  end
  # verify the required parameter 'customer_id' is set
  fail ArgumentError, "Missing the required parameter 'customer_id' when calling CustomersApi.delete_customer" if customer_id.nil?
  # resource path
  local_var_path = "/v2/customers/{customer_id}".sub('{format}','json').sub('{' + 'customer_id' + '}', customer_id.to_s)

  # query parameters
  query_params = {}

  # header parameters
  header_params = {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  # HTTP header 'Content-Type'
  header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])

  # form parameters
  form_params = {}

  # http body (model)
  post_body = nil
  auth_names = ['oauth2']
  data, status_code, headers = @api_client.call_api(:DELETE, local_var_path,
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => 'DeleteCustomerResponse')
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: CustomersApi#delete_customer\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#list_customers(opts = {}) ⇒ ListCustomersResponse

ListCustomers Lists a business’s customers.

Parameters:

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :cursor (String)

    A pagination cursor returned by a previous call to this endpoint. Provide this to retrieve the next set of results for your original query. See [Paginating results](#paginatingresults) for more information.

Returns:



245
246
247
248
# File 'lib/square_connect/api/customers_api.rb', line 245

def list_customers(opts = {})
  data, _status_code, _headers = list_customers_with_http_info(opts)
  return data
end

#list_customers_with_http_info(opts = {}) ⇒ Array<(ListCustomersResponse, Fixnum, Hash)>

ListCustomers Lists a business&#39;s customers.

Parameters:

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :cursor (String)

    A pagination cursor returned by a previous call to this endpoint. Provide this to retrieve the next set of results for your original query. See [Paginating results](#paginatingresults) for more information.

Returns:

  • (Array<(ListCustomersResponse, Fixnum, Hash)>)

    ListCustomersResponse data, response status code and response headers



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/square_connect/api/customers_api.rb', line 255

def list_customers_with_http_info(opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug "Calling API: CustomersApi.list_customers ..."
  end
  # resource path
  local_var_path = "/v2/customers".sub('{format}','json')

  # query parameters
  query_params = {}
  query_params[:'cursor'] = opts[:'cursor'] if !opts[:'cursor'].nil?

  # header parameters
  header_params = {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  # HTTP header 'Content-Type'
  header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])

  # form parameters
  form_params = {}

  # http body (model)
  post_body = nil
  auth_names = ['oauth2']
  data, status_code, headers = @api_client.call_api(:GET, local_var_path,
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => 'ListCustomersResponse')
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: CustomersApi#list_customers\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#retrieve_customer(customer_id, opts = {}) ⇒ RetrieveCustomerResponse

RetrieveCustomer Returns details for a single customer.

Parameters:

  • customer_id

    The ID of the customer to retrieve.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



297
298
299
300
# File 'lib/square_connect/api/customers_api.rb', line 297

def retrieve_customer(customer_id, opts = {})
  data, _status_code, _headers = retrieve_customer_with_http_info(customer_id, opts)
  return data
end

#retrieve_customer_with_http_info(customer_id, opts = {}) ⇒ Array<(RetrieveCustomerResponse, Fixnum, Hash)>

RetrieveCustomer Returns details for a single customer.

Parameters:

  • customer_id

    The ID of the customer to retrieve.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(RetrieveCustomerResponse, Fixnum, Hash)>)

    RetrieveCustomerResponse data, response status code and response headers



307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/square_connect/api/customers_api.rb', line 307

def retrieve_customer_with_http_info(customer_id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug "Calling API: CustomersApi.retrieve_customer ..."
  end
  # verify the required parameter 'customer_id' is set
  fail ArgumentError, "Missing the required parameter 'customer_id' when calling CustomersApi.retrieve_customer" if customer_id.nil?
  # resource path
  local_var_path = "/v2/customers/{customer_id}".sub('{format}','json').sub('{' + 'customer_id' + '}', customer_id.to_s)

  # query parameters
  query_params = {}

  # header parameters
  header_params = {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  # HTTP header 'Content-Type'
  header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])

  # form parameters
  form_params = {}

  # http body (model)
  post_body = nil
  auth_names = ['oauth2']
  data, status_code, headers = @api_client.call_api(:GET, local_var_path,
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => 'RetrieveCustomerResponse')
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: CustomersApi#retrieve_customer\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#update_customer(customer_id, body, opts = {}) ⇒ UpdateCustomerResponse

UpdateCustomer Updates the details of an existing customer. The ID of the customer may change if the customer has been merged into another customer. You cannot edit a customer’s cards on file with this endpoint. To make changes to a card on file, you must delete the existing card on file with the [DeleteCustomerCard](#endpoint-deletecustomercard) endpoint, then create a new one with the [CreateCustomerCard](#endpoint-createcustomercard) endpoint.

Parameters:

  • customer_id

    The ID of the customer to update.

  • body

    An object containing the fields to POST for the request. See the corresponding object definition for field details.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



351
352
353
354
# File 'lib/square_connect/api/customers_api.rb', line 351

def update_customer(customer_id, body, opts = {})
  data, _status_code, _headers = update_customer_with_http_info(customer_id, body, opts)
  return data
end

#update_customer_with_http_info(customer_id, body, opts = {}) ⇒ Array<(UpdateCustomerResponse, Fixnum, Hash)>

UpdateCustomer Updates the details of an existing customer. The ID of the customer may change if the customer has been merged into another customer. You cannot edit a customer&#39;s cards on file with this endpoint. To make changes to a card on file, you must delete the existing card on file with the [DeleteCustomerCard](#endpoint-deletecustomercard) endpoint, then create a new one with the [CreateCustomerCard](#endpoint-createcustomercard) endpoint.

Parameters:

  • customer_id

    The ID of the customer to update.

  • body

    An object containing the fields to POST for the request. See the corresponding object definition for field details.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(UpdateCustomerResponse, Fixnum, Hash)>)

    UpdateCustomerResponse data, response status code and response headers



362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
# File 'lib/square_connect/api/customers_api.rb', line 362

def update_customer_with_http_info(customer_id, body, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug "Calling API: CustomersApi.update_customer ..."
  end
  # verify the required parameter 'customer_id' is set
  fail ArgumentError, "Missing the required parameter 'customer_id' when calling CustomersApi.update_customer" if customer_id.nil?
  # verify the required parameter 'body' is set
  fail ArgumentError, "Missing the required parameter 'body' when calling CustomersApi.update_customer" if body.nil?
  # resource path
  local_var_path = "/v2/customers/{customer_id}".sub('{format}','json').sub('{' + 'customer_id' + '}', customer_id.to_s)

  # query parameters
  query_params = {}

  # header parameters
  header_params = {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  # HTTP header 'Content-Type'
  header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])

  # form parameters
  form_params = {}

  # http body (model)
  post_body = @api_client.object_to_http_body(body)
  auth_names = ['oauth2']
  data, status_code, headers = @api_client.call_api(:PUT, local_var_path,
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => 'UpdateCustomerResponse')
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: CustomersApi#update_customer\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end