square.rb 26.0.0.20221214 → 26.2.0.20230315

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/lib/square/api/apple_pay_api.rb +14 -30
  4. data/lib/square/api/bank_accounts_api.rb +40 -90
  5. data/lib/square/api/base_api.rb +42 -42
  6. data/lib/square/api/booking_custom_attributes_api.rb +164 -329
  7. data/lib/square/api/bookings_api.rb +135 -260
  8. data/lib/square/api/cards_api.rb +56 -118
  9. data/lib/square/api/cash_drawers_api.rb +47 -103
  10. data/lib/square/api/catalog_api.rb +197 -423
  11. data/lib/square/api/checkout_api.rb +85 -175
  12. data/lib/square/api/customer_custom_attributes_api.rb +150 -303
  13. data/lib/square/api/customer_groups_api.rb +69 -145
  14. data/lib/square/api/customer_segments_api.rb +26 -61
  15. data/lib/square/api/customers_api.rb +147 -294
  16. data/lib/square/api/devices_api.rb +42 -89
  17. data/lib/square/api/disputes_api.rb +130 -288
  18. data/lib/square/api/employees_api.rb +28 -63
  19. data/lib/square/api/gift_card_activities_api.rb +33 -65
  20. data/lib/square/api/gift_cards_api.rb +103 -202
  21. data/lib/square/api/inventory_api.rb +179 -366
  22. data/lib/square/api/invoices_api.rb +118 -237
  23. data/lib/square/api/labor_api.rb +223 -459
  24. data/lib/square/api/location_custom_attributes_api.rb +419 -0
  25. data/lib/square/api/locations_api.rb +54 -112
  26. data/lib/square/api/loyalty_api.rb +259 -512
  27. data/lib/square/api/merchants_api.rb +25 -60
  28. data/lib/square/api/mobile_authorization_api.rb +14 -30
  29. data/lib/square/api/o_auth_api.rb +54 -109
  30. data/lib/square/api/order_custom_attributes_api.rb +168 -333
  31. data/lib/square/api/orders_api.rb +115 -222
  32. data/lib/square/api/payments_api.rb +106 -208
  33. data/lib/square/api/payouts_api.rb +47 -100
  34. data/lib/square/api/refunds_api.rb +46 -93
  35. data/lib/square/api/sites_api.rb +11 -28
  36. data/lib/square/api/snippets_api.rb +42 -90
  37. data/lib/square/api/subscriptions_api.rb +150 -299
  38. data/lib/square/api/team_api.rb +114 -224
  39. data/lib/square/api/terminal_api.rb +162 -328
  40. data/lib/square/api/transactions_api.rb +62 -126
  41. data/lib/square/api/v1_transactions_api.rb +155 -296
  42. data/lib/square/api/vendors_api.rb +99 -192
  43. data/lib/square/api/webhook_subscriptions_api.rb +115 -235
  44. data/lib/square/api_helper.rb +1 -437
  45. data/lib/square/client.rb +82 -46
  46. data/lib/square/configuration.rb +28 -53
  47. data/lib/square/exceptions/api_exception.rb +1 -11
  48. data/lib/square/http/api_response.rb +13 -19
  49. data/lib/square/http/auth/o_auth2.rb +14 -7
  50. data/lib/square/http/http_call_back.rb +1 -15
  51. data/lib/square/http/http_method_enum.rb +1 -4
  52. data/lib/square/http/http_request.rb +1 -45
  53. data/lib/square/http/http_response.rb +1 -20
  54. data/lib/square/utilities/date_time_helper.rb +1 -146
  55. data/lib/square/utilities/file_wrapper.rb +5 -5
  56. data/lib/square.rb +7 -6
  57. data/spec/user_journey_spec.rb +2 -2
  58. data/test/api/api_test_base.rb +13 -5
  59. data/test/api/test_catalog_api.rb +5 -4
  60. data/test/api/test_customers_api.rb +3 -2
  61. data/test/api/test_employees_api.rb +4 -3
  62. data/test/api/test_labor_api.rb +6 -5
  63. data/test/api/test_locations_api.rb +3 -2
  64. data/test/api/test_merchants_api.rb +4 -3
  65. data/test/api/test_payments_api.rb +4 -3
  66. data/test/api/test_refunds_api.rb +4 -3
  67. metadata +12 -111
  68. data/lib/square/exceptions/validation_exception.rb +0 -13
  69. data/lib/square/http/faraday_client.rb +0 -93
  70. data/lib/square/http/http_client.rb +0 -118
  71. data/test/test_helper.rb +0 -89
