square.rb 12.0.0.20210616 → 14.1.0.20210915

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,13 +6,14 @@ module Square
6
6
  end
7
7
 
8
8
  # Returns a paginated list of `BreakType` instances for a business.
9
- # @param [String] location_id Optional parameter: Filter Break Types
10
- # returned to only those that are associated with the specified location.
11
- # @param [Integer] limit Optional parameter: Maximum number of Break Types
12
- # to return per page. Can range between 1 and 200. The default is the
13
- # maximum at 200.
14
- # @param [String] cursor Optional parameter: Pointer to the next page of
15
- # Break Type results to fetch.
9
+ # @param [String] location_id Optional parameter: Filter the returned
10
+ # `BreakType` results to only those that are associated with the specified
11
+ # location.
12
+ # @param [Integer] limit Optional parameter: The maximum number of
13
+ # `BreakType` results to return per page. The number can range between 1 and
14
+ # 200. The default is 200.
15
+ # @param [String] cursor Optional parameter: A pointer to the next page of
16
+ # `BreakType` results to fetch.
16
17
  # @return [ListBreakTypesResponse Hash] response from the API call
17
18
  def list_break_types(location_id: nil,
18
19
  limit: nil,
@@ -57,8 +58,8 @@ module Square
57
58
  # - `break_name`
58
59
  # - `expected_duration`
59
60
  # - `is_paid`
60
- # You can only have 3 `BreakType` instances per location. If you attempt to
61
- # add a 4th
61
+ # You can only have three `BreakType` instances per location. If you attempt
62
+ # to add a fourth
62
63
  # `BreakType` for a location, an `INVALID_REQUEST_ERROR` "Exceeded limit of
63
64
  # 3 breaks per location."
64
65
  # is returned.
@@ -97,7 +98,7 @@ module Square
97
98
 
98
99
  # Deletes an existing `BreakType`.
99
100
  # A `BreakType` can be deleted even if it is referenced from a `Shift`.
100
- # @param [String] id Required parameter: UUID for the `BreakType` being
101
+ # @param [String] id Required parameter: The UUID for the `BreakType` being
101
102
  # deleted.
102
103
  # @return [DeleteBreakTypeResponse Hash] response from the API call
103
104
  def delete_break_type(id:)
@@ -131,8 +132,8 @@ module Square
131
132
  )
132
133
  end
133
134
 
134
- # Returns a single `BreakType` specified by id.
135
- # @param [String] id Required parameter: UUID for the `BreakType` being
135
+ # Returns a single `BreakType` specified by `id`.
136
+ # @param [String] id Required parameter: The UUID for the `BreakType` being
136
137
  # retrieved.
137
138
  # @return [GetBreakTypeResponse Hash] response from the API call
138
139
  def get_break_type(id:)
@@ -167,7 +168,7 @@ module Square
167
168
  end
168
169
 
169
170
  # Updates an existing `BreakType`.
170
- # @param [String] id Required parameter: UUID for the `BreakType` being
171
+ # @param [String] id Required parameter: The UUID for the `BreakType` being
171
172
  # updated.
172
173
  # @param [UpdateBreakTypeRequest] body Required parameter: An object
173
174
  # containing the fields to POST for the request. See the corresponding
@@ -208,13 +209,13 @@ module Square
208
209
  end
209
210
 
210
211
  # Returns a paginated list of `EmployeeWage` instances for a business.
211
- # @param [String] employee_id Optional parameter: Filter wages returned to
212
- # only those that are associated with the specified employee.
213
- # @param [Integer] limit Optional parameter: Maximum number of Employee
214
- # Wages to return per page. Can range between 1 and 200. The default is the
215
- # maximum at 200.
216
- # @param [String] cursor Optional parameter: Pointer to the next page of
217
- # Employee Wage results to fetch.
212
+ # @param [String] employee_id Optional parameter: Filter the returned wages
213
+ # to only those that are associated with the specified employee.
214
+ # @param [Integer] limit Optional parameter: The maximum number of
215
+ # `EmployeeWage` results to return per page. The number can range between 1
216
+ # and 200. The default is 200.
217
+ # @param [String] cursor Optional parameter: A pointer to the next page of
218
+ # `EmployeeWage` results to fetch.
218
219
  # @return [ListEmployeeWagesResponse Hash] response from the API call
