square.rb 8.1.0.20210121 → 18.1.0.20220316

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.md +59 -213
  4. data/lib/square/api/apple_pay_api.rb +9 -8
  5. data/lib/square/api/bank_accounts_api.rb +5 -5
  6. data/lib/square/api/base_api.rb +20 -9
  7. data/lib/square/api/bookings_api.rb +95 -12
  8. data/lib/square/api/cards_api.rb +170 -0
  9. data/lib/square/api/cash_drawers_api.rb +2 -2
  10. data/lib/square/api/catalog_api.rb +140 -66
  11. data/lib/square/api/checkout_api.rb +3 -3
  12. data/lib/square/api/customer_groups_api.rb +17 -8
  13. data/lib/square/api/customer_segments_api.rb +15 -6
  14. data/lib/square/api/customers_api.rb +61 -31
  15. data/lib/square/api/devices_api.rb +3 -2
  16. data/lib/square/api/disputes_api.rb +101 -92
  17. data/lib/square/api/gift_card_activities_api.rb +133 -0
  18. data/lib/square/api/gift_cards_api.rb +297 -0
  19. data/lib/square/api/inventory_api.rb +263 -24
  20. data/lib/square/api/invoices_api.rb +19 -19
  21. data/lib/square/api/labor_api.rb +70 -68
  22. data/lib/square/api/locations_api.rb +22 -14
  23. data/lib/square/api/loyalty_api.rb +86 -32
  24. data/lib/square/api/merchants_api.rb +11 -9
  25. data/lib/square/api/mobile_authorization_api.rb +4 -4
  26. data/lib/square/api/o_auth_api.rb +31 -25
  27. data/lib/square/api/orders_api.rb +78 -39
  28. data/lib/square/api/payments_api.rb +71 -23
  29. data/lib/square/api/refunds_api.rb +18 -7
  30. data/lib/square/api/sites_api.rb +43 -0
  31. data/lib/square/api/snippets_api.rb +146 -0
  32. data/lib/square/api/subscriptions_api.rb +190 -12
  33. data/lib/square/api/team_api.rb +46 -46
  34. data/lib/square/api/terminal_api.rb +19 -18
  35. data/lib/square/api/transactions_api.rb +15 -191
  36. data/lib/square/api/v1_transactions_api.rb +13 -85
  37. data/lib/square/api/vendors_api.rb +257 -0
  38. data/lib/square/api_helper.rb +45 -57
  39. data/lib/square/client.rb +54 -18
  40. data/lib/square/configuration.rb +59 -20
  41. data/lib/square/http/api_response.rb +1 -1
  42. data/lib/square/http/faraday_client.rb +24 -4
  43. data/lib/square/utilities/date_time_helper.rb +151 -0
  44. data/lib/square/utilities/file_wrapper.rb +1 -2
  45. data/lib/square.rb +49 -44
  46. data/test/api/test_locations_api.rb +2 -5
  47. data/test/test_helper.rb +1 -1
  48. metadata +11 -6
  49. data/lib/square/api/v1_employees_api.rb +0 -749
  50. data/lib/square/api/v1_items_api.rb +0 -1766
@@ -5,7 +5,8 @@ module Square
5
5
  super(config, http_call_back: http_call_back)
6
6
  end
7
7
 
8
- # Creates a loyalty account.
8
+ # Creates a loyalty account. To create a loyalty account, you must provide
9
+ # the `program_id` and a `mapping` with the `phone_number` of the buyer.
9
10
  # @param [CreateLoyaltyAccountRequest] body Required parameter: An object
10
11
  # containing the fields to POST for the request. See the corresponding
11
12
  # object definition for field details.
@@ -19,7 +20,7 @@ module Square
19
20
  # Prepare headers.
20
21
  _headers = {
21
22
  'accept' => 'application/json',
22
- 'content-type' => 'application/json; charset=utf-8'
23
+ 'Content-Type' => 'application/json'
23
24
  }
24
25
 
25
26
  # Prepare and execute HttpRequest.
@@ -57,7 +58,7 @@ module Square
57
58
  # Prepare headers.