@@ -1,10 +1,6 @@
1
1
  module Square
2
2
  # BookingsApi
3
3
  class BookingsApi < BaseApi
4
- def initialize(config, http_call_back: nil)
5
- super(config, http_call_back: http_call_back)
6
- end
7
-
8
4
  # Retrieve a collection of bookings.
9
5
  # To call this endpoint with buyer-level permissions, set
10
6
  # `APPOINTMENTS_READ` for the OAuth scope.
@@ -34,42 +30,32 @@ module Square
34
30
  location_id: nil,
35
31
  start_at_min: nil,
36
32
  start_at_max: nil)
37
- # Prepare query url.
38
- _query_builder = config.get_base_uri
39
- _query_builder << '/v2/bookings'
40
- _query_builder = APIHelper.append_url_with_query_parameters(
41
- _query_builder,
42
- 'limit' => limit,
43
- 'cursor' => cursor,
44
- 'team_member_id' => team_member_id,
45
- 'location_id' => location_id,
46
- 'start_at_min' => start_at_min,
47
- 'start_at_max' => start_at_max
48
- )
49
- _query_url = APIHelper.clean_url _query_builder
50
-
51
- # Prepare headers.
52
- _headers = {
53
- 'accept' => 'application/json'
54
- }
55
-
56
- # Prepare and execute HttpRequest.
57
- _request = config.http_client.get(
58
- _query_url,
59
- headers: _headers
60
- )
61
- OAuth2.apply(config, _request)
62
- _response = execute_request(_request)
63
-
64
- # Return appropriate response type.
65
- decoded = APIHelper.json_deserialize(_response.raw_body)
66
- _errors = APIHelper.map_response(decoded, ['errors'])
67
- ApiResponse.new(
68
- _response, data: decoded, errors: _errors
69
- )
33
+ new_api_call_builder
34
+ .request(new_request_builder(HttpMethodEnum::GET,
35
+ '/v2/bookings',
36
+ 'default')
37
+ .query_param(new_parameter(limit, key: 'limit'))
38
+ .query_param(new_parameter(cursor, key: 'cursor'))
39
+ .query_param(new_parameter(team_member_id, key: 'team_member_id'))
40
+ .query_param(new_parameter(location_id, key: 'location_id'))
41
+ .query_param(new_parameter(start_at_min, key: 'start_at_min'))
42
+ .query_param(new_parameter(start_at_max, key: 'start_at_max'))
43
+ .header_param(new_parameter('application/json', key: 'accept'))
44
+ .auth(Single.new('global')))
45
+ .response(new_response_handler
46
+ .deserializer(APIHelper.method(:json_deserialize))
47
+ .is_api_response(true)
48
+ .convertor(ApiResponse.method(:create)))
49
+ .execute
70
50
  end
71
51
 
72
52
  # Creates a booking.
53
+ # The required input must include the following:
54
+ # - `Booking.location_id`,
55
+ # - `Booking.start_at`,
56
+ # - `Booking.team_member_id`
57
+ # - `Booking.AppointmentSegment.service_variation_id`
58
+ # - `Booking.AppointmentSegment.service_variation_version`
73
59
  # To call this endpoint with buyer-level permissions, set