219
220
  def list_employee_wages(employee_id: nil,
220
221
  limit: nil,
@@ -252,9 +253,9 @@ module Square
252
253
  )
253
254
  end
254
255
 
255
- # Returns a single `EmployeeWage` specified by id.
256
- # @param [String] id Required parameter: UUID for the `EmployeeWage` being
257
- # retrieved.
256
+ # Returns a single `EmployeeWage` specified by `id`.
257
+ # @param [String] id Required parameter: The UUID for the `EmployeeWage`
258
+ # being retrieved.
258
259
  # @return [GetEmployeeWageResponse Hash] response from the API call
259
260
  def get_employee_wage(id:)
260
261
  warn 'Endpoint get_employee_wage in LaborApi is deprecated'
@@ -289,7 +290,7 @@ module Square
289
290
  end
290
291
 
291
292
  # Creates a new `Shift`.
292
- # A `Shift` represents a complete work day for a single employee.
293
+ # A `Shift` represents a complete workday for a single employee.
293
294
  # You must provide the following values in your request to this
294
295
  # endpoint:
295
296
  # - `location_id`
@@ -299,12 +300,12 @@ module Square
299
300
  # when:
300
301
  # - The `status` of the new `Shift` is `OPEN` and the employee has another
301
302
  # shift with an `OPEN` status.
302
- # - The `start_at` date is in the future
303
- # - the `start_at` or `end_at` overlaps another shift for the same employee
304
- # - If `Break`s are set in the request, a break `start_at`
305
- # must not be before the `Shift.start_at`. A break `end_at` must not be
306
- # after
307
- # the `Shift.end_at`
303
+ # - The `start_at` date is in the future.
304
+ # - The `start_at` or `end_at` date overlaps another shift for the same
305
+ # employee.
306
+ # - The `Break` instances are set in the request and a break `start_at`
307
+ # is before the `Shift.start_at`, a break `end_at` is after
308
+ # the `Shift.end_at`, or both.
308
309
  # @param [CreateShiftRequest] body Required parameter: An object containing
309
310
  # the fields to POST for the request. See the corresponding object
310
311
  # definition for field details.
@@ -340,17 +341,17 @@ module Square
340
341
 
341
342
  # Returns a paginated list of `Shift` records for a business.
342
343
  # The list to be returned can be filtered by:
343
- # - Location IDs **and**
344
- # - employee IDs **and**
345
- # - shift status (`OPEN`, `CLOSED`) **and**
346
- # - shift start **and**
347
- # - shift end **and**
348
- # - work day details
344
+ # - Location IDs.
345
+ # - Employee IDs.
346
+ # - Shift status (`OPEN` and `CLOSED`).
347
+ # - Shift start.
348
+ # - Shift end.
349
+ # - Workday details.
349
350
  # The list can be sorted by:
350
- # - `start_at`
351
- # - `end_at`
352
- # - `created_at`
353
- # - `updated_at`
351
+ # - `start_at`.
352
+ # - `end_at`.
353
+ # - `created_at`.
354
+ # - `updated_at`.
354
355
  # @param [SearchShiftsRequest] body Required parameter: An object containing
355
356
  # the fields to POST for the request. See the corresponding object
356
357
  # definition for field details.
@@ -385,7 +386,7 @@ module Square
385
386
  end
386
387
 
387
388
  # Deletes a `Shift`.
388
- # @param [String] id Required parameter: UUID for the `Shift` being
389
+ # @param [String] id Required parameter: The UUID for the `Shift` being
389
390
  # deleted.
390
391
  # @return [DeleteShiftResponse Hash] response from the API call
391
392
  def delete_shift(id:)
@@ -419,8 +420,8 @@ module Square
419
420
  )
420
421
  end
421
422
 
422
- # Returns a single `Shift` specified by id.
423
- # @param [String] id Required parameter: UUID for the `Shift` being
423
+ # Returns a single `Shift` specified by `id`.
424
+ # @param [String] id Required parameter: The UUID for the `Shift` being
424
425
  # retrieved.