58
59
  _headers = {
59
60
  'accept' => 'application/json',
60
- 'content-type' => 'application/json; charset=utf-8'
61
+ 'Content-Type' => 'application/json'
61
62
  }
62
63
 
63
64
  # Prepare and execute HttpRequest.
@@ -79,7 +80,7 @@ module Square
79
80
 
80
81
  # Retrieves a loyalty account.
81
82
  # @param [String] account_id Required parameter: The ID of the [loyalty
82
- # account](#type-LoyaltyAccount) to retrieve.
83
+ # account]($m/LoyaltyAccount) to retrieve.
83
84
  # @return [RetrieveLoyaltyAccountResponse Hash] response from the API call
84
85
  def retrieve_loyalty_account(account_id:)
85
86
  # Prepare query url.
@@ -119,14 +120,12 @@ module Square
119
120
  # account.
120
121
  # - If you are not using the Orders API to manage orders,
121
122
  # you first perform a client-side computation to compute the points.
122
- # For spend-based and visit-based programs, you can call
123
- # [CalculateLoyaltyPoints](#endpoint-Loyalty-CalculateLoyaltyPoints) to
124
- # compute the points. For more information,
125
- # see [Loyalty Program
126
- # Overview](https://developer.squareup.com/docs/loyalty/overview).
127
- # You then provide the points in a request to this endpoint.
123
+ # For spend-based and visit-based programs, you can first call
124
+ # [CalculateLoyaltyPoints]($e/Loyalty/CalculateLoyaltyPoints) to compute the
125
+ # points
126
+ # that you provide to this endpoint.
128
127
  # @param [String] account_id Required parameter: The [loyalty
129
- # account](#type-LoyaltyAccount) ID to which to add the points.
128
+ # account]($m/LoyaltyAccount) ID to which to add the points.
130
129
  # @param [AccumulateLoyaltyPointsRequest] body Required parameter: An object
131
130
  # containing the fields to POST for the request. See the corresponding
132
131
  # object definition for field details.
@@ -145,7 +144,7 @@ module Square
145
144
  # Prepare headers.
146
145
  _headers = {
147
146
  'accept' => 'application/json',
148
- 'content-type' => 'application/json; charset=utf-8'
147
+ 'Content-Type' => 'application/json'
149
148
  }
150
149
 
151
150
  # Prepare and execute HttpRequest.
@@ -168,10 +167,10 @@ module Square
168
167
  # Adds points to or subtracts points from a buyer's account.
169
168
  # Use this endpoint only when you need to manually adjust points. Otherwise,
170
169
  # in your application flow, you call
171
- # [AccumulateLoyaltyPoints](#endpoint-Loyalty-AccumulateLoyaltyPoints)
170
+ # [AccumulateLoyaltyPoints]($e/Loyalty/AccumulateLoyaltyPoints)
172
171
  # to add points when a buyer pays for the purchase.
173
172
  # @param [String] account_id Required parameter: The ID of the [loyalty
174
- # account](#type-LoyaltyAccount) in which to adjust the points.
173
+ # account]($m/LoyaltyAccount) in which to adjust the points.
175
174
  # @param [AdjustLoyaltyPointsRequest] body Required parameter: An object
176
175
  # containing the fields to POST for the request. See the corresponding
177
176
  # object definition for field details.
@@ -190,7 +189,7 @@ module Square
190
189
  # Prepare headers.
191
190
  _headers = {
192
191
  'accept' => 'application/json',
193
- 'content-type' => 'application/json; charset=utf-8'
192
+ 'Content-Type' => 'application/json'
194
193
  }
195
194
 
196
195
  # Prepare and execute HttpRequest.
@@ -217,6 +216,7 @@ module Square
217
216
  # (for example, points earned, points redeemed, and points expired) is
218
217
  # recorded in the ledger. Using this endpoint, you can search the ledger for
219
218
  # events.
219
+ # Search results are sorted by `created_at` in descending order.
220
220
  # @param [SearchLoyaltyEventsRequest] body Required parameter: An object