74
60
  # `APPOINTMENTS_WRITE` for the OAuth scope.
75
61
  # To call this endpoint with seller-level permissions, set
@@ -82,32 +68,20 @@ module Square
82
68
  # object definition for field details.
83
69
  # @return [CreateBookingResponse Hash] response from the API call
84
70
  def create_booking(body:)
85
- # Prepare query url.
86
- _query_builder = config.get_base_uri
87
- _query_builder << '/v2/bookings'
88
- _query_url = APIHelper.clean_url _query_builder
89
-
90
- # Prepare headers.
91
- _headers = {
92
- 'accept' => 'application/json',
93
- 'Content-Type' => 'application/json'
94
- }
95
-
96
- # Prepare and execute HttpRequest.
97
- _request = config.http_client.post(
98
- _query_url,
99
- headers: _headers,
100
- parameters: body.to_json
101
- )
102
- OAuth2.apply(config, _request)
103
- _response = execute_request(_request)
104
-
105
- # Return appropriate response type.
106
- decoded = APIHelper.json_deserialize(_response.raw_body)
107
- _errors = APIHelper.map_response(decoded, ['errors'])
108
- ApiResponse.new(
109
- _response, data: decoded, errors: _errors
110
- )
71
+ new_api_call_builder
72
+ .request(new_request_builder(HttpMethodEnum::POST,
73
+ '/v2/bookings',
74
+ 'default')
75
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
76
+ .body_param(new_parameter(body))
77
+ .header_param(new_parameter('application/json', key: 'accept'))
78
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
79
+ .auth(Single.new('global')))
80
+ .response(new_response_handler
81
+ .deserializer(APIHelper.method(:json_deserialize))
82
+ .is_api_response(true)
83
+ .convertor(ApiResponse.method(:create)))
84
+ .execute
111
85
  end
112
86
 
113
87
  # Searches for availabilities for booking.
@@ -120,61 +94,36 @@ module Square
120
94
  # object definition for field details.
121
95
  # @return [SearchAvailabilityResponse Hash] response from the API call
122
96
  def search_availability(body:)
123
- # Prepare query url.
124
- _query_builder = config.get_base_uri
125
- _query_builder << '/v2/bookings/availability/search'
126
- _query_url = APIHelper.clean_url _query_builder
127
-
128
- # Prepare headers.
129
- _headers = {
130
- 'accept' => 'application/json',
131
- 'Content-Type' => 'application/json'
132
- }
133
-
134
- # Prepare and execute HttpRequest.
135
- _request = config.http_client.post(
136
- _query_url,
137
- headers: _headers,
138
- parameters: body.to_json
139
- )
140
- OAuth2.apply(config, _request)
141
- _response = execute_request(_request)
142
-
143
- # Return appropriate response type.
144
- decoded = APIHelper.json_deserialize(_response.raw_body)
145
- _errors = APIHelper.map_response(decoded, ['errors'])
146
- ApiResponse.new(
147
- _response, data: decoded, errors: _errors
148
- )
97
+ new_api_call_builder
98
+ .request(new_request_builder(HttpMethodEnum::POST,
99
+ '/v2/bookings/availability/search',
100
+ 'default')
101
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
102
+ .body_param(new_parameter(body))
103
+ .header_param(new_parameter('application/json', key: 'accept'))
104
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
105
+ .auth(Single.new('global')))
106
+ .response(new_response_handler
107
+ .deserializer(APIHelper.method(:json_deserialize))
108
+ .is_api_response(true)
109
+ .convertor(ApiResponse.method(:create)))
110
+ .execute
149
111
  end
150
112
 
151
113
  # Retrieves a seller's booking profile.
152
114
  # @return [RetrieveBusinessBookingProfileResponse Hash] response from the API call
153
115
  def retrieve_business_booking_profile
