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
  # InvoicesApi
3
3
  class InvoicesApi < BaseApi
4
- def initialize(config, http_call_back: nil)
5
- super(config, http_call_back: http_call_back)
6
- end
7
-
8
4
  # Returns a list of invoices for a given location. The response
9
5
  # is paginated. If truncated, the response includes a `cursor` that you
10
6
  # use in a subsequent request to retrieve the next set of invoices.
@@ -22,36 +18,20 @@ module Square
22
18
  def list_invoices(location_id:,
23
19
  cursor: nil,
24
20
  limit: nil)
25
- # Prepare query url.
26
- _query_builder = config.get_base_uri
27
- _query_builder << '/v2/invoices'
28
- _query_builder = APIHelper.append_url_with_query_parameters(
29
- _query_builder,
30
- 'location_id' => location_id,
31
- 'cursor' => cursor,
32
- 'limit' => limit
33
- )
34
- _query_url = APIHelper.clean_url _query_builder
35
-
36
- # Prepare headers.
37
- _headers = {
38
- 'accept' => 'application/json'
39
- }
40
-
41
- # Prepare and execute HttpRequest.
42
- _request = config.http_client.get(
43
- _query_url,
44
- headers: _headers
45
- )
46
- OAuth2.apply(config, _request)
47
- _response = execute_request(_request)
48
-
49
- # Return appropriate response type.
50
- decoded = APIHelper.json_deserialize(_response.raw_body)
51
- _errors = APIHelper.map_response(decoded, ['errors'])
52
- ApiResponse.new(
53
- _response, data: decoded, errors: _errors
54
- )
21
+ new_api_call_builder
22
+ .request(new_request_builder(HttpMethodEnum::GET,
23
+ '/v2/invoices',
24
+ 'default')
25
+ .query_param(new_parameter(location_id, key: 'location_id'))
26
+ .query_param(new_parameter(cursor, key: 'cursor'))
27
+ .query_param(new_parameter(limit, key: 'limit'))
28
+ .header_param(new_parameter('application/json', key: 'accept'))
29
+ .auth(Single.new('global')))
30
+ .response(new_response_handler
31
+ .deserializer(APIHelper.method(:json_deserialize))
32
+ .is_api_response(true)
33
+ .convertor(ApiResponse.method(:create)))
34
+ .execute
55
35
  end
56
36
 
57
37
  # Creates a draft [invoice]($m/Invoice)
@@ -64,32 +44,20 @@ module Square
64
44
  # object definition for field details.
65
45
  # @return [CreateInvoiceResponse Hash] response from the API call
66
46
  def create_invoice(body:)
67
- # Prepare query url.
68
- _query_builder = config.get_base_uri
69
- _query_builder << '/v2/invoices'
70
- _query_url = APIHelper.clean_url _query_builder
71
-
72
- # Prepare headers.
73
- _headers = {
74
- 'accept' => 'application/json',
75
- 'Content-Type' => 'application/json'
76
- }
77
-
78
- # Prepare and execute HttpRequest.
79
- _request = config.http_client.post(
80
- _query_url,
81
- headers: _headers,
82
- parameters: body.to_json
83
- )
84
- OAuth2.apply(config, _request)
85
- _response = execute_request(_request)
86
-
87
- # Return appropriate response type.
88
- decoded = APIHelper.json_deserialize(_response.raw_body)
89
- _errors = APIHelper.map_response(decoded, ['errors'])
90
- ApiResponse.new(
91
- _response, data: decoded, errors: _errors
92
- )
47
+ new_api_call_builder
48
+ .request(new_request_builder(HttpMethodEnum::POST,
49
+ '/v2/invoices',
50
+ 'default')
51
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
52
+ .body_param(new_parameter(body))
53
+ .header_param(new_parameter('application/json', key: 'accept'))
54
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
55
+ .auth(Single.new('global')))
56
+ .response(new_response_handler
57
+ .deserializer(APIHelper.method(:json_deserialize))
58
+ .is_api_response(true)
59
+ .convertor(ApiResponse.method(:create)))
60
+ .execute
93
61
  end
94
62
 
