square.rb 26.1.0.20230119 → 27.0.0.20230419

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -0
  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 +171 -336
  7. data/lib/square/api/bookings_api.rb +140 -263
  8. data/lib/square/api/cards_api.rb +58 -120
  9. data/lib/square/api/cash_drawers_api.rb +47 -103
  10. data/lib/square/api/catalog_api.rb +200 -426
  11. data/lib/square/api/checkout_api.rb +86 -176
  12. data/lib/square/api/customer_custom_attributes_api.rb +157 -310
  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 +132 -290
  18. data/lib/square/api/employees_api.rb +28 -63
  19. data/lib/square/api/gift_card_activities_api.rb +34 -66
  20. data/lib/square/api/gift_cards_api.rb +109 -207
  21. data/lib/square/api/inventory_api.rb +204 -391
  22. data/lib/square/api/invoices_api.rb +121 -240
  23. data/lib/square/api/labor_api.rb +223 -459
  24. data/lib/square/api/location_custom_attributes_api.rb +173 -338
  25. data/lib/square/api/locations_api.rb +54 -112
  26. data/lib/square/api/loyalty_api.rb +283 -535
  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 +174 -339
  31. data/lib/square/api/orders_api.rb +115 -222
  32. data/lib/square/api/payments_api.rb +118 -217
  33. data/lib/square/api/payouts_api.rb +54 -107
  34. data/lib/square/api/refunds_api.rb +59 -104
  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 +64 -128
  41. data/lib/square/api/v1_transactions_api.rb +155 -296
  42. data/lib/square/api/vendors_api.rb +100 -193
  43. data/lib/square/api/webhook_subscriptions_api.rb +124 -244
  44. data/lib/square/api_helper.rb +1 -437
  45. data/lib/square/client.rb +77 -47
  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 +6 -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 +11 -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
  # OrdersApi
3
3
  class OrdersApi < BaseApi
4
- def initialize(config, http_call_back: nil)
5
- super(config, http_call_back: http_call_back)
6
- end
7
-
8
4
  # Creates a new [order]($m/Order) that can include information about
9
5
  # products for
10
6
  # purchase and settings to apply to the purchase.
@@ -18,32 +14,20 @@ module Square
18
14
  # definition for field details.
19
15
  # @return [CreateOrderResponse Hash] response from the API call
20
16
  def create_order(body:)
21
- # Prepare query url.
22
- _query_builder = config.get_base_uri
23
- _query_builder << '/v2/orders'
24
- _query_url = APIHelper.clean_url _query_builder
25
-
26
- # Prepare headers.
27
- _headers = {
28
- 'accept' => 'application/json',
29
- 'Content-Type' => 'application/json'
30
- }
31
-
32
- # Prepare and execute HttpRequest.
33
- _request = config.http_client.post(
34
- _query_url,
35
- headers: _headers,
36
- parameters: body.to_json
37
- )
38
- OAuth2.apply(config, _request)
39
- _response = execute_request(_request)
40
-
41
- # Return appropriate response type.
42
- decoded = APIHelper.json_deserialize(_response.raw_body)
43
- _errors = APIHelper.map_response(decoded, ['errors'])
44
- ApiResponse.new(
45
- _response, data: decoded, errors: _errors
46
- )
17
+ new_api_call_builder
18
+ .request(new_request_builder(HttpMethodEnum::POST,
19
+ '/v2/orders',
20
+ 'default')
21
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
22
+ .body_param(new_parameter(body))
23
+ .header_param(new_parameter('application/json', key: 'accept'))
24
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
25
+ .auth(Single.new('global')))
26
+ .response(new_response_handler
27
+ .deserializer(APIHelper.method(:json_deserialize))
28
+ .is_api_response(true)
29
+ .convertor(ApiResponse.method(:create)))
30
+ .execute
47
31
  end
48
32
 
49
33
  # Retrieves a set of [orders]($m/Order) by their IDs.
@@ -54,32 +38,20 @@ module Square
54
38
  # object definition for field details.