154
- # Prepare query url.
155
- _query_builder = config.get_base_uri
156
- _query_builder << '/v2/bookings/business-booking-profile'
157
- _query_url = APIHelper.clean_url _query_builder
158
-
159
- # Prepare headers.
160
- _headers = {
161
- 'accept' => 'application/json'
162
- }
163
-
164
- # Prepare and execute HttpRequest.
165
- _request = config.http_client.get(
166
- _query_url,
167
- headers: _headers
168
- )
169
- OAuth2.apply(config, _request)
170
- _response = execute_request(_request)
171
-
172
- # Return appropriate response type.
173
- decoded = APIHelper.json_deserialize(_response.raw_body)
174
- _errors = APIHelper.map_response(decoded, ['errors'])
175
- ApiResponse.new(
176
- _response, data: decoded, errors: _errors
177
- )
116
+ new_api_call_builder
117
+ .request(new_request_builder(HttpMethodEnum::GET,
118
+ '/v2/bookings/business-booking-profile',
119
+ 'default')
120
+ .header_param(new_parameter('application/json', key: 'accept'))
121
+ .auth(Single.new('global')))
122
+ .response(new_response_handler
123
+ .deserializer(APIHelper.method(:json_deserialize))
124
+ .is_api_response(true)
125
+ .convertor(ApiResponse.method(:create)))
126
+ .execute
178
127
  end
179
128
 
180
129
  # Lists booking profiles for team members.
@@ -194,37 +143,21 @@ module Square
194
143
  limit: nil,
195
144
  cursor: nil,
196
145
  location_id: nil)
197
- # Prepare query url.
198
- _query_builder = config.get_base_uri
199
- _query_builder << '/v2/bookings/team-member-booking-profiles'
200
- _query_builder = APIHelper.append_url_with_query_parameters(
201
- _query_builder,
202
- 'bookable_only' => bookable_only,
203
- 'limit' => limit,
204
- 'cursor' => cursor,
205
- 'location_id' => location_id
206
- )
207
- _query_url = APIHelper.clean_url _query_builder
208
-
209
- # Prepare headers.
210
- _headers = {
211
- 'accept' => 'application/json'
212
- }
213
-
214
- # Prepare and execute HttpRequest.
215
- _request = config.http_client.get(
216
- _query_url,
217
- headers: _headers
218
- )
219
- OAuth2.apply(config, _request)
220
- _response = execute_request(_request)
221
-
222
- # Return appropriate response type.
223
- decoded = APIHelper.json_deserialize(_response.raw_body)
224
- _errors = APIHelper.map_response(decoded, ['errors'])
225
- ApiResponse.new(
226
- _response, data: decoded, errors: _errors
227
- )
146
+ new_api_call_builder
147
+ .request(new_request_builder(HttpMethodEnum::GET,
148
+ '/v2/bookings/team-member-booking-profiles',
149
+ 'default')
150
+ .query_param(new_parameter(bookable_only, key: 'bookable_only'))
151
+ .query_param(new_parameter(limit, key: 'limit'))
152
+ .query_param(new_parameter(cursor, key: 'cursor'))
153
+ .query_param(new_parameter(location_id, key: 'location_id'))
154
+ .header_param(new_parameter('application/json', key: 'accept'))
155
+ .auth(Single.new('global')))
156
+ .response(new_response_handler
157
+ .deserializer(APIHelper.method(:json_deserialize))
158
+ .is_api_response(true)
159
+ .convertor(ApiResponse.method(:create)))
160
+ .execute
228
161
  end
229
162
 
230
163
  # Retrieves a team member's booking profile.
@@ -232,34 +165,19 @@ module Square
232
165
  # member to retrieve.
233
166
  # @return [RetrieveTeamMemberBookingProfileResponse Hash] response from the API call
234
167
  def retrieve_team_member_booking_profile(team_member_id:)