425
426
  # @return [GetShiftResponse Hash] response from the API call
426
427
  def get_shift(id:)
@@ -455,13 +456,14 @@ module Square
455
456
  end
456
457
 
457
458
  # Updates an existing `Shift`.
458
- # When adding a `Break` to a `Shift`, any earlier `Breaks` in the `Shift`
459
- # have
459
+ # When adding a `Break` to a `Shift`, any earlier `Break` instances in the
460
+ # `Shift` have
460
461
  # the `end_at` property set to a valid RFC-3339 datetime string.
461
- # When closing a `Shift`, all `Break` instances in the shift must be
462
+ # When closing a `Shift`, all `Break` instances in the `Shift` must be
462
463
  # complete with `end_at`
463
464
  # set on each `Break`.
464
- # @param [String] id Required parameter: ID of the object being updated.
465
+ # @param [String] id Required parameter: The ID of the object being
466
+ # updated.
465
467
  # @param [UpdateShiftRequest] body Required parameter: An object containing
466
468
  # the fields to POST for the request. See the corresponding object
467
469
  # definition for field details.
@@ -501,13 +503,13 @@ module Square
501
503
  end
502
504
 
503
505
  # Returns a paginated list of `TeamMemberWage` instances for a business.
504
- # @param [String] team_member_id Optional parameter: Filter wages returned
505
- # to only those that are associated with the specified team member.
506
- # @param [Integer] limit Optional parameter: Maximum number of Team Member
507
- # Wages to return per page. Can range between 1 and 200. The default is the
508
- # maximum at 200.
509
- # @param [String] cursor Optional parameter: Pointer to the next page of
510
- # Employee Wage results to fetch.
506
+ # @param [String] team_member_id Optional parameter: Filter the returned
507
+ # wages to only those that are associated with the specified team member.
508
+ # @param [Integer] limit Optional parameter: The maximum number of
509
+ # `TeamMemberWage` results to return per page. The number can range between
510
+ # 1 and 200. The default is 200.
511
+ # @param [String] cursor Optional parameter: A pointer to the next page of
512
+ # `EmployeeWage` results to fetch.
511
513
  # @return [ListTeamMemberWagesResponse Hash] response from the API call
512
514
  def list_team_member_wages(team_member_id: nil,
513
515
  limit: nil,
@@ -544,9 +546,9 @@ module Square
544
546
  )
545
547
  end
546
548
 
547
- # Returns a single `TeamMemberWage` specified by id.
548
- # @param [String] id Required parameter: UUID for the `TeamMemberWage` being
549
- # retrieved.
549
+ # Returns a single `TeamMemberWage` specified by `id `.
550
+ # @param [String] id Required parameter: The UUID for the `TeamMemberWage`
551
+ # being retrieved.
550
552
  # @return [GetTeamMemberWageResponse Hash] response from the API call
551
553
  def get_team_member_wage(id:)
552
554
  # Prepare query url.
@@ -580,10 +582,10 @@ module Square
580
582
  end
581
583
 
582
584
  # Returns a list of `WorkweekConfig` instances for a business.
583
- # @param [Integer] limit Optional parameter: Maximum number of Workweek
584
- # Configs to return per page.
585
- # @param [String] cursor Optional parameter: Pointer to the next page of
586
- # Workweek Config results to fetch.
585
+ # @param [Integer] limit Optional parameter: The maximum number of
586
+ # `WorkweekConfigs` results to return per page.
587
+ # @param [String] cursor Optional parameter: A pointer to the next page of
588
+ # `WorkweekConfig` results to fetch.
587
589
  # @return [ListWorkweekConfigsResponse Hash] response from the API call
588
590
  def list_workweek_configs(limit: nil,
589
591
  cursor: nil)
@@ -619,7 +621,7 @@ module Square
619
621
  end
620
622
 
621
623
  # Updates a `WorkweekConfig`.
622
- # @param [String] id Required parameter: UUID for the `WorkweekConfig`
624
+ # @param [String] id Required parameter: The UUID for the `WorkweekConfig`
623
625
  # object being updated.
624
626
  # @param [UpdateWorkweekConfigRequest] body Required parameter: An object
