fangkuai.rb 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +10 -0
- data/README.md +1 -0
- data/lib/square.rb +61 -0
- data/lib/square/api/apple_pay_api.rb +50 -0
- data/lib/square/api/bank_accounts_api.rb +136 -0
- data/lib/square/api/base_api.rb +43 -0
- data/lib/square/api/cash_drawers_api.rb +150 -0
- data/lib/square/api/catalog_api.rb +572 -0
- data/lib/square/api/checkout_api.rb +49 -0
- data/lib/square/api/customer_groups_api.rb +182 -0
- data/lib/square/api/customer_segments_api.rb +78 -0
- data/lib/square/api/customers_api.rb +418 -0
- data/lib/square/api/devices_api.rb +120 -0
- data/lib/square/api/disputes_api.rb +398 -0
- data/lib/square/api/employees_api.rb +87 -0
- data/lib/square/api/inventory_api.rb +296 -0
- data/lib/square/api/invoices_api.rb +358 -0
- data/lib/square/api/labor_api.rb +630 -0
- data/lib/square/api/locations_api.rb +151 -0
- data/lib/square/api/loyalty_api.rb +543 -0
- data/lib/square/api/merchants_api.rb +83 -0
- data/lib/square/api/mobile_authorization_api.rb +52 -0
- data/lib/square/api/o_auth_api.rb +163 -0
- data/lib/square/api/orders_api.rb +280 -0
- data/lib/square/api/payments_api.rb +279 -0
- data/lib/square/api/refunds_api.rb +145 -0
- data/lib/square/api/subscriptions_api.rb +251 -0
- data/lib/square/api/team_api.rb +326 -0
- data/lib/square/api/terminal_api.rb +141 -0
- data/lib/square/api/transactions_api.rb +369 -0
- data/lib/square/api/v1_employees_api.rb +723 -0
- data/lib/square/api/v1_items_api.rb +1686 -0
- data/lib/square/api/v1_locations_api.rb +65 -0
- data/lib/square/api/v1_transactions_api.rb +572 -0
- data/lib/square/api_helper.rb +276 -0
- data/lib/square/client.rb +211 -0
- data/lib/square/configuration.rb +101 -0
- data/lib/square/exceptions/api_exception.rb +15 -0
- data/lib/square/http/api_response.rb +45 -0
- data/lib/square/http/auth/o_auth2.rb +12 -0
- data/lib/square/http/faraday_client.rb +55 -0
- data/lib/square/http/http_call_back.rb +19 -0
- data/lib/square/http/http_client.rb +99 -0
- data/lib/square/http/http_method_enum.rb +8 -0
- data/lib/square/http/http_request.rb +45 -0
- data/lib/square/http/http_response.rb +24 -0
- data/lib/square/utilities/file_wrapper.rb +12 -0
- data/spec/user_journey_spec.rb +148 -0
- data/test/api/api_test_base.rb +24 -0
- data/test/api/test_catalog_api.rb +59 -0
- data/test/api/test_customers_api.rb +45 -0
- data/test/api/test_employees_api.rb +36 -0
- data/test/api/test_labor_api.rb +74 -0
- data/test/api/test_locations_api.rb +35 -0
- data/test/api/test_merchants_api.rb +40 -0
- data/test/api/test_payments_api.rb +42 -0
- data/test/api/test_refunds_api.rb +41 -0
- data/test/http_response_catcher.rb +19 -0
- data/test/test_helper.rb +94 -0
- metadata +199 -0
@@ -0,0 +1,87 @@
|
|
1
|
+
module Square
|
2
|
+
# EmployeesApi
|
3
|
+
class EmployeesApi < BaseApi
|
4
|
+
def initialize(config, http_call_back: nil)
|
5
|
+
super(config, http_call_back: http_call_back)
|
6
|
+
end
|
7
|
+
|
8
|
+
# ListEmployees
|
9
|
+
# @param [String] location_id Optional parameter: Example:
|
10
|
+
# @param [EmployeeStatus] status Optional parameter: Specifies the
|
11
|
+
# EmployeeStatus to filter the employee by.
|
12
|
+
# @param [Integer] limit Optional parameter: The number of employees to be
|
13
|
+
# returned on each page.
|
14
|
+
# @param [String] cursor Optional parameter: The token required to retrieve
|
15
|
+
# the specified page of results.
|
16
|
+
# @return [ListEmployeesResponse Hash] response from the API call
|
17
|
+
def list_employees(location_id: nil,
|
18
|
+
status: nil,
|
19
|
+
limit: nil,
|
20
|
+
cursor: nil)
|
21
|
+
warn 'Endpoint list_employees in EmployeesApi is deprecated'
|
22
|
+
# Prepare query url.
|
23
|
+
_query_builder = config.get_base_uri
|
24
|
+
_query_builder << '/v2/employees'
|
25
|
+
_query_builder = APIHelper.append_url_with_query_parameters(
|
26
|
+
_query_builder,
|
27
|
+
'location_id' => location_id,
|
28
|
+
'status' => status,
|
29
|
+
'limit' => limit,
|
30
|
+
'cursor' => cursor
|
31
|
+
)
|
32
|
+
_query_url = APIHelper.clean_url _query_builder
|
33
|
+
|
34
|
+
# Prepare headers.
|
35
|
+
_headers = {
|
36
|
+
'accept' => 'application/json'
|
37
|
+
}
|
38
|
+
|
39
|
+
# Prepare and execute HttpRequest.
|
40
|
+
_request = config.http_client.get(
|
41
|
+
_query_url,
|
42
|
+
headers: _headers
|
43
|
+
)
|
44
|
+
OAuth2.apply(config, _request)
|
45
|
+
_response = execute_request(_request)
|
46
|
+
|
47
|
+
# Return appropriate response type.
|
48
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
49
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
50
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
51
|
+
end
|
52
|
+
|
53
|
+
# RetrieveEmployee
|
54
|
+
# @param [String] id Required parameter: UUID for the employee that was
|
55
|
+
# requested.
|
56
|
+
# @return [RetrieveEmployeeResponse Hash] response from the API call
|
57
|
+
def retrieve_employee(id:)
|
58
|
+
warn 'Endpoint retrieve_employee in EmployeesApi is deprecated'
|
59
|
+
# Prepare query url.
|
60
|
+
_query_builder = config.get_base_uri
|
61
|
+
_query_builder << '/v2/employees/{id}'
|
62
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
63
|
+
_query_builder,
|
64
|
+
'id' => id
|
65
|
+
)
|
66
|
+
_query_url = APIHelper.clean_url _query_builder
|
67
|
+
|
68
|
+
# Prepare headers.
|
69
|
+
_headers = {
|
70
|
+
'accept' => 'application/json'
|
71
|
+
}
|
72
|
+
|
73
|
+
# Prepare and execute HttpRequest.
|
74
|
+
_request = config.http_client.get(
|
75
|
+
_query_url,
|
76
|
+
headers: _headers
|
77
|
+
)
|
78
|
+
OAuth2.apply(config, _request)
|
79
|
+
_response = execute_request(_request)
|
80
|
+
|
81
|
+
# Return appropriate response type.
|
82
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
83
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
84
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,296 @@
|
|
1
|
+
module Square
|
2
|
+
# InventoryApi
|
3
|
+
class InventoryApi < BaseApi
|
4
|
+
def initialize(config, http_call_back: nil)
|
5
|
+
super(config, http_call_back: http_call_back)
|
6
|
+
end
|
7
|
+
|
8
|
+
# Returns the [InventoryAdjustment](#type-inventoryadjustment) object
|
9
|
+
# with the provided `adjustment_id`.
|
10
|
+
# @param [String] adjustment_id Required parameter: ID of the
|
11
|
+
# [InventoryAdjustment](#type-inventoryadjustment) to retrieve.
|
12
|
+
# @return [RetrieveInventoryAdjustmentResponse Hash] response from the API call
|
13
|
+
def retrieve_inventory_adjustment(adjustment_id:)
|
14
|
+
# Prepare query url.
|
15
|
+
_query_builder = config.get_base_uri
|
16
|
+
_query_builder << '/v2/inventory/adjustment/{adjustment_id}'
|
17
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
18
|
+
_query_builder,
|
19
|
+
'adjustment_id' => adjustment_id
|
20
|
+
)
|
21
|
+
_query_url = APIHelper.clean_url _query_builder
|
22
|
+
|
23
|
+
# Prepare headers.
|
24
|
+
_headers = {
|
25
|
+
'accept' => 'application/json'
|
26
|
+
}
|
27
|
+
|
28
|
+
# Prepare and execute HttpRequest.
|
29
|
+
_request = config.http_client.get(
|
30
|
+
_query_url,
|
31
|
+
headers: _headers
|
32
|
+
)
|
33
|
+
OAuth2.apply(config, _request)
|
34
|
+
_response = execute_request(_request)
|
35
|
+
|
36
|
+
# Return appropriate response type.
|
37
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
38
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
39
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Applies adjustments and counts to the provided item quantities.
|
43
|
+
# On success: returns the current calculated counts for all objects
|
44
|
+
# referenced in the request.
|
45
|
+
# On failure: returns a list of related errors.
|
46
|
+
# @param [BatchChangeInventoryRequest] body Required parameter: An object
|
47
|
+
# containing the fields to POST for the request. See the corresponding
|
48
|
+
# object definition for field details.
|
49
|
+
# @return [BatchChangeInventoryResponse Hash] response from the API call
|
50
|
+
def batch_change_inventory(body:)
|
51
|
+
# Prepare query url.
|
52
|
+
_query_builder = config.get_base_uri
|
53
|
+
_query_builder << '/v2/inventory/batch-change'
|
54
|
+
_query_url = APIHelper.clean_url _query_builder
|
55
|
+
|
56
|
+
# Prepare headers.
|
57
|
+
_headers = {
|
58
|
+
'accept' => 'application/json',
|
59
|
+
'content-type' => 'application/json; charset=utf-8'
|
60
|
+
}
|
61
|
+
|
62
|
+
# Prepare and execute HttpRequest.
|
63
|
+
_request = config.http_client.post(
|
64
|
+
_query_url,
|
65
|
+
headers: _headers,
|
66
|
+
parameters: body.to_json
|
67
|
+
)
|
68
|
+
OAuth2.apply(config, _request)
|
69
|
+
_response = execute_request(_request)
|
70
|
+
|
71
|
+
# Return appropriate response type.
|
72
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
73
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
74
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
75
|
+
end
|
76
|
+
|
77
|
+
# Returns historical physical counts and adjustments based on the
|
78
|
+
# provided filter criteria.
|
79
|
+
# Results are paginated and sorted in ascending order according their
|
80
|
+
# `occurred_at` timestamp (oldest first).
|
81
|
+
# BatchRetrieveInventoryChanges is a catch-all query endpoint for queries
|
82
|
+
# that cannot be handled by other, simpler endpoints.
|
83
|
+
# @param [BatchRetrieveInventoryChangesRequest] body Required parameter: An
|
84
|
+
# object containing the fields to POST for the request. See the
|
85
|
+
# corresponding object definition for field details.
|
86
|
+
# @return [BatchRetrieveInventoryChangesResponse Hash] response from the API call
|
87
|
+
def batch_retrieve_inventory_changes(body:)
|
88
|
+
# Prepare query url.
|
89
|
+
_query_builder = config.get_base_uri
|
90
|
+
_query_builder << '/v2/inventory/batch-retrieve-changes'
|
91
|
+
_query_url = APIHelper.clean_url _query_builder
|
92
|
+
|
93
|
+
# Prepare headers.
|
94
|
+
_headers = {
|
95
|
+
'accept' => 'application/json',
|
96
|
+
'content-type' => 'application/json; charset=utf-8'
|
97
|
+
}
|
98
|
+
|
99
|
+
# Prepare and execute HttpRequest.
|
100
|
+
_request = config.http_client.post(
|
101
|
+
_query_url,
|
102
|
+
headers: _headers,
|
103
|
+
parameters: body.to_json
|
104
|
+
)
|
105
|
+
OAuth2.apply(config, _request)
|
106
|
+
_response = execute_request(_request)
|
107
|
+
|
108
|
+
# Return appropriate response type.
|
109
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
110
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
111
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
112
|
+
end
|
113
|
+
|
114
|
+
# Returns current counts for the provided
|
115
|
+
# [CatalogObject](#type-catalogobject)s at the requested
|
116
|
+
# [Location](#type-location)s.
|
117
|
+
# Results are paginated and sorted in descending order according to their
|
118
|
+
# `calculated_at` timestamp (newest first).
|
119
|
+
# When `updated_after` is specified, only counts that have changed since
|
120
|
+
# that
|
121
|
+
# time (based on the server timestamp for the most recent change) are
|
122
|
+
# returned. This allows clients to perform a "sync" operation, for example
|
123
|
+
# in response to receiving a Webhook notification.
|
124
|
+
# @param [BatchRetrieveInventoryCountsRequest] body Required parameter: An
|
125
|
+
# object containing the fields to POST for the request. See the
|
126
|
+
# corresponding object definition for field details.
|
127
|
+
# @return [BatchRetrieveInventoryCountsResponse Hash] response from the API call
|
128
|
+
def batch_retrieve_inventory_counts(body:)
|
129
|
+
# Prepare query url.
|
130
|
+
_query_builder = config.get_base_uri
|
131
|
+
_query_builder << '/v2/inventory/batch-retrieve-counts'
|
132
|
+
_query_url = APIHelper.clean_url _query_builder
|
133
|
+
|
134
|
+
# Prepare headers.
|
135
|
+
_headers = {
|
136
|
+
'accept' => 'application/json',
|
137
|
+
'content-type' => 'application/json; charset=utf-8'
|
138
|
+
}
|
139
|
+
|
140
|
+
# Prepare and execute HttpRequest.
|
141
|
+
_request = config.http_client.post(
|
142
|
+
_query_url,
|
143
|
+
headers: _headers,
|
144
|
+
parameters: body.to_json
|
145
|
+
)
|
146
|
+
OAuth2.apply(config, _request)
|
147
|
+
_response = execute_request(_request)
|
148
|
+
|
149
|
+
# Return appropriate response type.
|
150
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
151
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
152
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
153
|
+
end
|
154
|
+
|
155
|
+
# Returns the [InventoryPhysicalCount](#type-inventoryphysicalcount)
|
156
|
+
# object with the provided `physical_count_id`.
|
157
|
+
# @param [String] physical_count_id Required parameter: ID of the
|
158
|
+
# [InventoryPhysicalCount](#type-inventoryphysicalcount) to retrieve.
|
159
|
+
# @return [RetrieveInventoryPhysicalCountResponse Hash] response from the API call
|
160
|
+
def retrieve_inventory_physical_count(physical_count_id:)
|
161
|
+
# Prepare query url.
|
162
|
+
_query_builder = config.get_base_uri
|
163
|
+
_query_builder << '/v2/inventory/physical-count/{physical_count_id}'
|
164
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
165
|
+
_query_builder,
|
166
|
+
'physical_count_id' => physical_count_id
|
167
|
+
)
|
168
|
+
_query_url = APIHelper.clean_url _query_builder
|
169
|
+
|
170
|
+
# Prepare headers.
|
171
|
+
_headers = {
|
172
|
+
'accept' => 'application/json'
|
173
|
+
}
|
174
|
+
|
175
|
+
# Prepare and execute HttpRequest.
|
176
|
+
_request = config.http_client.get(
|
177
|
+
_query_url,
|
178
|
+
headers: _headers
|
179
|
+
)
|
180
|
+
OAuth2.apply(config, _request)
|
181
|
+
_response = execute_request(_request)
|
182
|
+
|
183
|
+
# Return appropriate response type.
|
184
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
185
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
186
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
187
|
+
end
|
188
|
+
|
189
|
+
# Retrieves the current calculated stock count for a given
|
190
|
+
# [CatalogObject](#type-catalogobject) at a given set of
|
191
|
+
# [Location](#type-location)s. Responses are paginated and unsorted.
|
192
|
+
# For more sophisticated queries, use a batch endpoint.
|
193
|
+
# @param [String] catalog_object_id Required parameter: ID of the
|
194
|
+
# [CatalogObject](#type-catalogobject) to retrieve.
|
195
|
+
# @param [String] location_ids Optional parameter: The
|
196
|
+
# [Location](#type-location) IDs to look up as a comma-separated list. An
|
197
|
+
# empty list queries all locations.
|
198
|
+
# @param [String] cursor Optional parameter: A pagination cursor returned by
|
199
|
+
# a previous call to this endpoint. Provide this to retrieve the next set of
|
200
|
+
# results for the original query. See the
|
201
|
+
# [Pagination](https://developer.squareup.com/docs/docs/working-with-apis/pa
|
202
|
+
# gination) guide for more information.
|
203
|
+
# @return [RetrieveInventoryCountResponse Hash] response from the API call
|
204
|
+
def retrieve_inventory_count(catalog_object_id:,
|
205
|
+
location_ids: nil,
|
206
|
+
cursor: nil)
|
207
|
+
# Prepare query url.
|
208
|
+
_query_builder = config.get_base_uri
|
209
|
+
_query_builder << '/v2/inventory/{catalog_object_id}'
|
210
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
211
|
+
_query_builder,
|
212
|
+
'catalog_object_id' => catalog_object_id
|
213
|
+
)
|
214
|
+
_query_builder = APIHelper.append_url_with_query_parameters(
|
215
|
+
_query_builder,
|
216
|
+
'location_ids' => location_ids,
|
217
|
+
'cursor' => cursor
|
218
|
+
)
|
219
|
+
_query_url = APIHelper.clean_url _query_builder
|
220
|
+
|
221
|
+
# Prepare headers.
|
222
|
+
_headers = {
|
223
|
+
'accept' => 'application/json'
|
224
|
+
}
|
225
|
+
|
226
|
+
# Prepare and execute HttpRequest.
|
227
|
+
_request = config.http_client.get(
|
228
|
+
_query_url,
|
229
|
+
headers: _headers
|
230
|
+
)
|
231
|
+
OAuth2.apply(config, _request)
|
232
|
+
_response = execute_request(_request)
|
233
|
+
|
234
|
+
# Return appropriate response type.
|
235
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
236
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
237
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
238
|
+
end
|
239
|
+
|
240
|
+
# Returns a set of physical counts and inventory adjustments for the
|
241
|
+
# provided [CatalogObject](#type-catalogobject) at the requested
|
242
|
+
# [Location](#type-location)s.
|
243
|
+
# Results are paginated and sorted in descending order according to their
|
244
|
+
# `occurred_at` timestamp (newest first).
|
245
|
+
# There are no limits on how far back the caller can page. This endpoint can
|
246
|
+
# be
|
247
|
+
# used to display recent changes for a specific item. For more
|
248
|
+
# sophisticated queries, use a batch endpoint.
|
249
|
+
# @param [String] catalog_object_id Required parameter: ID of the
|
250
|
+
# [CatalogObject](#type-catalogobject) to retrieve.
|
251
|
+
# @param [String] location_ids Optional parameter: The
|
252
|
+
# [Location](#type-location) IDs to look up as a comma-separated list. An
|
253
|
+
# empty list queries all locations.
|
254
|
+
# @param [String] cursor Optional parameter: A pagination cursor returned by
|
255
|
+
# a previous call to this endpoint. Provide this to retrieve the next set of
|
256
|
+
# results for the original query. See the
|
257
|
+
# [Pagination](https://developer.squareup.com/docs/working-with-apis/paginat
|
258
|
+
# ion) guide for more information.
|
259
|
+
# @return [RetrieveInventoryChangesResponse Hash] response from the API call
|
260
|
+
def retrieve_inventory_changes(catalog_object_id:,
|
261
|
+
location_ids: nil,
|
262
|
+
cursor: nil)
|
263
|
+
# Prepare query url.
|
264
|
+
_query_builder = config.get_base_uri
|
265
|
+
_query_builder << '/v2/inventory/{catalog_object_id}/changes'
|
266
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
267
|
+
_query_builder,
|
268
|
+
'catalog_object_id' => catalog_object_id
|
269
|
+
)
|
270
|
+
_query_builder = APIHelper.append_url_with_query_parameters(
|
271
|
+
_query_builder,
|
272
|
+
'location_ids' => location_ids,
|
273
|
+
'cursor' => cursor
|
274
|
+
)
|
275
|
+
_query_url = APIHelper.clean_url _query_builder
|
276
|
+
|
277
|
+
# Prepare headers.
|
278
|
+
_headers = {
|
279
|
+
'accept' => 'application/json'
|
280
|
+
}
|
281
|
+
|
282
|
+
# Prepare and execute HttpRequest.
|
283
|
+
_request = config.http_client.get(
|
284
|
+
_query_url,
|
285
|
+
headers: _headers
|
286
|
+
)
|
287
|
+
OAuth2.apply(config, _request)
|
288
|
+
_response = execute_request(_request)
|
289
|
+
|
290
|
+
# Return appropriate response type.
|
291
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
292
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
293
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
294
|
+
end
|
295
|
+
end
|
296
|
+
end
|
@@ -0,0 +1,358 @@
|
|
1
|
+
module Square
|
2
|
+
# InvoicesApi
|
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
|
+
# Returns a list of invoices for a given location. The response
|
9
|
+
# is paginated. If truncated, the response includes a `cursor` that you
|
10
|
+
# use in a subsequent request to fetch the next set of invoices.
|
11
|
+
# For more information about retrieving invoices, see [Retrieve
|
12
|
+
# invoices](https://developer.squareup.com/docs/docs/invoices-api/overview#r
|
13
|
+
# etrieve-invoices).
|
14
|
+
# @param [String] location_id Required parameter: The ID of the location for
|
15
|
+
# which to list invoices.
|
16
|
+
# @param [String] cursor Optional parameter: A pagination cursor returned by
|
17
|
+
# a previous call to this endpoint. Provide this cursor to retrieve the
|
18
|
+
# next set of results for your original query. For more information, see
|
19
|
+
# [Pagination](https://developer.squareup.com/docs/docs/working-with-apis/pa
|
20
|
+
# gination).
|
21
|
+
# @param [Integer] limit Optional parameter: The maximum number of invoices
|
22
|
+
# to return (200 is the maximum `limit`). If not provided, the server uses
|
23
|
+
# a default limit of 100 invoices.
|
24
|
+
# @return [ListInvoicesResponse Hash] response from the API call
|
25
|
+
def list_invoices(location_id:,
|
26
|
+
cursor: nil,
|
27
|
+
limit: nil)
|
28
|
+
# Prepare query url.
|
29
|
+
_query_builder = config.get_base_uri
|
30
|
+
_query_builder << '/v2/invoices'
|
31
|
+
_query_builder = APIHelper.append_url_with_query_parameters(
|
32
|
+
_query_builder,
|
33
|
+
'location_id' => location_id,
|
34
|
+
'cursor' => cursor,
|
35
|
+
'limit' => limit
|
36
|
+
)
|
37
|
+
_query_url = APIHelper.clean_url _query_builder
|
38
|
+
|
39
|
+
# Prepare headers.
|
40
|
+
_headers = {
|
41
|
+
'accept' => 'application/json'
|
42
|
+
}
|
43
|
+
|
44
|
+
# Prepare and execute HttpRequest.
|
45
|
+
_request = config.http_client.get(
|
46
|
+
_query_url,
|
47
|
+
headers: _headers
|
48
|
+
)
|
49
|
+
OAuth2.apply(config, _request)
|
50
|
+
_response = execute_request(_request)
|
51
|
+
|
52
|
+
# Return appropriate response type.
|
53
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
54
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
55
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Creates a draft [invoice](#type-invoice)
|
59
|
+
# for an order created using the Orders API.
|
60
|
+
# A draft invoice remains in your account and no action is taken.
|
61
|
+
# You must publish the invoice before Square can process it (send it to the
|
62
|
+
# customer's email address or charge the customer’s card on file).
|
63
|
+
# For more information, see [Manage Invoices Using the Invoices
|
64
|
+
# API](https://developer.squareup.com/docs/docs/invoices-api/overview).
|
65
|
+
# @param [CreateInvoiceRequest] body Required parameter: An object
|
66
|
+
# containing the fields to POST for the request. See the corresponding
|
67
|
+
# object definition for field details.
|
68
|
+
# @return [CreateInvoiceResponse Hash] response from the API call
|
69
|
+
def create_invoice(body:)
|
70
|
+
# Prepare query url.
|
71
|
+
_query_builder = config.get_base_uri
|
72
|
+
_query_builder << '/v2/invoices'
|
73
|
+
_query_url = APIHelper.clean_url _query_builder
|
74
|
+
|
75
|
+
# Prepare headers.
|
76
|
+
_headers = {
|
77
|
+
'accept' => 'application/json',
|
78
|
+
'content-type' => 'application/json; charset=utf-8'
|
79
|
+
}
|
80
|
+
|
81
|
+
# Prepare and execute HttpRequest.
|
82
|
+
_request = config.http_client.post(
|
83
|
+
_query_url,
|
84
|
+
headers: _headers,
|
85
|
+
parameters: body.to_json
|
86
|
+
)
|
87
|
+
OAuth2.apply(config, _request)
|
88
|
+
_response = execute_request(_request)
|
89
|
+
|
90
|
+
# Return appropriate response type.
|
91
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
92
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
93
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
94
|
+
end
|
95
|
+
|
96
|
+
# Searches for invoices from a location specified in
|
97
|
+
# the filter. You can optionally specify customers in the filter for whom to
|
98
|
+
# retrieve invoices. In the current implementation, you can only specify one
|
99
|
+
# location and
|
100
|
+
# optionally one customer.
|
101
|
+
# The response is paginated. If truncated, the response includes a `cursor`
|
102
|
+
# that you use in a subsequent request to fetch the next set of invoices.
|
103
|
+
# For more information about retrieving invoices, see [Retrieve
|
104
|
+
# invoices](https://developer.squareup.com/docs/docs/invoices-api/overview#r
|
105
|
+
# etrieve-invoices).
|
106
|
+
# @param [SearchInvoicesRequest] body Required parameter: An object
|
107
|
+
# containing the fields to POST for the request. See the corresponding
|
108
|
+
# object definition for field details.
|
109
|
+
# @return [SearchInvoicesResponse Hash] response from the API call
|
110
|
+
def search_invoices(body:)
|
111
|
+
# Prepare query url.
|
112
|
+
_query_builder = config.get_base_uri
|
113
|
+
_query_builder << '/v2/invoices/search'
|
114
|
+
_query_url = APIHelper.clean_url _query_builder
|
115
|
+
|
116
|
+
# Prepare headers.
|
117
|
+
_headers = {
|
118
|
+
'accept' => 'application/json',
|
119
|
+
'content-type' => 'application/json; charset=utf-8'
|
120
|
+
}
|
121
|
+
|
122
|
+
# Prepare and execute HttpRequest.
|
123
|
+
_request = config.http_client.post(
|
124
|
+
_query_url,
|
125
|
+
headers: _headers,
|
126
|
+
parameters: body.to_json
|
127
|
+
)
|
128
|
+
OAuth2.apply(config, _request)
|
129
|
+
_response = execute_request(_request)
|
130
|
+
|
131
|
+
# Return appropriate response type.
|
132
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
133
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
134
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
135
|
+
end
|
136
|
+
|
137
|
+
# Deletes the specified invoice. When an invoice is deleted, the
|
138
|
+
# associated Order status changes to CANCELED. You can only delete a draft
|
139
|
+
# invoice (you cannot delete an invoice scheduled for publication, or a
|
140
|
+
# published invoice).
|
141
|
+
# @param [String] invoice_id Required parameter: The ID of the invoice to
|
142
|
+
# delete.
|
143
|
+
# @param [Integer] version Optional parameter: The version of the
|
144
|
+
# [invoice](#type-invoice) to delete. If you do not know the version, you
|
145
|
+
# can call [GetInvoice](#endpoint-Invoices-GetInvoice) or
|
146
|
+
# [ListInvoices](#endpoint-Invoices-ListInvoices).
|
147
|
+
# @return [DeleteInvoiceResponse Hash] response from the API call
|
148
|
+
def delete_invoice(invoice_id:,
|
149
|
+
version: nil)
|
150
|
+
# Prepare query url.
|
151
|
+
_query_builder = config.get_base_uri
|
152
|
+
_query_builder << '/v2/invoices/{invoice_id}'
|
153
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
154
|
+
_query_builder,
|
155
|
+
'invoice_id' => invoice_id
|
156
|
+
)
|
157
|
+
_query_builder = APIHelper.append_url_with_query_parameters(
|
158
|
+
_query_builder,
|
159
|
+
'version' => version
|
160
|
+
)
|
161
|
+
_query_url = APIHelper.clean_url _query_builder
|
162
|
+
|
163
|
+
# Prepare headers.
|
164
|
+
_headers = {
|
165
|
+
'accept' => 'application/json'
|
166
|
+
}
|
167
|
+
|
168
|
+
# Prepare and execute HttpRequest.
|
169
|
+
_request = config.http_client.delete(
|
170
|
+
_query_url,
|
171
|
+
headers: _headers
|
172
|
+
)
|
173
|
+
OAuth2.apply(config, _request)
|
174
|
+
_response = execute_request(_request)
|
175
|
+
|
176
|
+
# Return appropriate response type.
|
177
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
178
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
179
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
180
|
+
end
|
181
|
+
|
182
|
+
# Retrieves an invoice by invoice ID.
|
183
|
+
# @param [String] invoice_id Required parameter: The id of the invoice to
|
184
|
+
# retrieve.
|
185
|
+
# @return [GetInvoiceResponse Hash] response from the API call
|
186
|
+
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' => invoice_id
|
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(_response, data: decoded, errors: _errors)
|
213
|
+
end
|
214
|
+
|
215
|
+
# Updates an invoice by modifying field values, clearing field values, or
|
216
|
+
# both
|
217
|
+
# as specified in the request.
|
218
|
+
# There are no restrictions to updating an invoice in a draft state.
|
219
|
+
# However, there are guidelines for updating a published invoice.
|
220
|
+
# For more information, see [Update an
|
221
|
+
# invoice](https://developer.squareup.com/docs/docs/invoices-api/overview#up
|
222
|
+
# date-an-invoice).
|
223
|
+
# @param [String] invoice_id Required parameter: The id of the invoice to
|
224
|
+
# update.
|
225
|
+
# @param [UpdateInvoiceRequest] body Required parameter: An object
|
226
|
+
# containing the fields to POST for the request. See the corresponding
|
227
|
+
# object definition for field details.
|
228
|
+
# @return [UpdateInvoiceResponse Hash] response from the API call
|
229
|
+
def update_invoice(invoice_id:,
|
230
|
+
body:)
|
231
|
+
# Prepare query url.
|
232
|
+
_query_builder = config.get_base_uri
|
233
|
+
_query_builder << '/v2/invoices/{invoice_id}'
|
234
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
235
|
+
_query_builder,
|
236
|
+
'invoice_id' => invoice_id
|
237
|
+
)
|
238
|
+
_query_url = APIHelper.clean_url _query_builder
|
239
|
+
|
240
|
+
# Prepare headers.
|
241
|
+
_headers = {
|
242
|
+
'accept' => 'application/json',
|
243
|
+
'content-type' => 'application/json; charset=utf-8'
|
244
|
+
}
|
245
|
+
|
246
|
+
# Prepare and execute HttpRequest.
|
247
|
+
_request = config.http_client.put(
|
248
|
+
_query_url,
|
249
|
+
headers: _headers,
|
250
|
+
parameters: body.to_json
|
251
|
+
)
|
252
|
+
OAuth2.apply(config, _request)
|
253
|
+
_response = execute_request(_request)
|
254
|
+
|
255
|
+
# Return appropriate response type.
|
256
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
257
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
258
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
259
|
+
end
|
260
|
+
|
261
|
+
# Cancels an invoice. The seller cannot collect payments for
|
262
|
+
# the canceled invoice.
|
263
|
+
# You cannot cancel an invoice in a terminal state: `PAID`, `REFUNDED`,
|
264
|
+
# `CANCELED`, or `FAILED`.
|
265
|
+
# @param [String] invoice_id Required parameter: The ID of the
|
266
|
+
# [invoice](#type-invoice) to cancel.
|
267
|
+
# @param [CancelInvoiceRequest] body Required parameter: An object
|
268
|
+
# containing the fields to POST for the request. See the corresponding
|
269
|
+
# object definition for field details.
|
270
|
+
# @return [CancelInvoiceResponse Hash] response from the API call
|
271
|
+
def cancel_invoice(invoice_id:,
|
272
|
+
body:)
|
273
|
+
# Prepare query url.
|
274
|
+
_query_builder = config.get_base_uri
|
275
|
+
_query_builder << '/v2/invoices/{invoice_id}/cancel'
|
276
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
277
|
+
_query_builder,
|
278
|
+
'invoice_id' => invoice_id
|
279
|
+
)
|
280
|
+
_query_url = APIHelper.clean_url _query_builder
|
281
|
+
|
282
|
+
# Prepare headers.
|
283
|
+
_headers = {
|
284
|
+
'accept' => 'application/json',
|
285
|
+
'content-type' => 'application/json; charset=utf-8'
|
286
|
+
}
|
287
|
+
|
288
|
+
# Prepare and execute HttpRequest.
|
289
|
+
_request = config.http_client.post(
|
290
|
+
_query_url,
|
291
|
+
headers: _headers,
|
292
|
+
parameters: body.to_json
|
293
|
+
)
|
294
|
+
OAuth2.apply(config, _request)
|
295
|
+
_response = execute_request(_request)
|
296
|
+
|
297
|
+
# Return appropriate response type.
|
298
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
299
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
300
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
301
|
+
end
|
302
|
+
|
303
|
+
# Publishes the specified draft invoice.
|
304
|
+
# After an invoice is published, Square
|
305
|
+
# follows up based on the invoice configuration. For example, Square
|
306
|
+
# sends the invoice to the customer's email address, charges the customer's
|
307
|
+
# card on file, or does
|
308
|
+
# nothing. Square also makes the invoice available on a Square-hosted
|
309
|
+
# invoice page.
|
310
|
+
# The invoice `status` also changes from `DRAFT` to a status
|
311
|
+
# based on the invoice configuration. For example, the status changes to
|
312
|
+
# `UNPAID` if
|
313
|
+
# Square emails the invoice or `PARTIALLY_PAID` if Square charge a card on
|
314
|
+
# file for a portion of the
|
315
|
+
# invoice amount).
|
316
|
+
# For more information, see
|
317
|
+
# [Create and publish an
|
318
|
+
# invoice](https://developer.squareup.com/docs/docs/invoices-api/overview#cr
|
319
|
+
# eate-and-publish-an-invoice).
|
320
|
+
# @param [String] invoice_id Required parameter: The id of the invoice to
|
321
|
+
# publish.
|
322
|
+
# @param [PublishInvoiceRequest] body Required parameter: An object
|
323
|
+
# containing the fields to POST for the request. See the corresponding
|
324
|
+
# object definition for field details.
|
325
|
+
# @return [PublishInvoiceResponse Hash] response from the API call
|
326
|
+
def publish_invoice(invoice_id:,
|
327
|
+
body:)
|
328
|
+
# Prepare query url.
|
329
|
+
_query_builder = config.get_base_uri
|
330
|
+
_query_builder << '/v2/invoices/{invoice_id}/publish'
|
331
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
332
|
+
_query_builder,
|
333
|
+
'invoice_id' => invoice_id
|
334
|
+
)
|
335
|
+
_query_url = APIHelper.clean_url _query_builder
|
336
|
+
|
337
|
+
# Prepare headers.
|
338
|
+
_headers = {
|
339
|
+
'accept' => 'application/json',
|
340
|
+
'content-type' => 'application/json; charset=utf-8'
|
341
|
+
}
|
342
|
+
|
343
|
+
# Prepare and execute HttpRequest.
|
344
|
+
_request = config.http_client.post(
|
345
|
+
_query_url,
|
346
|
+
headers: _headers,
|
347
|
+
parameters: body.to_json
|
348
|
+
)
|
349
|
+
OAuth2.apply(config, _request)
|
350
|
+
_response = execute_request(_request)
|
351
|
+
|
352
|
+
# Return appropriate response type.
|
353
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
354
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
355
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
356
|
+
end
|
357
|
+
end
|
358
|
+
end
|