221
221
  # containing the fields to POST for the request. See the corresponding
222
222
  # object definition for field details.
@@ -230,7 +230,7 @@ module Square
230
230
  # Prepare headers.
231
231
  _headers = {
232
232
  'accept' => 'application/json',
233
- 'content-type' => 'application/json; charset=utf-8'
233
+ 'Content-Type' => 'application/json'
234
234
  }
235
235
 
236
236
  # Prepare and execute HttpRequest.
@@ -251,9 +251,16 @@ module Square
251
251
  end
252
252
 
253
253
  # Returns a list of loyalty programs in the seller's account.
254
- # Currently, a seller can only have one loyalty program.
254
+ # Loyalty programs define how buyers can earn points and redeem points for
255
+ # rewards. Square sellers can have only one loyalty program, which is
256
+ # created and managed from the Seller Dashboard. For more information, see
257
+ # [Loyalty Program
258
+ # Overview](https://developer.squareup.com/docs/loyalty/overview).
259
+ # Replaced with [RetrieveLoyaltyProgram]($e/Loyalty/RetrieveLoyaltyProgram)
260
+ # when used with the keyword `main`.
255
261
  # @return [ListLoyaltyProgramsResponse Hash] response from the API call
256
262
  def list_loyalty_programs
263
+ warn 'Endpoint list_loyalty_programs in LoyaltyApi is deprecated'
257
264
  # Prepare query url.
258
265
  _query_builder = config.get_base_uri
259
266
  _query_builder << '/v2/loyalty/programs'
@@ -280,9 +287,51 @@ module Square
280
287
  )
281
288
  end
282
289
 
290
+ # Retrieves the loyalty program in a seller's account, specified by the
291
+ # program ID or the keyword `main`.
292
+ # Loyalty programs define how buyers can earn points and redeem points for
293
+ # rewards. Square sellers can have only one loyalty program, which is
294
+ # created and managed from the Seller Dashboard. For more information, see
295
+ # [Loyalty Program
296
+ # Overview](https://developer.squareup.com/docs/loyalty/overview).
297
+ # @param [String] program_id Required parameter: The ID of the loyalty
298
+ # program or the keyword `main`. Either value can be used to retrieve the
299
+ # single loyalty program that belongs to the seller.
300
+ # @return [RetrieveLoyaltyProgramResponse Hash] response from the API call
301
+ def retrieve_loyalty_program(program_id:)
302
+ # Prepare query url.
303
+ _query_builder = config.get_base_uri
304
+ _query_builder << '/v2/loyalty/programs/{program_id}'
305
+ _query_builder = APIHelper.append_url_with_template_parameters(
306
+ _query_builder,
307
+ 'program_id' => { 'value' => program_id, 'encode' => true }
308
+ )
309
+ _query_url = APIHelper.clean_url _query_builder
310
+
311
+ # Prepare headers.
312
+ _headers = {
313
+ 'accept' => 'application/json'
314
+ }
315
+
316
+ # Prepare and execute HttpRequest.
317
+ _request = config.http_client.get(
318
+ _query_url,
319
+ headers: _headers
320
+ )
321
+ OAuth2.apply(config, _request)
322
+ _response = execute_request(_request)
323
+
324
+ # Return appropriate response type.
325
+ decoded = APIHelper.json_deserialize(_response.raw_body)
326
+ _errors = APIHelper.map_response(decoded, ['errors'])
327
+ ApiResponse.new(
328
+ _response, data: decoded, errors: _errors
329
+ )
330
+ end
331
+
283
332
  # Calculates the points a purchase earns.
284
- # - If you are using the Orders API to manage orders, you provide `order_id`
285
- # in the request. The
333
+ # - If you are using the Orders API to manage orders, you provide the
334
+ # `order_id` in the request. The
286
335
  # endpoint calculates the points by reading the order.
287
336
  # - If you are not using the Orders API to manage orders, you provide the
288
337
  # purchase amount in
@@ -290,8 +339,11 @@ module Square
290
339
  # An application might call this endpoint to show the points that a buyer