55
39
  # @return [BatchRetrieveOrdersResponse Hash] response from the API call
56
40
  def batch_retrieve_orders(body:)
57
- # Prepare query url.
58
- _query_builder = config.get_base_uri
59
- _query_builder << '/v2/orders/batch-retrieve'
60
- _query_url = APIHelper.clean_url _query_builder
61
-
62
- # Prepare headers.
63
- _headers = {
64
- 'accept' => 'application/json',
65
- 'Content-Type' => 'application/json'
66
- }
67
-
68
- # Prepare and execute HttpRequest.
69
- _request = config.http_client.post(
70
- _query_url,
71
- headers: _headers,
72
- parameters: body.to_json
73
- )
74
- OAuth2.apply(config, _request)
75
- _response = execute_request(_request)
76
-
77
- # Return appropriate response type.
78
- decoded = APIHelper.json_deserialize(_response.raw_body)
79
- _errors = APIHelper.map_response(decoded, ['errors'])
80
- ApiResponse.new(
81
- _response, data: decoded, errors: _errors
82
- )
41
+ new_api_call_builder
42
+ .request(new_request_builder(HttpMethodEnum::POST,
43
+ '/v2/orders/batch-retrieve',
44
+ 'default')
45
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
46
+ .body_param(new_parameter(body))
47
+ .header_param(new_parameter('application/json', key: 'accept'))
48
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
49
+ .auth(Single.new('global')))
50
+ .response(new_response_handler
51
+ .deserializer(APIHelper.method(:json_deserialize))
52
+ .is_api_response(true)
53
+ .convertor(ApiResponse.method(:create)))
54
+ .execute
83
55
  end
84
56
 
85
57
  # Enables applications to preview order pricing without creating an order.
@@ -88,32 +60,20 @@ module Square
88
60
  # object definition for field details.
89
61
  # @return [CalculateOrderResponse Hash] response from the API call
90
62
  def calculate_order(body:)
91
- # Prepare query url.
92
- _query_builder = config.get_base_uri
93
- _query_builder << '/v2/orders/calculate'
94
- _query_url = APIHelper.clean_url _query_builder
95
-
96
- # Prepare headers.
97
- _headers = {
98
- 'accept' => 'application/json',
99
- 'Content-Type' => 'application/json'
100
- }
101
-
102
- # Prepare and execute HttpRequest.
103
- _request = config.http_client.post(
104
- _query_url,
105
- headers: _headers,
106
- parameters: body.to_json
107
- )
108
- OAuth2.apply(config, _request)
109
- _response = execute_request(_request)
110
-
111
- # Return appropriate response type.
112
- decoded = APIHelper.json_deserialize(_response.raw_body)
113
- _errors = APIHelper.map_response(decoded, ['errors'])
114
- ApiResponse.new(
115
- _response, data: decoded, errors: _errors
116
- )
63
+ new_api_call_builder
64
+ .request(new_request_builder(HttpMethodEnum::POST,
65
+ '/v2/orders/calculate',
66
+ 'default')
67
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
68
+ .body_param(new_parameter(body))
69
+ .header_param(new_parameter('application/json', key: 'accept'))
70
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
71
+ .auth(Single.new('global')))
72
+ .response(new_response_handler
73
+ .deserializer(APIHelper.method(:json_deserialize))
74
+ .is_api_response(true)
75
+ .convertor(ApiResponse.method(:create)))
76
+ .execute
117
77
  end
118
78
 
119
79
  # Creates a new order, in the `DRAFT` state, by duplicating an existing
@@ -125,32 +85,20 @@ module Square
125
85
  # definition for field details.
126
86
  # @return [CloneOrderResponse Hash] response from the API call
127
87
  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'
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
- )
88
+ new_api_call_builder
89
+ .request(new_request_builder(HttpMethodEnum::POST,
90
+ '/v2/orders/clone',
91
+ 'default')
92
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
93
+ .body_param(new_parameter(body))
94
+ .header_param(new_parameter('application/json', key: 'accept'))
95
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
96
+ .auth(Single.new('global')))
97
+ .response(new_response_handler
98
+ .deserializer(APIHelper.method(:json_deserialize))
99
+ .is_api_response(true)
100
+ .convertor(ApiResponse.method(:create)))
101
+ .execute
154
102
  end
