fangkuai.rb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +10 -0
  3. data/README.md +1 -0
  4. data/lib/square.rb +61 -0
  5. data/lib/square/api/apple_pay_api.rb +50 -0
  6. data/lib/square/api/bank_accounts_api.rb +136 -0
  7. data/lib/square/api/base_api.rb +43 -0
  8. data/lib/square/api/cash_drawers_api.rb +150 -0
  9. data/lib/square/api/catalog_api.rb +572 -0
  10. data/lib/square/api/checkout_api.rb +49 -0
  11. data/lib/square/api/customer_groups_api.rb +182 -0
  12. data/lib/square/api/customer_segments_api.rb +78 -0
  13. data/lib/square/api/customers_api.rb +418 -0
  14. data/lib/square/api/devices_api.rb +120 -0
  15. data/lib/square/api/disputes_api.rb +398 -0
  16. data/lib/square/api/employees_api.rb +87 -0
  17. data/lib/square/api/inventory_api.rb +296 -0
  18. data/lib/square/api/invoices_api.rb +358 -0
  19. data/lib/square/api/labor_api.rb +630 -0
  20. data/lib/square/api/locations_api.rb +151 -0
  21. data/lib/square/api/loyalty_api.rb +543 -0
  22. data/lib/square/api/merchants_api.rb +83 -0
  23. data/lib/square/api/mobile_authorization_api.rb +52 -0
  24. data/lib/square/api/o_auth_api.rb +163 -0
  25. data/lib/square/api/orders_api.rb +280 -0
  26. data/lib/square/api/payments_api.rb +279 -0
  27. data/lib/square/api/refunds_api.rb +145 -0
  28. data/lib/square/api/subscriptions_api.rb +251 -0
  29. data/lib/square/api/team_api.rb +326 -0
  30. data/lib/square/api/terminal_api.rb +141 -0
  31. data/lib/square/api/transactions_api.rb +369 -0
  32. data/lib/square/api/v1_employees_api.rb +723 -0
  33. data/lib/square/api/v1_items_api.rb +1686 -0
  34. data/lib/square/api/v1_locations_api.rb +65 -0
  35. data/lib/square/api/v1_transactions_api.rb +572 -0
  36. data/lib/square/api_helper.rb +276 -0
  37. data/lib/square/client.rb +211 -0
  38. data/lib/square/configuration.rb +101 -0
  39. data/lib/square/exceptions/api_exception.rb +15 -0
  40. data/lib/square/http/api_response.rb +45 -0
  41. data/lib/square/http/auth/o_auth2.rb +12 -0
  42. data/lib/square/http/faraday_client.rb +55 -0
  43. data/lib/square/http/http_call_back.rb +19 -0
  44. data/lib/square/http/http_client.rb +99 -0
  45. data/lib/square/http/http_method_enum.rb +8 -0
  46. data/lib/square/http/http_request.rb +45 -0
  47. data/lib/square/http/http_response.rb +24 -0
  48. data/lib/square/utilities/file_wrapper.rb +12 -0
  49. data/spec/user_journey_spec.rb +148 -0
  50. data/test/api/api_test_base.rb +24 -0
  51. data/test/api/test_catalog_api.rb +59 -0
  52. data/test/api/test_customers_api.rb +45 -0
  53. data/test/api/test_employees_api.rb +36 -0
  54. data/test/api/test_labor_api.rb +74 -0
  55. data/test/api/test_locations_api.rb +35 -0
  56. data/test/api/test_merchants_api.rb +40 -0
  57. data/test/api/test_payments_api.rb +42 -0
  58. data/test/api/test_refunds_api.rb +41 -0
  59. data/test/http_response_catcher.rb +19 -0
  60. data/test/test_helper.rb +94 -0
  61. metadata +199 -0