235
- # Prepare query url.
236
- _query_builder = config.get_base_uri
237
- _query_builder << '/v2/bookings/team-member-booking-profiles/{team_member_id}'
238
- _query_builder = APIHelper.append_url_with_template_parameters(
239
- _query_builder,
240
- 'team_member_id' => { 'value' => team_member_id, 'encode' => true }
241
- )
242
- _query_url = APIHelper.clean_url _query_builder
243
-
244
- # Prepare headers.
245
- _headers = {
246
- 'accept' => 'application/json'
247
- }
248
-
249
- # Prepare and execute HttpRequest.
250
- _request = config.http_client.get(
251
- _query_url,
252
- headers: _headers
253
- )
254
- OAuth2.apply(config, _request)
255
- _response = execute_request(_request)
256
-
257
- # Return appropriate response type.
258
- decoded = APIHelper.json_deserialize(_response.raw_body)
259
- _errors = APIHelper.map_response(decoded, ['errors'])
260
- ApiResponse.new(
261
- _response, data: decoded, errors: _errors
262
- )
168
+ new_api_call_builder
169
+ .request(new_request_builder(HttpMethodEnum::GET,
170
+ '/v2/bookings/team-member-booking-profiles/{team_member_id}',
171
+ 'default')
172
+ .template_param(new_parameter(team_member_id, key: 'team_member_id')
173
+ .should_encode(true))
174
+ .header_param(new_parameter('application/json', key: 'accept'))
175
+ .auth(Single.new('global')))
176
+ .response(new_response_handler
177
+ .deserializer(APIHelper.method(:json_deserialize))
178
+ .is_api_response(true)
179
+ .convertor(ApiResponse.method(:create)))
180
+ .execute
263
181
  end
264
182
 
265
183
  # Retrieves a booking.
@@ -271,34 +189,19 @@ module Square
271
189
  # [Booking]($m/Booking) object representing the to-be-retrieved booking.
272
190
  # @return [RetrieveBookingResponse Hash] response from the API call
273
191
  def retrieve_booking(booking_id:)
274
- # Prepare query url.
275
- _query_builder = config.get_base_uri
276
- _query_builder << '/v2/bookings/{booking_id}'
277
- _query_builder = APIHelper.append_url_with_template_parameters(
278
- _query_builder,
279
- 'booking_id' => { 'value' => booking_id, 'encode' => true }
280
- )
281
- _query_url = APIHelper.clean_url _query_builder
282
-
283
- # Prepare headers.
284
- _headers = {
285
- 'accept' => 'application/json'
286
- }
287
-
288
- # Prepare and execute HttpRequest.
289
- _request = config.http_client.get(
290
- _query_url,
291
- headers: _headers
292
- )
293
- OAuth2.apply(config, _request)
294
- _response = execute_request(_request)
295
-
296
- # Return appropriate response type.
297
- decoded = APIHelper.json_deserialize(_response.raw_body)
298
- _errors = APIHelper.map_response(decoded, ['errors'])
299
- ApiResponse.new(
300
- _response, data: decoded, errors: _errors
301
- )
192
+ new_api_call_builder
193
+ .request(new_request_builder(HttpMethodEnum::GET,
194
+ '/v2/bookings/{booking_id}',
195
+ 'default')
196
+ .template_param(new_parameter(booking_id, key: 'booking_id')
197
+ .should_encode(true))
198
+ .header_param(new_parameter('application/json', key: 'accept'))
199
+ .auth(Single.new('global')))
200
+ .response(new_response_handler
201
+ .deserializer(APIHelper.method(:json_deserialize))
202
+ .is_api_response(true)
203
+ .convertor(ApiResponse.method(:create)))
204
+ .execute
302
205
  end
303
206
 
304
207
  # Updates a booking.
@@ -317,36 +220,22 @@ module Square
317
220
  # @return [UpdateBookingResponse Hash] response from the API call
318
221
  def update_booking(booking_id:,
319
222
  body:)