155
103
 
156
104
  # Search all orders for one or more locations. Orders include all sales,
@@ -175,32 +123,20 @@ module Square
175
123
  # definition for field details.
176
124
  # @return [SearchOrdersResponse Hash] response from the API call
177
125
  def search_orders(body:)
178
- # Prepare query url.
179
- _query_builder = config.get_base_uri
180
- _query_builder << '/v2/orders/search'
181
- _query_url = APIHelper.clean_url _query_builder
182
-
183
- # Prepare headers.
184
- _headers = {
185
- 'accept' => 'application/json',
186
- 'Content-Type' => 'application/json'
187
- }
188
-
189
- # Prepare and execute HttpRequest.
190
- _request = config.http_client.post(
191
- _query_url,
192
- headers: _headers,
193
- parameters: body.to_json
194
- )
195
- OAuth2.apply(config, _request)
196
- _response = execute_request(_request)
197
-
198
- # Return appropriate response type.
199
- decoded = APIHelper.json_deserialize(_response.raw_body)
200
- _errors = APIHelper.map_response(decoded, ['errors'])
201
- ApiResponse.new(
202
- _response, data: decoded, errors: _errors
203
- )
126
+ new_api_call_builder
127
+ .request(new_request_builder(HttpMethodEnum::POST,
128
+ '/v2/orders/search',
129
+ 'default')
130
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
131
+ .body_param(new_parameter(body))
132
+ .header_param(new_parameter('application/json', key: 'accept'))
133
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
134
+ .auth(Single.new('global')))
135
+ .response(new_response_handler
136
+ .deserializer(APIHelper.method(:json_deserialize))
137
+ .is_api_response(true)
138
+ .convertor(ApiResponse.method(:create)))
139
+ .execute
204
140
  end
205
141
 
206
142
  # Retrieves an [Order]($m/Order) by ID.
@@ -208,34 +144,19 @@ module Square
208
144
  # retrieve.
209
145
  # @return [RetrieveOrderResponse Hash] response from the API call
210
146
  def retrieve_order(order_id:)
211
- # Prepare query url.
212
- _query_builder = config.get_base_uri
213
- _query_builder << '/v2/orders/{order_id}'
214
- _query_builder = APIHelper.append_url_with_template_parameters(
215
- _query_builder,
216
- 'order_id' => { 'value' => order_id, 'encode' => true }
217
- )
218
- _query_url = APIHelper.clean_url _query_builder
219
-
220
- # Prepare headers.
221
- _headers = {
222
- 'accept' => 'application/json'
223
- }
224
-
225
- # Prepare and execute HttpRequest.
226
- _request = config.http_client.get(
227
- _query_url,
228
- headers: _headers
229
- )
230
- OAuth2.apply(config, _request)
231
- _response = execute_request(_request)
232
-
233
- # Return appropriate response type.
234
- decoded = APIHelper.json_deserialize(_response.raw_body)
235
- _errors = APIHelper.map_response(decoded, ['errors'])
236
- ApiResponse.new(
237
- _response, data: decoded, errors: _errors
238
- )
147
+ new_api_call_builder
148
+ .request(new_request_builder(HttpMethodEnum::GET,
149
+ '/v2/orders/{order_id}',
150
+ 'default')
151
+ .template_param(new_parameter(order_id, key: 'order_id')
152
+ .should_encode(true))
153
+ .header_param(new_parameter('application/json', key: 'accept'))
154
+ .auth(Single.new('global')))
155
+ .response(new_response_handler
156
+ .deserializer(APIHelper.method(:json_deserialize))
157
+ .is_api_response(true)
158
+ .convertor(ApiResponse.method(:create)))
159
+ .execute
239
160
  end
240
161
 
241
162
  # Updates an open [order]($m/Order) by adding, replacing, or deleting
