Class: Square::Customers::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/square/customers/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Square::Customers::Client



7
8
9
# File 'lib/square/customers/client.rb', line 7

def initialize(client:)
  @client = client
end

Instance Method Details

#batch_create(request_options: {}, **params) ⇒ Square::Types::BulkCreateCustomersResponse

Creates multiple [customer profiles](entity:Customer) for a business.

This endpoint takes a map of individual create requests and returns a map of responses.

You must provide at least one of the following values in each create request:

  • ‘given_name`

  • ‘family_name`

  • ‘company_name`

  • ‘email_address`

  • ‘phone_number`



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/square/customers/client.rb', line 92

def batch_create(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "POST",
    path: "v2/customers/bulk-create",
    body: params
  )
  begin
    _response = @client.send(_request)
  rescue Net::HTTPRequestTimeout
    raise Square::Errors::TimeoutError
  end
  code = _response.code.to_i
  if code.between?(200, 299)
    Square::Types::BulkCreateCustomersResponse.load(_response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(_response.body, code: code)
  end
end

#bulk_delete_customers(request_options: {}, **params) ⇒ Square::Types::BulkDeleteCustomersResponse

Deletes multiple customer profiles.

The endpoint takes a list of customer IDs and returns a map of responses.



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/square/customers/client.rb', line 118

def bulk_delete_customers(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "POST",
    path: "v2/customers/bulk-delete",
    body: params
  )
  begin
    _response = @client.send(_request)
  rescue Net::HTTPRequestTimeout
    raise Square::Errors::TimeoutError
  end
  code = _response.code.to_i
  if code.between?(200, 299)
    Square::Types::BulkDeleteCustomersResponse.load(_response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(_response.body, code: code)
  end
end

#bulk_retrieve_customers(request_options: {}, **params) ⇒ Square::Types::BulkRetrieveCustomersResponse

Retrieves multiple customer profiles.

This endpoint takes a list of customer IDs and returns a map of responses.



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/square/customers/client.rb', line 144

def bulk_retrieve_customers(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "POST",
    path: "v2/customers/bulk-retrieve",
    body: params
  )
  begin
    _response = @client.send(_request)
  rescue Net::HTTPRequestTimeout
    raise Square::Errors::TimeoutError
  end
  code = _response.code.to_i
  if code.between?(200, 299)
    Square::Types::BulkRetrieveCustomersResponse.load(_response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(_response.body, code: code)
  end
end

#bulk_update_customers(request_options: {}, **params) ⇒ Square::Types::BulkUpdateCustomersResponse

Updates multiple customer profiles.

This endpoint takes a map of individual update requests and returns a map of responses.



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/square/customers/client.rb', line 170

def bulk_update_customers(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "POST",
    path: "v2/customers/bulk-update",
    body: params
  )
  begin
    _response = @client.send(_request)
  rescue Net::HTTPRequestTimeout
    raise Square::Errors::TimeoutError
  end
  code = _response.code.to_i
  if code.between?(200, 299)
    Square::Types::BulkUpdateCustomersResponse.load(_response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(_response.body, code: code)
  end
end

#cardsSquare::Cards::Client



324
325
326
# File 'lib/square/customers/client.rb', line 324

def cards
  @cards ||= Square::Customers::Cards::Client.new(client: @client)
end

#create(request_options: {}, **params) ⇒ Square::Types::CreateCustomerResponse

Creates a new customer for a business.

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`



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/square/customers/client.rb', line 58