625
627
  # containing the fields to POST for the request. See the corresponding
@@ -120,12 +120,16 @@ module Square
120
120
  # account.
121
121
  # - If you are not using the Orders API to manage orders,
122
122
  # you first perform a client-side computation to compute the points.
123
- # For spend-based and visit-based programs, you can call
123
+ # For spend-based and visit-based programs, you can first call
124
124
  # [CalculateLoyaltyPoints]($e/Loyalty/CalculateLoyaltyPoints) to compute the
125
- # points. For more information,
126
- # see [Loyalty Program
127
- # Overview](https://developer.squareup.com/docs/loyalty/overview).
128
- # You then provide the points in a request to this endpoint.
125
+ # points
126
+ # that you provide to this endpoint.
127
+ # __Note:__ The country of the seller's Square account determines whether
128
+ # tax is included in the purchase amount when accruing points for
129
+ # spend-based and visit-based programs.
130
+ # For more information, see [Availability of Square
131
+ # Loyalty](https://developer.squareup.com/docs/loyalty-api/overview#loyalty-
132
+ # market-availability).
129
133
  # @param [String] account_id Required parameter: The [loyalty
130
134
  # account]($m/LoyaltyAccount) ID to which to add the points.
131
135
  # @param [AccumulateLoyaltyPointsRequest] body Required parameter: An object
@@ -341,6 +345,12 @@ module Square
341
345
  # An application might call this endpoint to show the points that a buyer
342
346
  # can earn with the
343
347
  # specific purchase.
348
+ # __Note:__ The country of the seller's Square account determines whether
349
+ # tax is included in the purchase amount when accruing points for
350
+ # spend-based and visit-based programs.
351
+ # For more information, see [Availability of Square
352
+ # Loyalty](https://developer.squareup.com/docs/loyalty-api/overview#loyalty-
353
+ # market-availability).
344
354
  # @param [String] program_id Required parameter: The [loyalty
345
355
  # program]($m/LoyaltyProgram) ID, which defines the rules for accruing
346
356
  # points.
@@ -27,8 +27,8 @@ module Square
27
27
  # Credentials
28
28
  # page in the [developer dashboard](https://developer.squareup.com/apps).
29
29
  # @param [String] client_id Required parameter: Your application ID,
30
- # available from the [developer
31
- # dashboard](https://developer.squareup.com/apps).
30
+ # available from the OAuth page for your application on the Developer
31
+ # Dashboard.
32
32
  # @param [RenewTokenRequest] body Required parameter: An object containing
33
33
  # the fields to POST for the request. See the corresponding object
34
34
  # definition for field details.
@@ -84,7 +84,7 @@ module Square
84
84
  # Authorization: Client APPLICATION_SECRET
85
85
  # ```
86
86
  # Replace `APPLICATION_SECRET` with the application secret on the OAuth
87
- # page in the [developer dashboard](https://developer.squareup.com/apps).
87
+ # page for your application on the Developer Dashboard.
88
88
  # @param [RevokeTokenRequest] body Required parameter: An object containing
89
89
  # the fields to POST for the request. See the corresponding object
90
90
  # definition for field details.
@@ -121,15 +121,22 @@ module Square
121
121
  )
122
122
  end
123
123
 
124
- # Returns an OAuth access token.
125
- # The endpoint supports distinct methods of obtaining OAuth access tokens.
126
- # Applications specify a method by adding the `grant_type` parameter
127
- # in the request and also provide relevant information.
128
- # __Note:__ Regardless of the method application specified,
129
- # the endpoint always returns two items; an OAuth access token and
130
- # a refresh token in the response.
131
- # __OAuth tokens should only live on secure servers. Application clients
132
- # should never interact directly with OAuth tokens__.
124
+ # Returns an OAuth access token and a refresh token unless the
125
+ # `short_lived` parameter is set to `true`, in which case the endpoint
126
+ # returns only an access token.
127
+ # The `grant_type` parameter specifies the type of OAuth request. If
128
+ # `grant_type` is `authorization_code`, you must include the authorization
129
+ # code you received when a seller granted you authorization. If `grant_type`
130
+ # is `refresh_token`, you must provide a valid refresh token. If you are
131
+ # using
132
+ # an old version of the Square APIs (prior to March 13, 2019), `grant_type`
133
+ # can be `migration_token` and you must provide a valid migration token.
134
+ # You can use the `scopes` parameter to limit the set of permissions granted
135
+ # to the access token and refresh token. You can use the `short_lived`
136
+ # parameter
137
+ # to create an access token that expires in 24 hours.
138
+ # __Note:__ OAuth tokens should be encrypted and stored on a secure server.
139
+ # Application clients should never interact directly with OAuth tokens.
133
140
  # @param [ObtainTokenRequest] body Required parameter: An object containing