95
63
  # Searches for invoices from a location specified in
@@ -104,32 +72,20 @@ module Square
104
72
  # object definition for field details.
105
73
  # @return [SearchInvoicesResponse Hash] response from the API call
106
74
  def search_invoices(body:)
107
- # Prepare query url.
108
- _query_builder = config.get_base_uri
109
- _query_builder << '/v2/invoices/search'
110
- _query_url = APIHelper.clean_url _query_builder
111
-
112
- # Prepare headers.
113
- _headers = {
114
- 'accept' => 'application/json',
115
- 'Content-Type' => 'application/json'
116
- }
117
-
118
- # Prepare and execute HttpRequest.
119
- _request = config.http_client.post(
120
- _query_url,
121
- headers: _headers,
122
- parameters: body.to_json
123
- )
124
- OAuth2.apply(config, _request)
125
- _response = execute_request(_request)
126
-
127
- # Return appropriate response type.
128
- decoded = APIHelper.json_deserialize(_response.raw_body)
129
- _errors = APIHelper.map_response(decoded, ['errors'])
130
- ApiResponse.new(
131
- _response, data: decoded, errors: _errors
132
- )
75
+ new_api_call_builder
76
+ .request(new_request_builder(HttpMethodEnum::POST,
77
+ '/v2/invoices/search',
78
+ 'default')
79
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
80
+ .body_param(new_parameter(body))
81
+ .header_param(new_parameter('application/json', key: 'accept'))
82
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
83
+ .auth(Single.new('global')))
84
+ .response(new_response_handler
85
+ .deserializer(APIHelper.method(:json_deserialize))
86
+ .is_api_response(true)
87
+ .convertor(ApiResponse.method(:create)))
88
+ .execute
133
89
  end
134
90
 
135
91
  # Deletes the specified invoice. When an invoice is deleted, the
@@ -140,43 +96,25 @@ module Square
140
96
  # delete.
141
97
  # @param [Integer] version Optional parameter: The version of the
142
98
  # [invoice]($m/Invoice) to delete. If you do not know the version, you can
143
- # call [GetInvoice]($e/Invoices/GetInvoice) or
99
+ # call [GetInvoice]($e/Invoices/GetInvoice) or
144
100
  # [ListInvoices]($e/Invoices/ListInvoices).
145
101
  # @return [DeleteInvoiceResponse Hash] response from the API call
146
102
  def delete_invoice(invoice_id:,
147
103
  version: nil)
148
- # Prepare query url.
149
- _query_builder = config.get_base_uri
150
- _query_builder << '/v2/invoices/{invoice_id}'
151
- _query_builder = APIHelper.append_url_with_template_parameters(
152
- _query_builder,
153
- 'invoice_id' => { 'value' => invoice_id, 'encode' => true }
154
- )
155
- _query_builder = APIHelper.append_url_with_query_parameters(
156
- _query_builder,
157
- 'version' => version
158
- )
159
- _query_url = APIHelper.clean_url _query_builder
160
-
161
- # Prepare headers.
162
- _headers = {
163
- 'accept' => 'application/json'
164
- }
165
-
166
- # Prepare and execute HttpRequest.
167
- _request = config.http_client.delete(
168
- _query_url,
169
- headers: _headers
170
- )
171
- OAuth2.apply(config, _request)
172
- _response = execute_request(_request)
173
-
174
- # Return appropriate response type.
175
- decoded = APIHelper.json_deserialize(_response.raw_body)
176
- _errors = APIHelper.map_response(decoded, ['errors'])
177
- ApiResponse.new(
178
- _response, data: decoded, errors: _errors
179
- )
104
+ new_api_call_builder
105
+ .request(new_request_builder(HttpMethodEnum::DELETE,
106
+ '/v2/invoices/{invoice_id}',
107
+ 'default')
108
+ .template_param(new_parameter(invoice_id, key: 'invoice_id')
109
+ .should_encode(true))
110
+ .query_param(new_parameter(version, key: 'version'))
111
+ .header_param(new_parameter('application/json', key: 'accept'))
112
+ .auth(Single.new('global')))
113
+ .response(new_response_handler
114
+ .deserializer(APIHelper.method(:json_deserialize))
115
+ .is_api_response(true)
116
+ .convertor(ApiResponse.method(:create)))
117
+ .execute
180
118
  end