291
340
  # can earn with the
292
341
  # specific purchase.
342
+ # For spend-based and visit-based programs, the `tax_mode` setting of the
343
+ # accrual rule indicates how taxes should be treated for loyalty points
344
+ # accrual.
293
345
  # @param [String] program_id Required parameter: The [loyalty
294
- # program](#type-LoyaltyProgram) ID, which defines the rules for accruing
346
+ # program]($m/LoyaltyProgram) ID, which defines the rules for accruing
295
347
  # points.
296
348
  # @param [CalculateLoyaltyPointsRequest] body Required parameter: An object
297
349
  # containing the fields to POST for the request. See the corresponding
@@ -311,7 +363,7 @@ module Square
311
363
  # Prepare headers.
312
364
  _headers = {
313
365
  'accept' => 'application/json',
314
- 'content-type' => 'application/json; charset=utf-8'
366
+ 'Content-Type' => 'application/json'
315
367
  }
316
368
 
317
369
  # Prepare and execute HttpRequest.
@@ -352,7 +404,7 @@ module Square
352
404
  # Prepare headers.
353
405
  _headers = {
354
406
  'accept' => 'application/json',
355
- 'content-type' => 'application/json; charset=utf-8'
407
+ 'Content-Type' => 'application/json'
356
408
  }
357
409
 
358
410
  # Prepare and execute HttpRequest.
@@ -372,11 +424,13 @@ module Square
372
424
  )
373
425
  end
374
426
 
375
- # Searches for loyalty rewards in a loyalty account.
376
- # In the current implementation, the endpoint supports search by the reward
377
- # `status`.
427
+ # Searches for loyalty rewards. This endpoint accepts a request with no
428
+ # query filters and returns results for all loyalty accounts.
429
+ # If you include a `query` object, `loyalty_account_id` is required and
430
+ # `status` is optional.
378
431
  # If you know a reward ID, use the
379
- # [RetrieveLoyaltyReward](#endpoint-Loyalty-RetrieveLoyaltyReward) endpoint.
432
+ # [RetrieveLoyaltyReward]($e/Loyalty/RetrieveLoyaltyReward) endpoint.
433
+ # Search results are sorted by `updated_at` in descending order.
380
434
  # @param [SearchLoyaltyRewardsRequest] body Required parameter: An object
381
435
  # containing the fields to POST for the request. See the corresponding
382
436
  # object definition for field details.
@@ -390,7 +444,7 @@ module Square
390
444
  # Prepare headers.
391
445
  _headers = {
392
446
  'accept' => 'application/json',
393
- 'content-type' => 'application/json; charset=utf-8'
447
+ 'Content-Type' => 'application/json'
394
448
  }
395
449
 
396
450
  # Prepare and execute HttpRequest.
@@ -413,12 +467,12 @@ module Square
413
467
  # Deletes a loyalty reward by doing the following:
414
468
  # - Returns the loyalty points back to the loyalty account.
415
469
  # - If an order ID was specified when the reward was created
416
- # (see [CreateLoyaltyReward](#endpoint-Loyalty-CreateLoyaltyReward)),
470
+ # (see [CreateLoyaltyReward]($e/Loyalty/CreateLoyaltyReward)),
417
471
  # it updates the order by removing the reward and related
418
472
  # discounts.
419
473
  # You cannot delete a reward that has reached the terminal state (REDEEMED).
420
474
  # @param [String] reward_id Required parameter: The ID of the [loyalty
421
- # reward](#type-LoyaltyReward) to delete.
475
+ # reward]($m/LoyaltyReward) to delete.
422
476
  # @return [DeleteLoyaltyRewardResponse Hash] response from the API call
423
477
  def delete_loyalty_reward(reward_id:)
424
478
  # Prepare query url.
@@ -453,7 +507,7 @@ module Square
453
507
 
454
508
  # Retrieves a loyalty reward.
455
509
  # @param [String] reward_id Required parameter: The ID of the [loyalty
456
- # reward](#type-LoyaltyReward) to retrieve.
510
+ # reward]($m/LoyaltyReward) to retrieve.
457
511
  # @return [RetrieveLoyaltyRewardResponse Hash] response from the API call