def create(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "POST",
    path: "v2/customers",
    body: params
  )
  begin
    _response = @client.send(_request)
  rescue Net::HTTPRequestTimeout
    raise Square::Errors::TimeoutError
  end
  code = _response.code.to_i
  if code.between?(200, 299)
    Square::Types::CreateCustomerResponse.load(_response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(_response.body, code: code)
  end
end

#custom_attribute_definitionsSquare::CustomAttributeDefinitions::Client

Returns:

  • (Square::CustomAttributeDefinitions::Client)


309
310
311
# File 'lib/square/customers/client.rb', line 309

def custom_attribute_definitions
  @custom_attribute_definitions ||= Square::Customers::CustomAttributeDefinitions::Client.new(client: @client)
end

#custom_attributesSquare::CustomAttributes::Client

Returns:

  • (Square::CustomAttributes::Client)


329
330
331
# File 'lib/square/customers/client.rb', line 329

def custom_attributes
  @custom_attributes ||= Square::Customers::CustomAttributes::Client.new(client: @client)
end

#delete(request_options: {}, **params) ⇒ Square::Types::DeleteCustomerResponse

Deletes a customer profile from a business.

To delete a customer profile that was created by merging existing profiles, you must use the ID of the newly created profile.



280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/square/customers/client.rb', line 280

def delete(request_options: {}, **params)
  _query_param_names = [
    ["version"],
    %i[version]
  ].flatten
  _query = params.slice(*_query_param_names)
  params = params.except(*_query_param_names)

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "DELETE",
    path: "v2/customers/#{params[:customer_id]}",
    query: _query
  )
  begin
    _response = @client.send(_request)
  rescue Net::HTTPRequestTimeout
    raise Square::Errors::TimeoutError
  end
  code = _response.code.to_i
  if code.between?(200, 299)
    Square::Types::DeleteCustomerResponse.load(_response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(_response.body, code: code)
  end
end

#get(request_options: {}, **params) ⇒ Square::Types::GetCustomerResponse

Returns details for a single customer.



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/square/customers/client.rb', line 226

def get(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "GET",
    path: "v2/customers/#{params[:customer_id]}"
  )
  begin
    _response = @client.send(_request)
  rescue Net::HTTPRequestTimeout
    raise Square::Errors::TimeoutError
  end
  code = _response.code.to_i
  if code.between?(200, 299)
    Square::Types::GetCustomerResponse.load(_response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(_response.body, code: code)
  end
end

#groupsSquare::Groups::Client

Returns:

  • (Square::Groups::Client)


314
315
316
# File 'lib/square/customers/client.rb', line 314

def groups
  @groups ||= Square::Customers::Groups::Client.new(client: @client)
end

#list(request_options: {}, **params) ⇒ Square::Types::ListCustomersResponse

Lists customer profiles associated with a Square account.

Under normal operating conditions, newly created or updated customer profiles become available for the listing operation in well under 30 seconds. Occasionally, propagation of the new or updated profiles can take closer to one minute or longer, especially during network incidents and outages.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/square/customers/client.rb', line 18

def list(request_options: {}, **params)
  _query_param_names = [
    %w[cursor limit sort_field sort_order count],
    %i[cursor limit sort_field sort_order count]
  ].flatten
  _query = params.slice(*_query_param_names)
  params.except(*_query_param_names)

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "GET",
    path: "v2/customers",
    query: _query
  )
  begin
    _response = @client.send(_request)
  rescue Net::HTTPRequestTimeout
    raise Square::Errors::TimeoutError
  end
  code = _response.code.to_i
  if code.between?(200, 299)
    Square::Types::ListCustomersResponse.load(_response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(_response.body, code: code)
  end
end

#search(request_options: {}, **params) ⇒ Square::Types::SearchCustomersResponse

Searches the customer profiles associated with a Square account using one or more supported query filters.

Calling ‘SearchCustomers` without any explicit query filter returns all customer profiles ordered alphabetically based on `given_name` and `family_name`.

Under normal operating conditions, newly created or updated customer profiles become available for the search operation in well under 30 seconds. Occasionally, propagation of the new or updated profiles can take closer to one minute or longer, especially during network incidents and outages.



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/square/customers/client.rb', line 202

def search(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "POST",
    path: "v2/customers/search",
    body: params
  )
  begin
    _response = @client.send(_request)
  rescue Net::HTTPRequestTimeout
    raise Square::Errors::TimeoutError
  end
  code = _response.code.to_i
  if code.between?(200, 299)
    Square::Types::SearchCustomersResponse.load(_response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(_response.body, code: code)
  end
end

#segmentsSquare::Segments::Client

Returns:

  • (Square::Segments::Client)


319
320
321
# File 'lib/square/customers/client.rb', line 319

def segments
  @segments ||= Square::Customers::Segments::Client.new(client: @client)
end

#update(request_options: {}, **params) ⇒ Square::Types::UpdateCustomerResponse

Updates a customer profile. This endpoint supports sparse updates, so only new or changed fields are required in the request. To add or update a field, specify the new value. To remove a field, specify ‘null`.

To update a customer profile that was created by merging existing profiles, you must use the ID of the newly created profile.



252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/square/customers/client.rb', line 252

def update(request_options: {}, **params)
  _path_param_names = ["customer_id"]

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "PUT",
    path: "v2/customers/#{params[:customer_id]}",
    body: params.except(*_path_param_names)
  )
  begin
    _response = @client.send(_request)
  rescue Net::HTTPRequestTimeout
    raise Square::Errors::TimeoutError
  end
  code = _response.code.to_i
  if code.between?(200, 299)
    Square::Types::UpdateCustomerResponse.load(_response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(_response.body, code: code)
  end
end