181
119
 
182
120
  # Retrieves an invoice by invoice ID.
@@ -184,34 +122,19 @@ module Square
184
122
  # retrieve.
185
123
  # @return [GetInvoiceResponse Hash] response from the API call
186
124
  def get_invoice(invoice_id:)
187
- # Prepare query url.
188
- _query_builder = config.get_base_uri
189
- _query_builder << '/v2/invoices/{invoice_id}'
190
- _query_builder = APIHelper.append_url_with_template_parameters(
191
- _query_builder,
192
- 'invoice_id' => { 'value' => invoice_id, 'encode' => true }
193
- )
194
- _query_url = APIHelper.clean_url _query_builder
195
-
196
- # Prepare headers.
197
- _headers = {
198
- 'accept' => 'application/json'
199
- }
200
-
201
- # Prepare and execute HttpRequest.
202
- _request = config.http_client.get(
203
- _query_url,
204
- headers: _headers
205
- )
206
- OAuth2.apply(config, _request)
207
- _response = execute_request(_request)
208
-
209
- # Return appropriate response type.
210
- decoded = APIHelper.json_deserialize(_response.raw_body)
211
- _errors = APIHelper.map_response(decoded, ['errors'])
212
- ApiResponse.new(
213
- _response, data: decoded, errors: _errors
214
- )
125
+ new_api_call_builder
126
+ .request(new_request_builder(HttpMethodEnum::GET,
127
+ '/v2/invoices/{invoice_id}',
128
+ 'default')
129
+ .template_param(new_parameter(invoice_id, key: 'invoice_id')
130
+ .should_encode(true))
131
+ .header_param(new_parameter('application/json', key: 'accept'))
132
+ .auth(Single.new('global')))
133
+ .response(new_response_handler
134
+ .deserializer(APIHelper.method(:json_deserialize))
135
+ .is_api_response(true)
136
+ .convertor(ApiResponse.method(:create)))
137
+ .execute
215
138
  end
216
139
 
217
140
  # Updates an invoice by modifying fields, clearing fields, or both. For most
@@ -230,36 +153,22 @@ module Square
230
153
  # @return [UpdateInvoiceResponse Hash] response from the API call
231
154
  def update_invoice(invoice_id:,
232
155
  body:)
233
- # Prepare query url.
234
- _query_builder = config.get_base_uri
235
- _query_builder << '/v2/invoices/{invoice_id}'
236
- _query_builder = APIHelper.append_url_with_template_parameters(
237
- _query_builder,
238
- 'invoice_id' => { 'value' => invoice_id, 'encode' => true }
239
- )
240
- _query_url = APIHelper.clean_url _query_builder
241
-
242
- # Prepare headers.
243
- _headers = {
244
- 'accept' => 'application/json',
245
- 'Content-Type' => 'application/json'
246
- }
247
-
248
- # Prepare and execute HttpRequest.
249
- _request = config.http_client.put(
250
- _query_url,
251
- headers: _headers,
252
- parameters: body.to_json
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
- )
156
+ new_api_call_builder
157
+ .request(new_request_builder(HttpMethodEnum::PUT,
158
+ '/v2/invoices/{invoice_id}',
159
+ 'default')
160
+ .template_param(new_parameter(invoice_id, key: 'invoice_id')
161
+ .should_encode(true))
162
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
163
+ .body_param(new_parameter(body))
164
+ .header_param(new_parameter('application/json', key: 'accept'))
165
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
166
+ .auth(Single.new('global')))
167
+ .response(new_response_handler
168
+ .deserializer(APIHelper.method(:json_deserialize))
169
+ .is_api_response(true)
170
+ .convertor(ApiResponse.method(:create)))
171
+ .execute
263
172
  end
264
173
 
265
174
  # Cancels an invoice. The seller cannot collect payments for
@@ -274,36 +183,22 @@ module Square
274
183
  # @return [CancelInvoiceResponse Hash] response from the API call