458
512
  def retrieve_loyalty_reward(reward_id:)
459
513
  # Prepare query url.
@@ -495,7 +549,7 @@ module Square
495
549
  # In other words, points used for the reward cannot be returned
496
550
  # to the account.
497
551
  # @param [String] reward_id Required parameter: The ID of the [loyalty
498
- # reward](#type-LoyaltyReward) to redeem.
552
+ # reward]($m/LoyaltyReward) to redeem.
499
553
  # @param [RedeemLoyaltyRewardRequest] body Required parameter: An object
500
554
  # containing the fields to POST for the request. See the corresponding
501
555
  # object definition for field details.
@@ -514,7 +568,7 @@ module Square
514
568
  # Prepare headers.
515
569
  _headers = {
516
570
  'accept' => 'application/json',
517
- 'content-type' => 'application/json; charset=utf-8'
571
+ 'Content-Type' => 'application/json'
518
572
  }
519
573
 
520
574
  # Prepare and execute HttpRequest.
@@ -5,15 +5,17 @@ module Square
5
5
  super(config, http_call_back: http_call_back)
6
6
  end
7
7
 
8
- # Returns `Merchant` information for a given access token.
9
- # If you don't know a `Merchant` ID, you can use this endpoint to retrieve
10
- # the merchant ID for an access token.
11
- # You can specify your personal access token to get your own merchant
12
- # information or specify an OAuth token
13
- # to get the information for the merchant that granted you access.
8
+ # Provides details about the merchant associated with a given access token.
9
+ # The access token used to connect your application to a Square seller is
10
+ # associated
11
+ # with a single merchant. That means that `ListMerchants` returns a list
12
+ # with a single `Merchant` object. You can specify your personal access
13
+ # token
14
+ # to get your own merchant information or specify an OAuth token to get the
15
+ # information for the merchant that granted your application access.
14
16
  # If you know the merchant ID, you can also use the
15
- # [RetrieveMerchant](#endpoint-merchants-retrievemerchant)
16
- # endpoint to get the merchant information.
17
+ # [RetrieveMerchant]($e/Merchants/RetrieveMerchant)
18
+ # endpoint to retrieve the merchant information.
17
19
  # @param [Integer] cursor Optional parameter: The cursor generated by the
18
20
  # previous response.
19
21
  # @return [ListMerchantsResponse Hash] response from the API call
@@ -48,7 +50,7 @@ module Square
48
50
  )
49
51
  end
50
52
 
51
- # Retrieve a `Merchant` object for the given `merchant_id`.
53
+ # Retrieves the `Merchant` object for the given `merchant_id`.
52
54
  # @param [String] merchant_id Required parameter: The ID of the merchant to
53
55
  # retrieve. If the string "me" is supplied as the ID, then retrieve the
54
56
  # merchant that is currently accessible to this call.
@@ -6,9 +6,9 @@ module Square
6
6
  end
7
7
 
8
8
  # Generates code to authorize a mobile application to connect to a Square
9
- # card reader
10
- # Authorization codes are one-time-use and expire __60 minutes__ after being
11
- # issued.
9
+ # card reader.
10
+ # Authorization codes are one-time-use codes and expire 60 minutes after
11
+ # being issued.
12
12
  # __Important:__ The `Authorization` header you provide to this endpoint
13
13
  # must have the following format:
14
14
  # ```
@@ -31,7 +31,7 @@ module Square
31
31
  # Prepare headers.
32
32
  _headers = {
33
33
  'accept' => 'application/json',
34
- 'content-type' => 'application/json; charset=utf-8'
34
+ 'Content-Type' => 'application/json'
35
35
  }
36
36
 
37
37
  # Prepare and execute HttpRequest.
@@ -7,16 +7,16 @@ module Square
7
7
 
8
8
  # `RenewToken` is deprecated. For information about refreshing OAuth access
9
9
  # tokens, see