134
141
  # the fields to POST for the request. See the corresponding object
135
142
  # definition for field details.
@@ -116,6 +116,43 @@ module Square
116
116
  )
117
117
  end
118
118
 
119
+ # Creates a new order, in the `DRAFT` state, by duplicating an existing
120
+ # order. The newly created order has
121
+ # only the core fields (such as line items, taxes, and discounts) copied
122
+ # from the original order.
123
+ # @param [CloneOrderRequest] body Required parameter: An object containing
124
+ # the fields to POST for the request. See the corresponding object
125
+ # definition for field details.
126
+ # @return [CloneOrderResponse Hash] response from the API call
127
+ def clone_order(body:)
128
+ # Prepare query url.
129
+ _query_builder = config.get_base_uri
130
+ _query_builder << '/v2/orders/clone'
131
+ _query_url = APIHelper.clean_url _query_builder
132
+
133
+ # Prepare headers.
134
+ _headers = {
135
+ 'accept' => 'application/json',
136
+ 'content-type' => 'application/json; charset=utf-8'
137
+ }
138
+
139
+ # Prepare and execute HttpRequest.
140
+ _request = config.http_client.post(
141
+ _query_url,
142
+ headers: _headers,
143
+ parameters: body.to_json
144
+ )
145
+ OAuth2.apply(config, _request)
146
+ _response = execute_request(_request)
147
+
148
+ # Return appropriate response type.
149
+ decoded = APIHelper.json_deserialize(_response.raw_body)
150
+ _errors = APIHelper.map_response(decoded, ['errors'])
151
+ ApiResponse.new(
152
+ _response, data: decoded, errors: _errors
153
+ )
154
+ end
155
+
119
156
  # Search all orders for one or more locations. Orders include all sales,
120
157
  # returns, and exchanges regardless of how or when they entered the Square
121
158
  # ecosystem (such as Point of Sale, Invoices, and Connect APIs).
@@ -8,13 +8,14 @@ module Square
8
8
  def self.serialize_array(key, array, formatting: 'indexed')
9
9
  tuples = []
10
10
 
11
- if formatting == 'unindexed'
11
+ case formatting
12
+ when 'unindexed'
12
13
  tuples += array.map { |element| ["#{key}[]", element] }
13
- elsif formatting == 'indexed'
14
+ when 'indexed'
14
15
  tuples += array.map.with_index do |element, index|
15
16
  ["#{key}[#{index}]", element]
16
17
  end
17
- elsif formatting == 'plain'
18
+ when 'plain'
18
19
  tuples += array.map { |element| [key, element] }
19
20
  else
20
21
  raise ArgumentError, 'Invalid format provided.'
@@ -55,7 +56,7 @@ module Square
55
56
  end
56
57
 
57
58
  # Find the template parameter and replace it with its value.
58
- query_builder = query_builder.gsub('{' + key.to_s + '}', replace_value)
59
+ query_builder = query_builder.gsub("{#{key}}", replace_value)
59
60
  end
60
61
  query_builder
61
62
  end
@@ -80,15 +81,16 @@ module Square
80
81
  unless value.nil?
81
82
  if value.instance_of? Array
82
83
  value.compact!
83
- query_builder += if array_serialization == 'csv'
84
+ query_builder += case array_serialization
85
+ when 'csv'
84
86
  "#{seperator}#{key}=#{value.map do |element|
85
87
  CGI.escape(element.to_s)
86
88
  end.join(',')}"
87
- elsif array_serialization == 'psv'
89
+ when 'psv'
88
90
  "#{seperator}#{key}=#{value.map do |element|