275
184
  def cancel_invoice(invoice_id:,
276
185
  body:)
277
- # Prepare query url.
278
- _query_builder = config.get_base_uri
279
- _query_builder << '/v2/invoices/{invoice_id}/cancel'
280
- _query_builder = APIHelper.append_url_with_template_parameters(
281
- _query_builder,
282
- 'invoice_id' => { 'value' => invoice_id, 'encode' => true }
283
- )
284
- _query_url = APIHelper.clean_url _query_builder
285
-
286
- # Prepare headers.
287
- _headers = {
288
- 'accept' => 'application/json',
289
- 'Content-Type' => 'application/json'
290
- }
291
-
292
- # Prepare and execute HttpRequest.
293
- _request = config.http_client.post(
294
- _query_url,
295
- headers: _headers,
296
- parameters: body.to_json
297
- )
298
- OAuth2.apply(config, _request)
299
- _response = execute_request(_request)
300
-
301
- # Return appropriate response type.
302
- decoded = APIHelper.json_deserialize(_response.raw_body)
303
- _errors = APIHelper.map_response(decoded, ['errors'])
304
- ApiResponse.new(
305
- _response, data: decoded, errors: _errors
306
- )
186
+ new_api_call_builder
187
+ .request(new_request_builder(HttpMethodEnum::POST,
188
+ '/v2/invoices/{invoice_id}/cancel',
189
+ 'default')
190
+ .template_param(new_parameter(invoice_id, key: 'invoice_id')
191
+ .should_encode(true))
192
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
193
+ .body_param(new_parameter(body))
194
+ .header_param(new_parameter('application/json', key: 'accept'))
195
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
196
+ .auth(Single.new('global')))
197
+ .response(new_response_handler
198
+ .deserializer(APIHelper.method(:json_deserialize))
199
+ .is_api_response(true)
200
+ .convertor(ApiResponse.method(:create)))
201
+ .execute
307
202
  end
308
203
 
309
204
  # Publishes the specified draft invoice.
@@ -327,36 +222,22 @@ module Square
327
222
  # @return [PublishInvoiceResponse Hash] response from the API call
328
223
  def publish_invoice(invoice_id:,
329
224
  body:)
330
- # Prepare query url.
331
- _query_builder = config.get_base_uri
332
- _query_builder << '/v2/invoices/{invoice_id}/publish'
333
- _query_builder = APIHelper.append_url_with_template_parameters(
334
- _query_builder,
335
- 'invoice_id' => { 'value' => invoice_id, 'encode' => true }
336
- )
337
- _query_url = APIHelper.clean_url _query_builder
338
-
339
- # Prepare headers.
340
- _headers = {
341
- 'accept' => 'application/json',
342
- 'Content-Type' => 'application/json'
343
- }
344
-
345
- # Prepare and execute HttpRequest.
346
- _request = config.http_client.post(
347
- _query_url,
348
- headers: _headers,
349
- parameters: body.to_json
350
- )
351
- OAuth2.apply(config, _request)
352
- _response = execute_request(_request)
353
-
354
- # Return appropriate response type.
355
- decoded = APIHelper.json_deserialize(_response.raw_body)
356
- _errors = APIHelper.map_response(decoded, ['errors'])
357
- ApiResponse.new(
358
- _response, data: decoded, errors: _errors
359
- )
225
+ new_api_call_builder
226
+ .request(new_request_builder(HttpMethodEnum::POST,
227
+ '/v2/invoices/{invoice_id}/publish',
228
+ 'default')
229
+ .template_param(new_parameter(invoice_id, key: 'invoice_id')
230
+ .should_encode(true))
231
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
232
+ .body_param(new_parameter(body))
233
+ .header_param(new_parameter('application/json', key: 'accept'))
234
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
235
+ .auth(Single.new('global')))
236
+ .response(new_response_handler
237
+ .deserializer(APIHelper.method(:json_deserialize))
238
+ .is_api_response(true)
239
+ .convertor(ApiResponse.method(:create)))
240
+ .execute
360
241
  end
361
242
  end
362
243
  end