10
- # [Renew OAuth
11
- # Token](https://developer.squareup.com/docs/oauth-api/cookbook/renew-oauth-
12
- # tokens).
10
+ # [Migrate from Renew to Refresh OAuth
11
+ # Tokens](https://developer.squareup.com/docs/oauth-api/migrate-to-refresh-t
12
+ # okens).
13
13
  # Renews an OAuth access token before it expires.
14
14
  # OAuth access tokens besides your application's personal access token
15
- # expire after __30 days__.
16
- # You can also renew expired tokens within __15 days__ of their expiration.
15
+ # expire after 30 days.
16
+ # You can also renew expired tokens within 15 days of their expiration.
17
17
  # You cannot renew an access token that has been expired for more than 15
18
18
  # days.
19
- # Instead, the associated user must re-complete the OAuth flow from the
19
+ # Instead, the associated user must recomplete the OAuth flow from the
20
20
  # beginning.
21
21
  # __Important:__ The `Authorization` header for this endpoint must have the
22
22
  # following format:
@@ -25,10 +25,10 @@ module Square
25
25
  # ```
26
26
  # Replace `APPLICATION_SECRET` with the application secret on the
27
27
  # Credentials
28
- # page in the [application dashboard](https://connect.squareup.com/apps).
29
- # @param [String] client_id Required parameter: Your application ID,
30
- # available from the [application
31
- # dashboard](https://connect.squareup.com/apps).
28
+ # page in the [Developer Dashboard](https://developer.squareup.com/apps).
29
+ # @param [String] client_id Required parameter: Your application ID, which
30
+ # is available in the OAuth page in the [Developer
31
+ # Dashboard](https://developer.squareup.com/apps).
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.
@@ -51,7 +51,7 @@ module Square
51
51
  # Prepare headers.
52
52
  _headers = {
53
53
  'accept' => 'application/json',
54
- 'content-type' => 'application/json; charset=utf-8',
54
+ 'Content-Type' => 'application/json',
55
55
  'Authorization' => authorization
56
56
  }
57
57
 
@@ -83,9 +83,8 @@ module Square
83
83
  # ```
84
84
  # Authorization: Client APPLICATION_SECRET
85
85
  # ```
86
- # Replace `APPLICATION_SECRET` with the application secret on the
87
- # Credentials
88
- # page in the [Developer Dashboard](https://developer.squareup.com/apps).
86
+ # Replace `APPLICATION_SECRET` with the application secret on the OAuth
87
+ # page for your application on the Developer Dashboard.
89
88
  # @param [RevokeTokenRequest] body Required parameter: An object containing
90
89
  # the fields to POST for the request. See the corresponding object
91
90
  # definition for field details.
@@ -102,7 +101,7 @@ module Square
102
101
  # Prepare headers.
103
102
  _headers = {
104
103
  'accept' => 'application/json',
105
- 'content-type' => 'application/json; charset=utf-8',
104
+ 'Content-Type' => 'application/json',
106
105
  'Authorization' => authorization
107
106
  }
108
107
 
@@ -122,15 +121,22 @@ module Square
122
121
  )
123
122
  end
124
123
 
125
- # Returns an OAuth access token.
126
- # The endpoint supports distinct methods of obtaining OAuth access tokens.
127
- # Applications specify a method by adding the `grant_type` parameter
128
- # in the request and also provide relevant information.
129
- # __Note:__ Regardless of the method application specified,
130
- # the endpoint always returns two items; an OAuth access token and
131
- # a refresh token in the response.
132
- # __OAuth tokens should only live on secure servers. Application clients
133
- # 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.
134
140
  # @param [ObtainTokenRequest] body Required parameter: An object containing
135
141
  # the fields to POST for the request. See the corresponding object
136
142
  # definition for field details.
@@ -144,7 +150,7 @@ module Square
144
150
  # Prepare headers.
145
151
  _headers = {
146
152
  'accept' => 'application/json',
147
- 'content-type' => 'application/json; charset=utf-8'
153
+ 'Content-Type' => 'application/json'
148
154
  }
149
155
 
150
156
  # Prepare and execute HttpRequest.