@@ -0,0 +1,65 @@
1
+ module Square
2
+ # V1LocationsApi
3
+ class V1LocationsApi < BaseApi
4
+ def initialize(config, http_call_back: nil)
5
+ super(config, http_call_back: http_call_back)
6
+ end
7
+
8
+ # Get the general information for a business.
9
+ # @return [V1Merchant Hash] response from the API call
10
+ def retrieve_business
11
+ warn 'Endpoint retrieve_business in V1LocationsApi is deprecated'
12
+ # Prepare query url.
13
+ _query_builder = config.get_base_uri
14
+ _query_builder << '/v1/me'
15
+ _query_url = APIHelper.clean_url _query_builder
16
+
17
+ # Prepare headers.
18
+ _headers = {
19
+ 'accept' => 'application/json'
20
+ }
21
+
22
+ # Prepare and execute HttpRequest.
23
+ _request = config.http_client.get(
24
+ _query_url,
25
+ headers: _headers
26
+ )
27
+ OAuth2.apply(config, _request)
28
+ _response = execute_request(_request)
29
+
30
+ # Return appropriate response type.
31
+ decoded = APIHelper.json_deserialize(_response.raw_body)
32
+ _errors = APIHelper.map_response(decoded, ['errors'])
33
+ ApiResponse.new(_response, data: decoded, errors: _errors)
34
+ end
35
+
36
+ # Provides details for all business locations associated with a Square
37
+ # account, including the Square-assigned object ID for the location.
38
+ # @return [List of V1Merchant Hash] response from the API call
39
+ def list_locations
40
+ warn 'Endpoint list_locations in V1LocationsApi is deprecated'
41
+ # Prepare query url.
42
+ _query_builder = config.get_base_uri
43
+ _query_builder << '/v1/me/locations'
44
+ _query_url = APIHelper.clean_url _query_builder
45
+
46
+ # Prepare headers.
47
+ _headers = {
48
+ 'accept' => 'application/json'
49
+ }
50
+
51
+ # Prepare and execute HttpRequest.
52
+ _request = config.http_client.get(
53
+ _query_url,
54
+ headers: _headers
55
+ )
56
+ OAuth2.apply(config, _request)
57
+ _response = execute_request(_request)
58
+
59
+ # Return appropriate response type.
60
+ decoded = APIHelper.json_deserialize(_response.raw_body)
61
+ _errors = APIHelper.map_response(decoded, ['errors'])
62
+ ApiResponse.new(_response, data: decoded, errors: _errors)
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,572 @@
1
+ module Square
2
+ # V1TransactionsApi
3
+ class V1TransactionsApi < BaseApi
4
+ def initialize(config, http_call_back: nil)
5
+ super(config, http_call_back: http_call_back)
6
+ end
7
+
8
+ # Provides non-confidential details for all of a location's associated bank
9
+ # accounts. This endpoint does not provide full bank account numbers, and
10
+ # there is no way to obtain a full bank account number with the Connect API.
11
+ # @param [String] location_id Required parameter: The ID of the location to
12
+ # list bank accounts for.
13
+ # @return [List of V1BankAccount Hash] response from the API call
14
+ def list_bank_accounts(location_id:)
15
+ warn 'Endpoint list_bank_accounts in V1TransactionsApi is deprecated'
16
+ # Prepare query url.
17
+ _query_builder = config.get_base_uri
18
+ _query_builder << '/v1/{location_id}/bank-accounts'
19
+ _query_builder = APIHelper.append_url_with_template_parameters(
20
+ _query_builder,
21
+ 'location_id' => location_id
22
+ )
23
+ _query_url = APIHelper.clean_url _query_builder
24
+
25
+ # Prepare headers.
26
+ _headers = {
27
+ 'accept' => 'application/json'
28
+ }
29
+
30
+ # Prepare and execute HttpRequest.
31
+ _request = config.http_client.get(
32
+ _query_url,
33
+ headers: _headers
34
+ )
35
+ OAuth2.apply(config, _request)
36
+ _response = execute_request(_request)
37
+
38
+ # Return appropriate response type.
39
+ decoded = APIHelper.json_deserialize(_response.raw_body)
40
+ _errors = APIHelper.map_response(decoded, ['errors'])
41
+ ApiResponse.new(_response, data: decoded, errors: _errors)
42
+ end
43
+
44
+ # Provides non-confidential details for a merchant's associated bank
45
+ # account. This endpoint does not provide full bank account numbers, and
46
+ # there is no way to obtain a full bank account number with the Connect API.
47
+ # @param [String] location_id Required parameter: The ID of the bank
48
+ # account's associated location.
49
+ # @param [String] bank_account_id Required parameter: The bank account's
50
+ # Square-issued ID. You obtain this value from Settlement objects
51
+ # returned.
52
+ # @return [V1BankAccount Hash] response from the API call
53
+ def retrieve_bank_account(location_id:,
54
+ bank_account_id:)
55
+ warn 'Endpoint retrieve_bank_account in V1TransactionsApi is deprecated'
56
+ # Prepare query url.
57
+ _query_builder = config.get_base_uri
58
+ _query_builder << '/v1/{location_id}/bank-accounts/{bank_account_id}'
59
+ _query_builder = APIHelper.append_url_with_template_parameters(
60
+ _query_builder,
61
+ 'location_id' => location_id,
62
+ 'bank_account_id' => bank_account_id
63
+ )
64
+ _query_url = APIHelper.clean_url _query_builder
65
+
66
+ # Prepare headers.
67
+ _headers = {
68
+ 'accept' => 'application/json'
69
+ }
70
+
71
+ # Prepare and execute HttpRequest.
72
+ _request = config.http_client.get(
73
+ _query_url,
74
+ headers: _headers
75
+ )
76
+ OAuth2.apply(config, _request)
77
+ _response = execute_request(_request)
78
+
79
+ # Return appropriate response type.
80
+ decoded = APIHelper.json_deserialize(_response.raw_body)
81
+ _errors = APIHelper.map_response(decoded, ['errors'])
82
+ ApiResponse.new(_response, data: decoded, errors: _errors)
83
+ end
84
+
85
+ # Provides summary information for a merchant's online store orders.
86
+ # @param [String] location_id Required parameter: The ID of the location to
87
+ # list online store orders for.
88
+ # @param [SortOrder] order Optional parameter: TThe order in which payments
89
+ # are listed in the response.
90
+ # @param [Integer] limit Optional parameter: The maximum number of payments
91
+ # to return in a single response. This value cannot exceed 200.
92
+ # @param [String] batch_token Optional parameter: A pagination cursor to
93
+ # retrieve the next set of results for your original query to the
94
+ # endpoint.
95
+ # @return [List of V1Order Hash] response from the API call
96
+ def list_orders(location_id:,
97
+ order: nil,
98
+ limit: nil,
99
+ batch_token: nil)
100
+ # Prepare query url.
101
+ _query_builder = config.get_base_uri
102
+ _query_builder << '/v1/{location_id}/orders'
103
+ _query_builder = APIHelper.append_url_with_template_parameters(
104
+ _query_builder,
105
+ 'location_id' => location_id
106
+ )
107
+ _query_builder = APIHelper.append_url_with_query_parameters(
108
+ _query_builder,
109
+ 'order' => order,
110
+ 'limit' => limit,
111
+ 'batch_token' => batch_token
112
+ )
113
+ _query_url = APIHelper.clean_url _query_builder
114
+
115
+ # Prepare headers.
116
+ _headers = {
117
+ 'accept' => 'application/json'
118
+ }
119
+
120
+ # Prepare and execute HttpRequest.
121
+ _request = config.http_client.get(
122
+ _query_url,
123
+ headers: _headers
124
+ )
125
+ OAuth2.apply(config, _request)
126
+ _response = execute_request(_request)
127
+
128
+ # Return appropriate response type.
129
+ decoded = APIHelper.json_deserialize(_response.raw_body)
130
+ _errors = APIHelper.map_response(decoded, ['errors'])
131
+ ApiResponse.new(_response, data: decoded, errors: _errors)
132
+ end
133
+
134
+ # Provides comprehensive information for a single online store order,
135
+ # including the order's history.
136
+ # @param [String] location_id Required parameter: The ID of the order's
137
+ # associated location.
138
+ # @param [String] order_id Required parameter: The order's Square-issued ID.
139
+ # You obtain this value from Order objects returned by the List Orders
140
+ # endpoint
141
+ # @return [V1Order Hash] response from the API call
142
+ def retrieve_order(location_id:,
143
+ order_id:)
144
+ # Prepare query url.
145
+ _query_builder = config.get_base_uri
146
+ _query_builder << '/v1/{location_id}/orders/{order_id}'
147
+ _query_builder = APIHelper.append_url_with_template_parameters(
148
+ _query_builder,
149
+ 'location_id' => location_id,
150
+ 'order_id' => order_id
151
+ )
152
+ _query_url = APIHelper.clean_url _query_builder
153
+
154
+ # Prepare headers.
155
+ _headers = {
156
+ 'accept' => 'application/json'
157
+ }
158
+
159
+ # Prepare and execute HttpRequest.
160
+ _request = config.http_client.get(
161
+ _query_url,
162
+ headers: _headers
163
+ )
164
+ OAuth2.apply(config, _request)
165
+ _response = execute_request(_request)
166
+
167
+ # Return appropriate response type.
168
+ decoded = APIHelper.json_deserialize(_response.raw_body)
169
+ _errors = APIHelper.map_response(decoded, ['errors'])
170
+ ApiResponse.new(_response, data: decoded, errors: _errors)
171
+ end
172
+
173
+ # Updates the details of an online store order. Every update you perform on
174
+ # an order corresponds to one of three actions:
175
+ # @param [String] location_id Required parameter: The ID of the order's
176
+ # associated location.
177
+ # @param [String] order_id Required parameter: The order's Square-issued ID.
178
+ # You obtain this value from Order objects returned by the List Orders
179
+ # endpoint
180
+ # @param [V1UpdateOrderRequest] body Required parameter: An object
181
+ # containing the fields to POST for the request. See the corresponding
182
+ # object definition for field details.
183
+ # @return [V1Order Hash] response from the API call
184
+ def update_order(location_id:,
185
+ order_id:,
186
+ body:)
187
+ # Prepare query url.
188
+ _query_builder = config.get_base_uri
189
+ _query_builder << '/v1/{location_id}/orders/{order_id}'
190
+ _query_builder = APIHelper.append_url_with_template_parameters(
191
+ _query_builder,
192
+ 'location_id' => location_id,
193
+ 'order_id' => order_id
194
+ )
195
+ _query_url = APIHelper.clean_url _query_builder
196
+
197
+ # Prepare headers.
198
+ _headers = {
199
+ 'accept' => 'application/json',
200
+ 'content-type' => 'application/json; charset=utf-8'
201
+ }
202
+
203
+ # Prepare and execute HttpRequest.
204
+ _request = config.http_client.put(
205
+ _query_url,
206
+ headers: _headers,
207
+ parameters: body.to_json
208
+ )
209
+ OAuth2.apply(config, _request)
210
+ _response = execute_request(_request)
211
+
212
+ # Return appropriate response type.
213
+ decoded = APIHelper.json_deserialize(_response.raw_body)
214
+ _errors = APIHelper.map_response(decoded, ['errors'])
215
+ ApiResponse.new(_response, data: decoded, errors: _errors)
216
+ end
217
+
218
+ # Provides summary information for all payments taken for a given
219
+ # Square account during a date range. Date ranges cannot exceed 1 year in
220
+ # length. See Date ranges for details of inclusive and exclusive dates.
221
+ # *Note**: Details for payments processed with Square Point of Sale while
222
+ # in offline mode may not be transmitted to Square for up to 72 hours.
223
+ # Offline payments have a `created_at` value that reflects the time the
224
+ # payment was originally processed, not the time it was subsequently
225
+ # transmitted to Square. Consequently, the ListPayments endpoint might
226
+ # list an offline payment chronologically between online payments that
227
+ # were seen in a previous request.
228
+ # @param [String] location_id Required parameter: The ID of the location to
229
+ # list payments for. If you specify me, this endpoint returns payments
230
+ # aggregated from all of the business's locations.
231
+ # @param [SortOrder] order Optional parameter: The order in which payments
232
+ # are listed in the response.
233
+ # @param [String] begin_time Optional parameter: The beginning of the
234
+ # requested reporting period, in ISO 8601 format. If this value is before
235
+ # January 1, 2013 (2013-01-01T00:00:00Z), this endpoint returns an error.
236
+ # Default value: The current time minus one year.
237
+ # @param [String] end_time Optional parameter: The end of the requested
238
+ # reporting period, in ISO 8601 format. If this value is more than one year
239
+ # greater than begin_time, this endpoint returns an error. Default value:
240
+ # The current time.
241
+ # @param [Integer] limit Optional parameter: The maximum number of payments
242
+ # to return in a single response. This value cannot exceed 200.
243
+ # @param [String] batch_token Optional parameter: A pagination cursor to
244
+ # retrieve the next set of results for your original query to the
245
+ # endpoint.
246
+ # @param [Boolean] include_partial Optional parameter: Indicates whether or
247
+ # not to include partial payments in the response. Partial payments will
248
+ # have the tenders collected so far, but the itemizations will be empty
249
+ # until the payment is completed.
250
+ # @return [List of V1Payment Hash] response from the API call
251
+ def list_payments(location_id:,
252
+ order: nil,
253
+ begin_time: nil,
254
+ end_time: nil,
255
+ limit: nil,
256
+ batch_token: nil,
257
+ include_partial: false)
258
+ # Prepare query url.
259
+ _query_builder = config.get_base_uri
260
+ _query_builder << '/v1/{location_id}/payments'
261
+ _query_builder = APIHelper.append_url_with_template_parameters(
262
+ _query_builder,
263
+ 'location_id' => location_id
264
+ )
265
+ _query_builder = APIHelper.append_url_with_query_parameters(
266
+ _query_builder,
267
+ 'order' => order,
268
+ 'begin_time' => begin_time,
269
+ 'end_time' => end_time,
270
+ 'limit' => limit,
271
+ 'batch_token' => batch_token,
272
+ 'include_partial' => include_partial
273
+ )
274
+ _query_url = APIHelper.clean_url _query_builder
275
+
276
+ # Prepare headers.
277
+ _headers = {
278
+ 'accept' => 'application/json'
279
+ }
280
+
281
+ # Prepare and execute HttpRequest.
282
+ _request = config.http_client.get(
283
+ _query_url,
284
+ headers: _headers
285
+ )
286
+ OAuth2.apply(config, _request)
287
+ _response = execute_request(_request)
288
+
289
+ # Return appropriate response type.
290
+ decoded = APIHelper.json_deserialize(_response.raw_body)
291
+ _errors = APIHelper.map_response(decoded, ['errors'])
292
+ ApiResponse.new(_response, data: decoded, errors: _errors)
293
+ end
294
+
295
+ # Provides comprehensive information for a single payment.
296
+ # @param [String] location_id Required parameter: The ID of the payment's
297
+ # associated location.
298
+ # @param [String] payment_id Required parameter: The Square-issued payment
299
+ # ID. payment_id comes from Payment objects returned by the List Payments
300
+ # endpoint, Settlement objects returned by the List Settlements endpoint, or
301
+ # Refund objects returned by the List Refunds endpoint.
302
+ # @return [V1Payment Hash] response from the API call
303
+ def retrieve_payment(location_id:,
304
+ payment_id:)
305
+ # Prepare query url.
306
+ _query_builder = config.get_base_uri
307
+ _query_builder << '/v1/{location_id}/payments/{payment_id}'
308
+ _query_builder = APIHelper.append_url_with_template_parameters(
309
+ _query_builder,
310
+ 'location_id' => location_id,
311
+ 'payment_id' => payment_id
312
+ )
313
+ _query_url = APIHelper.clean_url _query_builder
314
+
315
+ # Prepare headers.
316
+ _headers = {
317
+ 'accept' => 'application/json'
318
+ }
319
+
320
+ # Prepare and execute HttpRequest.
321
+ _request = config.http_client.get(
322
+ _query_url,
323
+ headers: _headers
324
+ )
325
+ OAuth2.apply(config, _request)
326
+ _response = execute_request(_request)
327
+
328
+ # Return appropriate response type.
329
+ decoded = APIHelper.json_deserialize(_response.raw_body)
330
+ _errors = APIHelper.map_response(decoded, ['errors'])
331
+ ApiResponse.new(_response, data: decoded, errors: _errors)
332
+ end
333
+
334
+ # Provides the details for all refunds initiated by a merchant or any of the
335
+ # merchant's mobile staff during a date range. Date ranges cannot exceed one
336
+ # year in length.
337
+ # @param [String] location_id Required parameter: The ID of the location to
338
+ # list refunds for.
339
+ # @param [SortOrder] order Optional parameter: TThe order in which payments
340
+ # are listed in the response.
341
+ # @param [String] begin_time Optional parameter: The beginning of the
342
+ # requested reporting period, in ISO 8601 format. If this value is before
343
+ # January 1, 2013 (2013-01-01T00:00:00Z), this endpoint returns an error.
344
+ # Default value: The current time minus one year.
345
+ # @param [String] end_time Optional parameter: The end of the requested
346
+ # reporting period, in ISO 8601 format. If this value is more than one year
347
+ # greater than begin_time, this endpoint returns an error. Default value:
348
+ # The current time.
349
+ # @param [Integer] limit Optional parameter: The approximate number of
350
+ # refunds to return in a single response. Default: 100. Max: 200. Response
351
+ # may contain more results than the prescribed limit when refunds are made
352
+ # simultaneously to multiple tenders in a payment or when refunds are
353
+ # generated in an exchange to account for the value of returned goods.
354
+ # @param [String] batch_token Optional parameter: A pagination cursor to
355
+ # retrieve the next set of results for your original query to the
356
+ # endpoint.
357
+ # @return [List of V1Refund Hash] response from the API call
358
+ def list_refunds(location_id:,
359
+ order: nil,
360
+ begin_time: nil,
361
+ end_time: nil,
362
+ limit: nil,
363
+ batch_token: nil)
364
+ # Prepare query url.
365
+ _query_builder = config.get_base_uri
366
+ _query_builder << '/v1/{location_id}/refunds'
367
+ _query_builder = APIHelper.append_url_with_template_parameters(
368
+ _query_builder,
369
+ 'location_id' => location_id
370
+ )
371
+ _query_builder = APIHelper.append_url_with_query_parameters(
372
+ _query_builder,
373
+ 'order' => order,
374
+ 'begin_time' => begin_time,
375
+ 'end_time' => end_time,
376
+ 'limit' => limit,
377
+ 'batch_token' => batch_token
378
+ )
379
+ _query_url = APIHelper.clean_url _query_builder
380
+
381
+ # Prepare headers.
382
+ _headers = {
383
+ 'accept' => 'application/json'
384
+ }
385
+
386
+ # Prepare and execute HttpRequest.
387
+ _request = config.http_client.get(
388
+ _query_url,
389
+ headers: _headers
390
+ )
391
+ OAuth2.apply(config, _request)
392
+ _response = execute_request(_request)
393
+
394
+ # Return appropriate response type.
395
+ decoded = APIHelper.json_deserialize(_response.raw_body)
396
+ _errors = APIHelper.map_response(decoded, ['errors'])
397
+ ApiResponse.new(_response, data: decoded, errors: _errors)
398
+ end
399
+
400
+ # Issues a refund for a previously processed payment. You must issue
401
+ # a refund within 60 days of the associated payment.
402
+ # You cannot issue a partial refund for a split tender payment. You must
403
+ # instead issue a full or partial refund for a particular tender, by
404
+ # providing the applicable tender id to the V1CreateRefund endpoint.
405
+ # Issuing a full refund for a split tender payment refunds all tenders
406
+ # associated with the payment.
407
+ # Issuing a refund for a card payment is not reversible. For development
408
+ # purposes, you can create fake cash payments in Square Point of Sale and
409
+ # refund them.
410
+ # @param [String] location_id Required parameter: The ID of the original
411
+ # payment's associated location.
412
+ # @param [V1CreateRefundRequest] body Required parameter: An object
413
+ # containing the fields to POST for the request. See the corresponding
414
+ # object definition for field details.
415
+ # @return [V1Refund Hash] response from the API call
416
+ def create_refund(location_id:,
417
+ body:)
418
+ # Prepare query url.
419
+ _query_builder = config.get_base_uri
420
+ _query_builder << '/v1/{location_id}/refunds'
421
+ _query_builder = APIHelper.append_url_with_template_parameters(
422
+ _query_builder,
423
+ 'location_id' => location_id
424
+ )
425
+ _query_url = APIHelper.clean_url _query_builder
426
+
427
+ # Prepare headers.
428
+ _headers = {
429
+ 'accept' => 'application/json',
430
+ 'content-type' => 'application/json; charset=utf-8'
431
+ }
432
+
433
+ # Prepare and execute HttpRequest.
434
+ _request = config.http_client.post(
435
+ _query_url,
436
+ headers: _headers,
437
+ parameters: body.to_json
438
+ )
439
+ OAuth2.apply(config, _request)
440
+ _response = execute_request(_request)
441
+
442
+ # Return appropriate response type.
443
+ decoded = APIHelper.json_deserialize(_response.raw_body)
444
+ _errors = APIHelper.map_response(decoded, ['errors'])
445
+ ApiResponse.new(_response, data: decoded, errors: _errors)
446
+ end
447
+
448
+ # Provides summary information for all deposits and withdrawals
449
+ # initiated by Square to a linked bank account during a date range. Date
450
+ # ranges cannot exceed one year in length.
451
+ # *Note**: the ListSettlements endpoint does not provide entry
452
+ # information.
453
+ # @param [String] location_id Required parameter: The ID of the location to
454
+ # list settlements for. If you specify me, this endpoint returns settlements
455
+ # aggregated from all of the business's locations.
456
+ # @param [SortOrder] order Optional parameter: The order in which
457
+ # settlements are listed in the response.
458
+ # @param [String] begin_time Optional parameter: The beginning of the
459
+ # requested reporting period, in ISO 8601 format. If this value is before
460
+ # January 1, 2013 (2013-01-01T00:00:00Z), this endpoint returns an error.
461
+ # Default value: The current time minus one year.
462
+ # @param [String] end_time Optional parameter: The end of the requested
463
+ # reporting period, in ISO 8601 format. If this value is more than one year
464
+ # greater than begin_time, this endpoint returns an error. Default value:
465
+ # The current time.
466
+ # @param [Integer] limit Optional parameter: The maximum number of
467
+ # settlements to return in a single response. This value cannot exceed
468
+ # 200.
469
+ # @param [V1ListSettlementsRequestStatus] status Optional parameter: Provide
470
+ # this parameter to retrieve only settlements with a particular status (SENT
471
+ # or FAILED).
472
+ # @param [String] batch_token Optional parameter: A pagination cursor to
473
+ # retrieve the next set of results for your original query to the
474
+ # endpoint.
475
+ # @return [List of V1Settlement Hash] response from the API call
476
+ def list_settlements(location_id:,
477
+ order: nil,
478
+ begin_time: nil,
479
+ end_time: nil,
480
+ limit: nil,
481
+ status: nil,
482
+ batch_token: nil)
483
+ # Prepare query url.
484
+ _query_builder = config.get_base_uri
485
+ _query_builder << '/v1/{location_id}/settlements'
486
+ _query_builder = APIHelper.append_url_with_template_parameters(
487
+ _query_builder,
488
+ 'location_id' => location_id
489
+ )
490
+ _query_builder = APIHelper.append_url_with_query_parameters(
491
+ _query_builder,
492
+ 'order' => order,
493
+ 'begin_time' => begin_time,
494
+ 'end_time' => end_time,
495
+ 'limit' => limit,
496
+ 'status' => status,
497
+ 'batch_token' => batch_token
498
+ )
499
+ _query_url = APIHelper.clean_url _query_builder
500
+
501
+ # Prepare headers.
502
+ _headers = {
503
+ 'accept' => 'application/json'
504
+ }
505
+
506
+ # Prepare and execute HttpRequest.
507
+ _request = config.http_client.get(
508
+ _query_url,
509
+ headers: _headers
510
+ )
511
+ OAuth2.apply(config, _request)
512
+ _response = execute_request(_request)
513
+
514
+ # Return appropriate response type.
515
+ decoded = APIHelper.json_deserialize(_response.raw_body)
516
+ _errors = APIHelper.map_response(decoded, ['errors'])
517
+ ApiResponse.new(_response, data: decoded, errors: _errors)
518
+ end
519
+
520
+ # Provides comprehensive information for a single settlement.
521
+ # The returned `Settlement` objects include an `entries` field that lists
522
+ # the transactions that contribute to the settlement total. Most
523
+ # settlement entries correspond to a payment payout, but settlement
524
+ # entries are also generated for less common events, like refunds, manual
525
+ # adjustments, or chargeback holds.
526
+ # Square initiates its regular deposits as indicated in the
527
+ # [Deposit Options with
528
+ # Square](https://squareup.com/help/us/en/article/3807)
529
+ # help article. Details for a regular deposit are usually not available
530
+ # from Connect API endpoints before 10 p.m. PST the same day.
531
+ # Square does not know when an initiated settlement **completes**, only
532
+ # whether it has failed. A completed settlement is typically reflected in
533
+ # a bank account within 3 business days, but in exceptional cases it may
534
+ # take longer.
535
+ # @param [String] location_id Required parameter: The ID of the
536
+ # settlements's associated location.
537
+ # @param [String] settlement_id Required parameter: The settlement's
538
+ # Square-issued ID. You obtain this value from Settlement objects returned
539
+ # by the List Settlements endpoint.
540
+ # @return [V1Settlement Hash] response from the API call
541
+ def retrieve_settlement(location_id:,
542
+ settlement_id:)
543
+ # Prepare query url.
544
+ _query_builder = config.get_base_uri
545
+ _query_builder << '/v1/{location_id}/settlements/{settlement_id}'
546
+ _query_builder = APIHelper.append_url_with_template_parameters(
547
+ _query_builder,
548
+ 'location_id' => location_id,
549
+ 'settlement_id' => settlement_id
550
+ )
551
+ _query_url = APIHelper.clean_url _query_builder
552
+
553
+ # Prepare headers.
554
+ _headers = {
555
+ 'accept' => 'application/json'
556
+ }
557
+
558
+ # Prepare and execute HttpRequest.
559
+ _request = config.http_client.get(
560
+ _query_url,
561
+ headers: _headers
562
+ )
563
+ OAuth2.apply(config, _request)
564
+ _response = execute_request(_request)
565
+
566
+ # Return appropriate response type.
567
+ decoded = APIHelper.json_deserialize(_response.raw_body)
568
+ _errors = APIHelper.map_response(decoded, ['errors'])
569
+ ApiResponse.new(_response, data: decoded, errors: _errors)
570
+ end
571
+ end
572
+ end