320
- # Prepare query url.
321
- _query_builder = config.get_base_uri
322
- _query_builder << '/v2/bookings/{booking_id}'
323
- _query_builder = APIHelper.append_url_with_template_parameters(
324
- _query_builder,
325
- 'booking_id' => { 'value' => booking_id, 'encode' => true }
326
- )
327
- _query_url = APIHelper.clean_url _query_builder
328
-
329
- # Prepare headers.
330
- _headers = {
331
- 'accept' => 'application/json',
332
- 'Content-Type' => 'application/json'
333
- }
334
-
335
- # Prepare and execute HttpRequest.
336
- _request = config.http_client.put(
337
- _query_url,
338
- headers: _headers,
339
- parameters: body.to_json
340
- )
341
- OAuth2.apply(config, _request)
342
- _response = execute_request(_request)
343
-
344
- # Return appropriate response type.
345
- decoded = APIHelper.json_deserialize(_response.raw_body)
346
- _errors = APIHelper.map_response(decoded, ['errors'])
347
- ApiResponse.new(
348
- _response, data: decoded, errors: _errors
349
- )
223
+ new_api_call_builder
224
+ .request(new_request_builder(HttpMethodEnum::PUT,
225
+ '/v2/bookings/{booking_id}',
226
+ 'default')
227
+ .template_param(new_parameter(booking_id, key: 'booking_id')
228
+ .should_encode(true))
229
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
230
+ .body_param(new_parameter(body))
231
+ .header_param(new_parameter('application/json', key: 'accept'))
232
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
233
+ .auth(Single.new('global')))
234
+ .response(new_response_handler
235
+ .deserializer(APIHelper.method(:json_deserialize))
236
+ .is_api_response(true)
237
+ .convertor(ApiResponse.method(:create)))
238
+ .execute
350
239
  end
351
240
 
352
241
  # Cancels an existing booking.
@@ -365,36 +254,22 @@ module Square
365
254
  # @return [CancelBookingResponse Hash] response from the API call
366
255
  def cancel_booking(booking_id:,
367
256
  body:)
368
- # Prepare query url.
369
- _query_builder = config.get_base_uri
370
- _query_builder << '/v2/bookings/{booking_id}/cancel'
371
- _query_builder = APIHelper.append_url_with_template_parameters(
372
- _query_builder,
373
- 'booking_id' => { 'value' => booking_id, 'encode' => true }
374
- )
375
- _query_url = APIHelper.clean_url _query_builder
376
-
377
- # Prepare headers.
378
- _headers = {
379
- 'accept' => 'application/json',
380
- 'Content-Type' => 'application/json'
381
- }
382
-
383
- # Prepare and execute HttpRequest.
384
- _request = config.http_client.post(
385
- _query_url,
386
- headers: _headers,
387
- parameters: body.to_json
388
- )
389
- OAuth2.apply(config, _request)
390
- _response = execute_request(_request)
391
-
392
- # Return appropriate response type.
393
- decoded = APIHelper.json_deserialize(_response.raw_body)
394
- _errors = APIHelper.map_response(decoded, ['errors'])
395
- ApiResponse.new(
396
- _response, data: decoded, errors: _errors
397
- )
257
+ new_api_call_builder
258
+ .request(new_request_builder(HttpMethodEnum::POST,
259
+ '/v2/bookings/{booking_id}/cancel',
260
+ 'default')
261
+ .template_param(new_parameter(booking_id, key: 'booking_id')
262
+ .should_encode(true))
263
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
264
+ .body_param(new_parameter(body))
265
+ .header_param(new_parameter('application/json', key: 'accept'))
266
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
267
+ .auth(Single.new('global')))
268
+ .response(new_response_handler
269
+ .deserializer(APIHelper.method(:json_deserialize))
270
+ .is_api_response(true)
271
+ .convertor(ApiResponse.method(:create)))
272
+ .execute
398
273
  end
399
274
  end
400
275
  end