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.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/square/api/apple_pay_api.rb +14 -30
- data/lib/square/api/bank_accounts_api.rb +40 -90
- data/lib/square/api/base_api.rb +42 -42
- data/lib/square/api/booking_custom_attributes_api.rb +171 -336
- data/lib/square/api/bookings_api.rb +140 -263
- data/lib/square/api/cards_api.rb +58 -120
- data/lib/square/api/cash_drawers_api.rb +47 -103
- data/lib/square/api/catalog_api.rb +200 -426
- data/lib/square/api/checkout_api.rb +86 -176
- data/lib/square/api/customer_custom_attributes_api.rb +157 -310
- data/lib/square/api/customer_groups_api.rb +69 -145
- data/lib/square/api/customer_segments_api.rb +26 -61
- data/lib/square/api/customers_api.rb +147 -294
- data/lib/square/api/devices_api.rb +42 -89
- data/lib/square/api/disputes_api.rb +132 -290
- data/lib/square/api/employees_api.rb +28 -63
- data/lib/square/api/gift_card_activities_api.rb +34 -66
- data/lib/square/api/gift_cards_api.rb +109 -207
- data/lib/square/api/inventory_api.rb +204 -391
- data/lib/square/api/invoices_api.rb +121 -240
- data/lib/square/api/labor_api.rb +223 -459
- data/lib/square/api/location_custom_attributes_api.rb +173 -338
- data/lib/square/api/locations_api.rb +54 -112
- data/lib/square/api/loyalty_api.rb +283 -535
- data/lib/square/api/merchants_api.rb +25 -60
- data/lib/square/api/mobile_authorization_api.rb +14 -30
- data/lib/square/api/o_auth_api.rb +54 -109
- data/lib/square/api/order_custom_attributes_api.rb +174 -339
- data/lib/square/api/orders_api.rb +115 -222
- data/lib/square/api/payments_api.rb +118 -217
- data/lib/square/api/payouts_api.rb +54 -107
- data/lib/square/api/refunds_api.rb +59 -104
- data/lib/square/api/sites_api.rb +11 -28
- data/lib/square/api/snippets_api.rb +42 -90
- data/lib/square/api/subscriptions_api.rb +150 -299
- data/lib/square/api/team_api.rb +114 -224
- data/lib/square/api/terminal_api.rb +162 -328
- data/lib/square/api/transactions_api.rb +64 -128
- data/lib/square/api/v1_transactions_api.rb +155 -296
- data/lib/square/api/vendors_api.rb +100 -193
- data/lib/square/api/webhook_subscriptions_api.rb +124 -244
- data/lib/square/api_helper.rb +1 -437
- data/lib/square/client.rb +77 -47
- data/lib/square/configuration.rb +28 -53
- data/lib/square/exceptions/api_exception.rb +1 -11
- data/lib/square/http/api_response.rb +13 -19
- data/lib/square/http/auth/o_auth2.rb +14 -7
- data/lib/square/http/http_call_back.rb +1 -15
- data/lib/square/http/http_method_enum.rb +1 -4
- data/lib/square/http/http_request.rb +1 -45
- data/lib/square/http/http_response.rb +1 -20
- data/lib/square/utilities/date_time_helper.rb +1 -146
- data/lib/square/utilities/file_wrapper.rb +5 -5
- data/lib/square.rb +6 -6
- data/spec/user_journey_spec.rb +2 -2
- data/test/api/api_test_base.rb +13 -5
- data/test/api/test_catalog_api.rb +5 -4
- data/test/api/test_customers_api.rb +3 -2
- data/test/api/test_employees_api.rb +4 -3
- data/test/api/test_labor_api.rb +6 -5
- data/test/api/test_locations_api.rb +3 -2
- data/test/api/test_merchants_api.rb +4 -3
- data/test/api/test_payments_api.rb +4 -3
- data/test/api/test_refunds_api.rb +4 -3
- metadata +11 -111
- data/lib/square/exceptions/validation_exception.rb +0 -13
- data/lib/square/http/faraday_client.rb +0 -93
- data/lib/square/http/http_client.rb +0 -118
- 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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
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
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
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
|
@@ -139,44 +95,26 @@ module Square
|
|
139
95
|
# @param [String] invoice_id Required parameter: The ID of the invoice to
|
140
96
|
# delete.
|
141
97
|
# @param [Integer] version Optional parameter: The version of the
|
142
|
-
# [invoice](
|
143
|
-
# call [GetInvoice](
|
144
|
-
# [ListInvoices](
|
98
|
+
# [invoice](entity:Invoice) to delete. If you do not know the version, you
|
99
|
+
# can call [GetInvoice](api-endpoint:Invoices-GetInvoice) or
|
100
|
+
# [ListInvoices](api-endpoint:Invoices-ListInvoices).
|
145
101
|
# @return [DeleteInvoiceResponse Hash] response from the API call
|
146
102
|
def delete_invoice(invoice_id:,
|
147
103
|
version: nil)
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
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
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
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
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
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
|
@@ -267,43 +176,29 @@ module Square
|
|
267
176
|
# You cannot cancel an invoice in the `DRAFT` state or in a terminal state:
|
268
177
|
# `PAID`, `REFUNDED`, `CANCELED`, or `FAILED`.
|
269
178
|
# @param [String] invoice_id Required parameter: The ID of the
|
270
|
-
# [invoice](
|
179
|
+
# [invoice](entity:Invoice) to cancel.
|
271
180
|
# @param [CancelInvoiceRequest] body Required parameter: An object
|
272
181
|
# containing the fields to POST for the request. See the corresponding
|
273
182
|
# object definition for field details.
|
274
183
|
# @return [CancelInvoiceResponse Hash] response from the API call
|
275
184
|
def cancel_invoice(invoice_id:,
|
276
185
|
body:)
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
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
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
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
|