89
91
  CGI.escape(element.to_s)
90
92
  end.join('|')}"
91
- elsif array_serialization == 'tsv'
93
+ when 'tsv'
92
94
  "#{seperator}#{key}=#{value.map do |element|
93
95
  CGI.escape(element.to_s)
94
96
  end.join("\t")}"
@@ -114,7 +116,7 @@ module Square
114
116
  raise ArgumentError, 'Invalid Url.' unless url.instance_of? String
115
117
 
116
118
  # Ensure that the urls are absolute.
117
- matches = url.match(%r{^(https?:\/\/[^\/]+)})
119
+ matches = url.match(%r{^(https?://[^/]+)})
118
120
  raise ArgumentError, 'Invalid Url format.' if matches.nil?
119
121
 
120
122
  # Get the http protocol match.
@@ -125,7 +127,7 @@ module Square
125
127
 
126
128
  # Remove redundant forward slashes.
127
129
  query = url[protocol.length...(!index.nil? ? index : url.length)]
128
- query.gsub!(%r{\/\/+}, '/')
130
+ query.gsub!(%r{//+}, '/')
129
131
 
130
132
  # Get the parameters.
131
133
  parameters = !index.nil? ? url[url.index('?')...url.length] : ''
@@ -137,7 +139,7 @@ module Square
137
139
  # Parses JSON string.
138
140
  # @param [String] A JSON string.
139
141
  def self.json_deserialize(json)
140
- return JSON.parse(json, symbolize_names: true)
142
+ JSON.parse(json, symbolize_names: true)
141
143
  rescue StandardError
142
144
  raise TypeError, 'Server responded with invalid JSON.'
143
145
  end
@@ -166,6 +168,7 @@ module Square
166
168
  a.each do |key, value_a|
167
169
  b.each do |k, value_b|
168
170
  next unless key == k
171
+
169
172
  x[k] = []
170
173
  if value_a.instance_of? Array
171
174
  value_a.each do |v|
@@ -207,13 +210,12 @@ module Square
207
210
  elsif obj.instance_of? Array
208
211
  if formatting == 'indexed'
209
212
  obj.each_with_index do |value, index|
210
- retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
211
- index.to_s + ']'))
213
+ retval.merge!(APIHelper.form_encode(value, "#{instance_name}[#{index}]"))
212
214
  end
213
215
  elsif serializable_types.map { |x| obj[0].is_a? x }.any?
214
216
  obj.each do |value|
215
217
  abc = if formatting == 'unindexed'
216
- APIHelper.form_encode(value, instance_name + '[]',
218
+ APIHelper.form_encode(value, "#{instance_name}[]",
217
219
  formatting: formatting)
218
220
  else
219
221
  APIHelper.form_encode(value, instance_name,
@@ -223,14 +225,14 @@ module Square
223
225
  end
224
226
  else
225
227
  obj.each_with_index do |value, index|
226
- retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
227
- index.to_s + ']', formatting: formatting))
228
+ retval.merge!(APIHelper.form_encode(value, "#{instance_name}[#{index}]",
229
+ formatting: formatting))
228
230
  end
229
231
  end
230
232
  elsif obj.instance_of? Hash
231
233
  obj.each do |key, value|
232
- retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
233
- key.to_s + ']', formatting: formatting))
234
+ retval.merge!(APIHelper.form_encode(value, "#{instance_name}[#{key}]",
235
+ formatting: formatting))
234
236
  end
235
237
  elsif obj.instance_of? File
236
238
  retval[instance_name] = UploadIO.new(
@@ -265,17 +267,5 @@ module Square
265
267
  end
266
268
  val
267
269
  end
268
-
269
- # Safely converts a string into an rfc3339 DateTime object
270
- # @param [String] The datetime string
271
- # @return [DateTime] A DateTime object of rfc3339 format
272
- def self.rfc3339(date_time)
273
- # missing timezone information
274
- if date_time.end_with?('Z') || date_time.index('+')
275
- DateTime.rfc3339(date_time)
276
- else
277
- DateTime.rfc3339(date_time + 'Z')
278
- end
279
- end
280
270
  end
281
271
  end