@@ -264,36 +185,22 @@ module Square
264
185
  # @return [UpdateOrderResponse Hash] response from the API call
265
186
  def update_order(order_id:,
266
187
  body:)
267
- # Prepare query url.
268
- _query_builder = config.get_base_uri
269
- _query_builder << '/v2/orders/{order_id}'
270
- _query_builder = APIHelper.append_url_with_template_parameters(
271
- _query_builder,
272
- 'order_id' => { 'value' => order_id, 'encode' => true }
273
- )
274
- _query_url = APIHelper.clean_url _query_builder
275
-
276
- # Prepare headers.
277
- _headers = {
278
- 'accept' => 'application/json',
279
- 'Content-Type' => 'application/json'
280
- }
281
-
282
- # Prepare and execute HttpRequest.
283
- _request = config.http_client.put(
284
- _query_url,
285
- headers: _headers,
286
- parameters: body.to_json
287
- )
288
- OAuth2.apply(config, _request)
289
- _response = execute_request(_request)
290
-
291
- # Return appropriate response type.
292
- decoded = APIHelper.json_deserialize(_response.raw_body)
293
- _errors = APIHelper.map_response(decoded, ['errors'])
294
- ApiResponse.new(
295
- _response, data: decoded, errors: _errors
296
- )
188
+ new_api_call_builder
189
+ .request(new_request_builder(HttpMethodEnum::PUT,
190
+ '/v2/orders/{order_id}',
191
+ 'default')
192
+ .template_param(new_parameter(order_id, key: 'order_id')
193
+ .should_encode(true))
194
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
195
+ .body_param(new_parameter(body))
196
+ .header_param(new_parameter('application/json', key: 'accept'))
197
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
198
+ .auth(Single.new('global')))
199
+ .response(new_response_handler
200
+ .deserializer(APIHelper.method(:json_deserialize))
201
+ .is_api_response(true)
202
+ .convertor(ApiResponse.method(:create)))
203
+ .execute
297
204
  end
298
205
 
299
206
  # Pay for an [order]($m/Order) using one or more approved
@@ -323,36 +230,22 @@ module Square
323
230
  # @return [PayOrderResponse Hash] response from the API call
324
231
  def pay_order(order_id:,
325
232
  body:)
326
- # Prepare query url.
327
- _query_builder = config.get_base_uri
328
- _query_builder << '/v2/orders/{order_id}/pay'
329
- _query_builder = APIHelper.append_url_with_template_parameters(
330
- _query_builder,
331
- 'order_id' => { 'value' => order_id, 'encode' => true }
332
- )
333
- _query_url = APIHelper.clean_url _query_builder
334
-
335
- # Prepare headers.
336
- _headers = {
337
- 'accept' => 'application/json',
338
- 'Content-Type' => 'application/json'
339
- }
340
-
341
- # Prepare and execute HttpRequest.
342
- _request = config.http_client.post(
343
- _query_url,
344
- headers: _headers,
345
- parameters: body.to_json
346
- )
347
- OAuth2.apply(config, _request)
348
- _response = execute_request(_request)
349
-
350
- # Return appropriate response type.
351
- decoded = APIHelper.json_deserialize(_response.raw_body)
352
- _errors = APIHelper.map_response(decoded, ['errors'])
353
- ApiResponse.new(
354
- _response, data: decoded, errors: _errors
355
- )
233
+ new_api_call_builder
234
+ .request(new_request_builder(HttpMethodEnum::POST,
235
+ '/v2/orders/{order_id}/pay',
236
+ 'default')
237
+ .template_param(new_parameter(order_id, key: 'order_id')
238
+ .should_encode(true))
239
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
240
+ .body_param(new_parameter(body))
241
+ .header_param(new_parameter('application/json', key: 'accept'))
242
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
243
+ .auth(Single.new('global')))
244
+ .response(new_response_handler
245
+ .deserializer(APIHelper.method(:json_deserialize))
246
+ .is_api_response(true)
247
+ .convertor(ApiResponse.method(:create)))
248
+ .execute
356
249
  end
357
250
  end
358
251
  end