square.rb 5.3.0.20200528 → 6.4.0.20200923
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 +317 -285
- data/lib/square.rb +4 -2
- data/lib/square/api/base_api.rb +2 -2
- data/lib/square/api/catalog_api.rb +76 -57
- data/lib/square/api/disputes_api.rb +3 -26
- data/lib/square/api/employees_api.rb +3 -2
- data/lib/square/api/inventory_api.rb +5 -4
- data/lib/square/api/invoices_api.rb +343 -0
- data/lib/square/api/labor_api.rb +77 -0
- data/lib/square/api/locations_api.rb +7 -2
- data/lib/square/api/merchants_api.rb +2 -1
- data/lib/square/api/orders_api.rb +59 -85
- data/lib/square/api/payments_api.rb +15 -24
- data/lib/square/api/refunds_api.rb +12 -7
- data/lib/square/api/subscriptions_api.rb +251 -0
- data/lib/square/api/team_api.rb +326 -0
- data/lib/square/api/transactions_api.rb +0 -71
- data/lib/square/api/v1_employees_api.rb +3 -76
- data/lib/square/api/v1_items_api.rb +0 -360
- data/lib/square/api/v1_locations_api.rb +0 -18
- data/lib/square/api/v1_transactions_api.rb +1 -19
- data/lib/square/client.rb +29 -16
- data/lib/square/configuration.rb +12 -4
- data/test/api/api_test_base.rb +1 -6
- data/test/api/test_catalog_api.rb +1 -4
- data/test/api/test_customers_api.rb +1 -4
- data/test/api/test_employees_api.rb +1 -4
- data/test/api/test_labor_api.rb +2 -6
- data/test/api/test_locations_api.rb +21 -32
- data/test/api/test_merchants_api.rb +1 -4
- data/test/api/test_payments_api.rb +3 -6
- data/test/api/test_refunds_api.rb +3 -6
- data/test/http_response_catcher.rb +0 -5
- data/test/test_helper.rb +0 -5
- metadata +33 -13
- data/lib/square/api/reporting_api.rb +0 -138
data/lib/square.rb
CHANGED
@@ -46,14 +46,16 @@ require_relative 'square/api/devices_api.rb'
|
|
46
46
|
require_relative 'square/api/disputes_api.rb'
|
47
47
|
require_relative 'square/api/employees_api.rb'
|
48
48
|
require_relative 'square/api/inventory_api.rb'
|
49
|
+
require_relative 'square/api/invoices_api.rb'
|
49
50
|
require_relative 'square/api/labor_api.rb'
|
50
51
|
require_relative 'square/api/locations_api.rb'
|
51
|
-
require_relative 'square/api/reporting_api.rb'
|
52
52
|
require_relative 'square/api/checkout_api.rb'
|
53
|
-
require_relative 'square/api/orders_api.rb'
|
54
53
|
require_relative 'square/api/transactions_api.rb'
|
55
54
|
require_relative 'square/api/loyalty_api.rb'
|
56
55
|
require_relative 'square/api/merchants_api.rb'
|
56
|
+
require_relative 'square/api/orders_api.rb'
|
57
57
|
require_relative 'square/api/payments_api.rb'
|
58
58
|
require_relative 'square/api/refunds_api.rb'
|
59
|
+
require_relative 'square/api/subscriptions_api.rb'
|
60
|
+
require_relative 'square/api/team_api.rb'
|
59
61
|
require_relative 'square/api/terminal_api.rb'
|
data/lib/square/api/base_api.rb
CHANGED
@@ -8,8 +8,8 @@ module Square
|
|
8
8
|
@http_call_back = http_call_back
|
9
9
|
|
10
10
|
@global_headers = {
|
11
|
-
'user-agent' => 'Square-Ruby-SDK/
|
12
|
-
'Square-Version' =>
|
11
|
+
'user-agent' => 'Square-Ruby-SDK/6.4.0.20200923',
|
12
|
+
'Square-Version' => config.square_version
|
13
13
|
}
|
14
14
|
end
|
15
15
|
|
@@ -131,42 +131,14 @@ module Square
|
|
131
131
|
ApiResponse.new(_response, data: decoded, errors: _errors)
|
132
132
|
end
|
133
133
|
|
134
|
-
#
|
135
|
-
#
|
136
|
-
# [CatalogObject](#type-catalogobject).
|
137
|
-
#
|
138
|
-
#
|
139
|
-
#
|
140
|
-
#
|
141
|
-
#
|
142
|
-
# JPEG, PJPEG, PNG, or GIF format. The maximum file size is 15MB. The
|
143
|
-
# following is an example of such an HTTP request:
|
144
|
-
# ```
|
145
|
-
# POST /v2/catalog/images
|
146
|
-
# Accept: application/json
|
147
|
-
# Content-Type: multipart/form-data;boundary="boundary"
|
148
|
-
# Square-Version: XXXX-XX-XX
|
149
|
-
# Authorization: Bearer {ACCESS_TOKEN}
|
150
|
-
# --boundary
|
151
|
-
# Content-Disposition: form-data; name="request"
|
152
|
-
# Content-Type: application/json
|
153
|
-
# {
|
154
|
-
# "idempotency_key":"528dea59-7bfb-43c1-bd48-4a6bba7dd61f86",
|
155
|
-
# "object_id": "ND6EA5AAJEO5WL3JNNIAQA32",
|
156
|
-
# "image":{
|
157
|
-
# "id":"#TEMP_ID",
|
158
|
-
# "type":"IMAGE",
|
159
|
-
# "image_data":{
|
160
|
-
# "caption":"A picture of a cup of coffee"
|
161
|
-
# }
|
162
|
-
# }
|
163
|
-
# }
|
164
|
-
# --boundary
|
165
|
-
# Content-Disposition: form-data; name="image"; filename="Coffee.jpg"
|
166
|
-
# Content-Type: image/jpeg
|
167
|
-
# {ACTUAL_IMAGE_BYTES}
|
168
|
-
# --boundary
|
169
|
-
# ```
|
134
|
+
# Uploads an image file to be represented by an
|
135
|
+
# [CatalogImage](#type-catalogimage) object linked to an existing
|
136
|
+
# [CatalogObject](#type-catalogobject) instance. A call to this endpoint can
|
137
|
+
# upload an image, link an image to
|
138
|
+
# a catalog object, or do both.
|
139
|
+
# This `CreateCatalogImage` endpoint accepts HTTP multipart/form-data
|
140
|
+
# requests with a JSON part and an image file part in
|
141
|
+
# JPEG, PJPEG, PNG, or GIF format. The maximum file size is 15MB.
|
170
142
|
# Additional information and an example cURL request can be found in the
|
171
143
|
# [Create a Catalog Image
|
172
144
|
# recipe](https://developer.squareup.com/docs/more-apis/catalog/cookbook/cre
|
@@ -222,8 +194,8 @@ module Square
|
|
222
194
|
ApiResponse.new(_response, data: decoded, errors: _errors)
|
223
195
|
end
|
224
196
|
|
225
|
-
#
|
226
|
-
# limits
|
197
|
+
# Retrieves information about the Square Catalog API, such as batch size
|
198
|
+
# limits that can be used by the `BatchUpsertCatalogObjects` endpoint.
|
227
199
|
# @return [CatalogInfoResponse Hash] response from the API call
|
228
200
|
def catalog_info
|
229
201
|
# Prepare query url.
|
@@ -400,7 +372,7 @@ module Square
|
|
400
372
|
# `false`
|
401
373
|
# @return [RetrieveCatalogObjectResponse Hash] response from the API call
|
402
374
|
def retrieve_catalog_object(object_id:,
|
403
|
-
include_related_objects:
|
375
|
+
include_related_objects: false)
|
404
376
|
# Prepare query url.
|
405
377
|
_query_builder = config.get_base_uri
|
406
378
|
_query_builder << '/v2/catalog/object/{object_id}'
|
@@ -433,24 +405,23 @@ module Square
|
|
433
405
|
ApiResponse.new(_response, data: decoded, errors: _errors)
|
434
406
|
end
|
435
407
|
|
436
|
-
#
|
437
|
-
#
|
438
|
-
#
|
439
|
-
#
|
440
|
-
#
|
441
|
-
# [
|
442
|
-
#
|
443
|
-
#
|
444
|
-
#
|
445
|
-
#
|
446
|
-
#
|
447
|
-
#
|
448
|
-
#
|
449
|
-
# ,
|
450
|
-
#
|
451
|
-
#
|
452
|
-
#
|
453
|
-
# ationsforitemoptionvalues).
|
408
|
+
# Searches for [CatalogObject](#type-CatalogObject) of any types against
|
409
|
+
# supported search attribute values,
|
410
|
+
# excluding custom attribute values on items or item variations, against one
|
411
|
+
# or more of the specified query expressions,
|
412
|
+
# This (`SearchCatalogObjects`) endpoint differs from the
|
413
|
+
# [SearchCatalogItems](#endpoint-Catalog-SearchCatalogItems)
|
414
|
+
# endpoint in the following aspects:
|
415
|
+
# - `SearchCatalogItems` can only search for items or item variations,
|
416
|
+
# whereas `SearchCatalogObjects` can search for any type of catalog objects.
|
417
|
+
# - `SearchCatalogItems` supports the custom attribute query filters to
|
418
|
+
# return items or item variations that contain custom attribute values,
|
419
|
+
# where `SearchCatalogObjects` does not.
|
420
|
+
# - `SearchCatalogItems` does not support the `include_deleted_objects`
|
421
|
+
# filter to search for deleted items or item variations, whereas
|
422
|
+
# `SearchCatalogObjects` does.
|
423
|
+
# - The both endpoints have different call conventions, including the query
|
424
|
+
# filter formats.
|
454
425
|
# @param [SearchCatalogObjectsRequest] body Required parameter: An object
|
455
426
|
# containing the fields to POST for the request. See the corresponding
|
456
427
|
# object definition for field details.
|
@@ -482,6 +453,54 @@ module Square
|
|
482
453
|
ApiResponse.new(_response, data: decoded, errors: _errors)
|
483
454
|
end
|
484
455
|
|
456
|
+
# Searches for catalog items or item variations by matching supported search
|
457
|
+
# attribute values, including
|
458
|
+
# custom attribute values, against one or more of the specified query
|
459
|
+
# expressions,
|
460
|
+
# This (`SearchCatalogItems`) endpoint differs from the
|
461
|
+
# [SearchCatalogObjects](#endpoint-Catalog-SearchCatalogObjects)
|
462
|
+
# endpoint in the following aspects:
|
463
|
+
# - `SearchCatalogItems` can only search for items or item variations,
|
464
|
+
# whereas `SearchCatalogObjects` can search for any type of catalog objects.
|
465
|
+
# - `SearchCatalogItems` supports the custom attribute query filters to
|
466
|
+
# return items or item variations that contain custom attribute values,
|
467
|
+
# where `SearchCatalogObjects` does not.
|
468
|
+
# - `SearchCatalogItems` does not support the `include_deleted_objects`
|
469
|
+
# filter to search for deleted items or item variations, whereas
|
470
|
+
# `SearchCatalogObjects` does.
|
471
|
+
# - The both endpoints use different call conventions, including the query
|
472
|
+
# filter formats.
|
473
|
+
# @param [SearchCatalogItemsRequest] body Required parameter: An object
|
474
|
+
# containing the fields to POST for the request. See the corresponding
|
475
|
+
# object definition for field details.
|
476
|
+
# @return [SearchCatalogItemsResponse Hash] response from the API call
|
477
|
+
def search_catalog_items(body:)
|
478
|
+
# Prepare query url.
|
479
|
+
_query_builder = config.get_base_uri
|
480
|
+
_query_builder << '/v2/catalog/search-catalog-items'
|
481
|
+
_query_url = APIHelper.clean_url _query_builder
|
482
|
+
|
483
|
+
# Prepare headers.
|
484
|
+
_headers = {
|
485
|
+
'accept' => 'application/json',
|
486
|
+
'content-type' => 'application/json; charset=utf-8'
|
487
|
+
}
|
488
|
+
|
489
|
+
# Prepare and execute HttpRequest.
|
490
|
+
_request = config.http_client.post(
|
491
|
+
_query_url,
|
492
|
+
headers: _headers,
|
493
|
+
parameters: body.to_json
|
494
|
+
)
|
495
|
+
OAuth2.apply(config, _request)
|
496
|
+
_response = execute_request(_request)
|
497
|
+
|
498
|
+
# Return appropriate response type.
|
499
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
500
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
501
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
502
|
+
end
|
503
|
+
|
485
504
|
# Updates the [CatalogModifierList](#type-catalogmodifierlist) objects
|
486
505
|
# that apply to the targeted [CatalogItem](#type-catalogitem) without having
|
487
506
|
# to perform an upsert on the entire item.
|
@@ -92,9 +92,6 @@ module Square
|
|
92
92
|
# Square debits the disputed amount from the seller’s Square
|
93
93
|
# account. If the Square account balance does not have
|
94
94
|
# sufficient funds, Square debits the associated bank account.
|
95
|
-
# For an overview of the Disputes API, see
|
96
|
-
# [Overview](https://developer.squareup.com/docs/docs/disputes-api/overview)
|
97
|
-
# .
|
98
95
|
# @param [String] dispute_id Required parameter: ID of the dispute you want
|
99
96
|
# to accept.
|
100
97
|
# @return [AcceptDisputeResponse Hash] response from the API call
|
@@ -244,20 +241,7 @@ module Square
|
|
244
241
|
# Uploads a file to use as evidence in a dispute challenge. The endpoint
|
245
242
|
# accepts
|
246
243
|
# HTTP multipart/form-data file uploads in HEIC, HEIF, JPEG, PDF, PNG,
|
247
|
-
# and TIFF formats.
|
248
|
-
# ```
|
249
|
-
# curl -X POST \
|
250
|
-
# -H 'Accept: application/json' \
|
251
|
-
# -H 'Authorization: Bearer {{ACCESS_TOKEN}}' \
|
252
|
-
# -H 'Content-Type: multipart/form-data' \
|
253
|
-
# -F 'evidence=@/path/to/file/filename.tiff' \
|
254
|
-
# -F 'request={ "idempotency_key":"{{UNIQUE_KEY}}",
|
255
|
-
# "evidence_type":"{{EVIDENCE_TYPE}}", "content_type":"image/tiff" }' \
|
256
|
-
# 'https://connect.squareup.com/v2/disputes/{{DISPUTE_ID}}/evidence_file'
|
257
|
-
# ```
|
258
|
-
# For more information, see [Challenge a
|
259
|
-
# Dispute](https://developer.squareup.com/docs/docs/disputes-api/process-dis
|
260
|
-
# putes#challenge-a-dispute).
|
244
|
+
# and TIFF formats.
|
261
245
|
# @param [String] dispute_id Required parameter: ID of the dispute you want
|
262
246
|
# to upload evidence for.
|
263
247
|
# @param [CreateDisputeEvidenceFileRequest] request Optional parameter:
|
@@ -317,11 +301,7 @@ module Square
|
|
317
301
|
ApiResponse.new(_response, data: decoded, errors: _errors)
|
318
302
|
end
|
319
303
|
|
320
|
-
# Uploads text to use as evidence for a dispute challenge.
|
321
|
-
# information, see
|
322
|
-
# [Challenge a
|
323
|
-
# Dispute](https://developer.squareup.com/docs/docs/disputes-api/process-dis
|
324
|
-
# putes#challenge-a-dispute).
|
304
|
+
# Uploads text to use as evidence for a dispute challenge.
|
325
305
|
# @param [String] dispute_id Required parameter: The ID of the dispute you
|
326
306
|
# want to upload evidence for.
|
327
307
|
# @param [CreateDisputeEvidenceTextRequest] body Required parameter: An
|
@@ -369,10 +349,7 @@ module Square
|
|
369
349
|
# [CreateDisputeEvidenceText](https://developer.squareup.com/docs/reference/
|
370
350
|
# square/disputes-api/create-dispute-evidence-text) endpoints,
|
371
351
|
# and evidence automatically provided by Square, when
|
372
|
-
# available.
|
373
|
-
# [Challenge a
|
374
|
-
# Dispute](https://developer.squareup.com/docs/docs/disputes-api/process-dis
|
375
|
-
# putes#challenge-a-dispute).
|
352
|
+
# available.
|
376
353
|
# @param [String] dispute_id Required parameter: The ID of the dispute you
|
377
354
|
# want to submit evidence for.
|
378
355
|
# @return [SubmitEvidenceResponse Hash] response from the API call
|
@@ -6,8 +6,7 @@ module Square
|
|
6
6
|
end
|
7
7
|
|
8
8
|
# ListEmployees
|
9
|
-
# @param [String] location_id Optional parameter:
|
10
|
-
# to only those that are associated with the specified location.
|
9
|
+
# @param [String] location_id Optional parameter: Example:
|
11
10
|
# @param [EmployeeStatus] status Optional parameter: Specifies the
|
12
11
|
# EmployeeStatus to filter the employee by.
|
13
12
|
# @param [Integer] limit Optional parameter: The number of employees to be
|
@@ -19,6 +18,7 @@ module Square
|
|
19
18
|
status: nil,
|
20
19
|
limit: nil,
|
21
20
|
cursor: nil)
|
21
|
+
warn 'Endpoint list_employees in EmployeesApi is deprecated'
|
22
22
|
# Prepare query url.
|
23
23
|
_query_builder = config.get_base_uri
|
24
24
|
_query_builder << '/v2/employees'
|
@@ -55,6 +55,7 @@ module Square
|
|
55
55
|
# requested.
|
56
56
|
# @return [RetrieveEmployeeResponse Hash] response from the API call
|
57
57
|
def retrieve_employee(id:)
|
58
|
+
warn 'Endpoint retrieve_employee in EmployeesApi is deprecated'
|
58
59
|
# Prepare query url.
|
59
60
|
_query_builder = config.get_base_uri
|
60
61
|
_query_builder << '/v2/employees/{id}'
|
@@ -242,8 +242,9 @@ module Square
|
|
242
242
|
# [Location](#type-location)s.
|
243
243
|
# Results are paginated and sorted in descending order according to their
|
244
244
|
# `occurred_at` timestamp (newest first).
|
245
|
-
# There are no limits on how far back the caller can page. This endpoint
|
246
|
-
#
|
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
|
247
248
|
# sophisticated queries, use a batch endpoint.
|
248
249
|
# @param [String] catalog_object_id Required parameter: ID of the
|
249
250
|
# [CatalogObject](#type-catalogobject) to retrieve.
|
@@ -253,8 +254,8 @@ module Square
|
|
253
254
|
# @param [String] cursor Optional parameter: A pagination cursor returned by
|
254
255
|
# a previous call to this endpoint. Provide this to retrieve the next set of
|
255
256
|
# results for the original query. See the
|
256
|
-
# [Pagination](https://developer.squareup.com/docs/
|
257
|
-
#
|
257
|
+
# [Pagination](https://developer.squareup.com/docs/working-with-apis/paginat
|
258
|
+
# ion) guide for more information.
|
258
259
|
# @return [RetrieveInventoryChangesResponse Hash] response from the API call
|
259
260
|
def retrieve_inventory_changes(catalog_object_id:,
|
260
261
|
location_ids: nil,
|
@@ -0,0 +1,343 @@
|
|
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
|
+
# @param [String] location_id Required parameter: The ID of the location for
|
12
|
+
# which to list invoices.
|
13
|
+
# @param [String] cursor Optional parameter: A pagination cursor returned by
|
14
|
+
# a previous call to this endpoint. Provide this cursor to retrieve the
|
15
|
+
# next set of results for your original query. For more information, see
|
16
|
+
# [Pagination](https://developer.squareup.com/docs/docs/working-with-apis/pa
|
17
|
+
# gination).
|
18
|
+
# @param [Integer] limit Optional parameter: The maximum number of invoices
|
19
|
+
# to return (200 is the maximum `limit`). If not provided, the server uses
|
20
|
+
# a default limit of 100 invoices.
|
21
|
+
# @return [ListInvoicesResponse Hash] response from the API call
|
22
|
+
def list_invoices(location_id:,
|
23
|
+
cursor: nil,
|
24
|
+
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(_response, data: decoded, errors: _errors)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Creates a draft [invoice](#type-invoice)
|
56
|
+
# for an order created using the Orders API.
|
57
|
+
# A draft invoice remains in your account and no action is taken.
|
58
|
+
# You must publish the invoice before Square can process it (send it to the
|
59
|
+
# customer's email address or charge the customer’s card on file).
|
60
|
+
# @param [CreateInvoiceRequest] body Required parameter: An object
|
61
|
+
# containing the fields to POST for the request. See the corresponding
|
62
|
+
# object definition for field details.
|
63
|
+
# @return [CreateInvoiceResponse Hash] response from the API call
|
64
|
+
def create_invoice(body:)
|
65
|
+
# Prepare query url.
|
66
|
+
_query_builder = config.get_base_uri
|
67
|
+
_query_builder << '/v2/invoices'
|
68
|
+
_query_url = APIHelper.clean_url _query_builder
|
69
|
+
|
70
|
+
# Prepare headers.
|
71
|
+
_headers = {
|
72
|
+
'accept' => 'application/json',
|
73
|
+
'content-type' => 'application/json; charset=utf-8'
|
74
|
+
}
|
75
|
+
|
76
|
+
# Prepare and execute HttpRequest.
|
77
|
+
_request = config.http_client.post(
|
78
|
+
_query_url,
|
79
|
+
headers: _headers,
|
80
|
+
parameters: body.to_json
|
81
|
+
)
|
82
|
+
OAuth2.apply(config, _request)
|
83
|
+
_response = execute_request(_request)
|
84
|
+
|
85
|
+
# Return appropriate response type.
|
86
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
87
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
88
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Searches for invoices from a location specified in
|
92
|
+
# the filter. You can optionally specify customers in the filter for whom to
|
93
|
+
# retrieve invoices. In the current implementation, you can only specify one
|
94
|
+
# location and
|
95
|
+
# optionally one customer.
|
96
|
+
# The response is paginated. If truncated, the response includes a `cursor`
|
97
|
+
# that you use in a subsequent request to fetch the next set of invoices.
|
98
|
+
# @param [SearchInvoicesRequest] body Required parameter: An object
|
99
|
+
# containing the fields to POST for the request. See the corresponding
|
100
|
+
# object definition for field details.
|
101
|
+
# @return [SearchInvoicesResponse Hash] response from the API call
|
102
|
+
def search_invoices(body:)
|
103
|
+
# Prepare query url.
|
104
|
+
_query_builder = config.get_base_uri
|
105
|
+
_query_builder << '/v2/invoices/search'
|
106
|
+
_query_url = APIHelper.clean_url _query_builder
|
107
|
+
|
108
|
+
# Prepare headers.
|
109
|
+
_headers = {
|
110
|
+
'accept' => 'application/json',
|
111
|
+
'content-type' => 'application/json; charset=utf-8'
|
112
|
+
}
|
113
|
+
|
114
|
+
# Prepare and execute HttpRequest.
|
115
|
+
_request = config.http_client.post(
|
116
|
+
_query_url,
|
117
|
+
headers: _headers,
|
118
|
+
parameters: body.to_json
|
119
|
+
)
|
120
|
+
OAuth2.apply(config, _request)
|
121
|
+
_response = execute_request(_request)
|
122
|
+
|
123
|
+
# Return appropriate response type.
|
124
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
125
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
126
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
127
|
+
end
|
128
|
+
|
129
|
+
# Deletes the specified invoice. When an invoice is deleted, the
|
130
|
+
# associated Order status changes to CANCELED. You can only delete a draft
|
131
|
+
# invoice (you cannot delete an invoice scheduled for publication, or a
|
132
|
+
# published invoice).
|
133
|
+
# @param [String] invoice_id Required parameter: The ID of the invoice to
|
134
|
+
# delete.
|
135
|
+
# @param [Integer] version Optional parameter: The version of the
|
136
|
+
# [invoice](#type-invoice) to delete. If you do not know the version, you
|
137
|
+
# can call [GetInvoice](#endpoint-Invoices-GetInvoice) or
|
138
|
+
# [ListInvoices](#endpoint-Invoices-ListInvoices).
|
139
|
+
# @return [DeleteInvoiceResponse Hash] response from the API call
|
140
|
+
def delete_invoice(invoice_id:,
|
141
|
+
version: nil)
|
142
|
+
# Prepare query url.
|
143
|
+
_query_builder = config.get_base_uri
|
144
|
+
_query_builder << '/v2/invoices/{invoice_id}'
|
145
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
146
|
+
_query_builder,
|
147
|
+
'invoice_id' => invoice_id
|
148
|
+
)
|
149
|
+
_query_builder = APIHelper.append_url_with_query_parameters(
|
150
|
+
_query_builder,
|
151
|
+
'version' => version
|
152
|
+
)
|
153
|
+
_query_url = APIHelper.clean_url _query_builder
|
154
|
+
|
155
|
+
# Prepare headers.
|
156
|
+
_headers = {
|
157
|
+
'accept' => 'application/json'
|
158
|
+
}
|
159
|
+
|
160
|
+
# Prepare and execute HttpRequest.
|
161
|
+
_request = config.http_client.delete(
|
162
|
+
_query_url,
|
163
|
+
headers: _headers
|
164
|
+
)
|
165
|
+
OAuth2.apply(config, _request)
|
166
|
+
_response = execute_request(_request)
|
167
|
+
|
168
|
+
# Return appropriate response type.
|
169
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
170
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
171
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
172
|
+
end
|
173
|
+
|
174
|
+
# Retrieves an invoice by invoice ID.
|
175
|
+
# @param [String] invoice_id Required parameter: The id of the invoice to
|
176
|
+
# retrieve.
|
177
|
+
# @return [GetInvoiceResponse Hash] response from the API call
|
178
|
+
def get_invoice(invoice_id:)
|
179
|
+
# Prepare query url.
|
180
|
+
_query_builder = config.get_base_uri
|
181
|
+
_query_builder << '/v2/invoices/{invoice_id}'
|
182
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
183
|
+
_query_builder,
|
184
|
+
'invoice_id' => invoice_id
|
185
|
+
)
|
186
|
+
_query_url = APIHelper.clean_url _query_builder
|
187
|
+
|
188
|
+
# Prepare headers.
|
189
|
+
_headers = {
|
190
|
+
'accept' => 'application/json'
|
191
|
+
}
|
192
|
+
|
193
|
+
# Prepare and execute HttpRequest.
|
194
|
+
_request = config.http_client.get(
|
195
|
+
_query_url,
|
196
|
+
headers: _headers
|
197
|
+
)
|
198
|
+
OAuth2.apply(config, _request)
|
199
|
+
_response = execute_request(_request)
|
200
|
+
|
201
|
+
# Return appropriate response type.
|
202
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
203
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
204
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
205
|
+
end
|
206
|
+
|
207
|
+
# Updates an invoice by modifying field values, clearing field values, or
|
208
|
+
# both
|
209
|
+
# as specified in the request.
|
210
|
+
# There are no restrictions to updating an invoice in a draft state.
|
211
|
+
# However, there are guidelines for updating a published invoice.
|
212
|
+
# @param [String] invoice_id Required parameter: The id of the invoice to
|
213
|
+
# update.
|
214
|
+
# @param [UpdateInvoiceRequest] body Required parameter: An object
|
215
|
+
# containing the fields to POST for the request. See the corresponding
|
216
|
+
# object definition for field details.
|
217
|
+
# @return [UpdateInvoiceResponse Hash] response from the API call
|
218
|
+
def update_invoice(invoice_id:,
|
219
|
+
body:)
|
220
|
+
# Prepare query url.
|
221
|
+
_query_builder = config.get_base_uri
|
222
|
+
_query_builder << '/v2/invoices/{invoice_id}'
|
223
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
224
|
+
_query_builder,
|
225
|
+
'invoice_id' => invoice_id
|
226
|
+
)
|
227
|
+
_query_url = APIHelper.clean_url _query_builder
|
228
|
+
|
229
|
+
# Prepare headers.
|
230
|
+
_headers = {
|
231
|
+
'accept' => 'application/json',
|
232
|
+
'content-type' => 'application/json; charset=utf-8'
|
233
|
+
}
|
234
|
+
|
235
|
+
# Prepare and execute HttpRequest.
|
236
|
+
_request = config.http_client.put(
|
237
|
+
_query_url,
|
238
|
+
headers: _headers,
|
239
|
+
parameters: body.to_json
|
240
|
+
)
|
241
|
+
OAuth2.apply(config, _request)
|
242
|
+
_response = execute_request(_request)
|
243
|
+
|
244
|
+
# Return appropriate response type.
|
245
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
246
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
247
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
248
|
+
end
|
249
|
+
|
250
|
+
# Cancels an invoice. The seller cannot collect payments for
|
251
|
+
# the canceled invoice.
|
252
|
+
# You cannot cancel an invoice in a terminal state: `PAID`, `REFUNDED`,
|
253
|
+
# `CANCELED`, or `FAILED`.
|
254
|
+
# @param [String] invoice_id Required parameter: The ID of the
|
255
|
+
# [invoice](#type-invoice) to cancel.
|
256
|
+
# @param [CancelInvoiceRequest] body Required parameter: An object
|
257
|
+
# containing the fields to POST for the request. See the corresponding
|
258
|
+
# object definition for field details.
|
259
|
+
# @return [CancelInvoiceResponse Hash] response from the API call
|
260
|
+
def cancel_invoice(invoice_id:,
|
261
|
+
body:)
|
262
|
+
# Prepare query url.
|
263
|
+
_query_builder = config.get_base_uri
|
264
|
+
_query_builder << '/v2/invoices/{invoice_id}/cancel'
|
265
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
266
|
+
_query_builder,
|
267
|
+
'invoice_id' => invoice_id
|
268
|
+
)
|
269
|
+
_query_url = APIHelper.clean_url _query_builder
|
270
|
+
|
271
|
+
# Prepare headers.
|
272
|
+
_headers = {
|
273
|
+
'accept' => 'application/json',
|
274
|
+
'content-type' => 'application/json; charset=utf-8'
|
275
|
+
}
|
276
|
+
|
277
|
+
# Prepare and execute HttpRequest.
|
278
|
+
_request = config.http_client.post(
|
279
|
+
_query_url,
|
280
|
+
headers: _headers,
|
281
|
+
parameters: body.to_json
|
282
|
+
)
|
283
|
+
OAuth2.apply(config, _request)
|
284
|
+
_response = execute_request(_request)
|
285
|
+
|
286
|
+
# Return appropriate response type.
|
287
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
288
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
289
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
290
|
+
end
|
291
|
+
|
292
|
+
# Publishes the specified draft invoice.
|
293
|
+
# After an invoice is published, Square
|
294
|
+
# follows up based on the invoice configuration. For example, Square
|
295
|
+
# sends the invoice to the customer's email address, charges the customer's
|
296
|
+
# card on file, or does
|
297
|
+
# nothing. Square also makes the invoice available on a Square-hosted
|
298
|
+
# invoice page.
|
299
|
+
# The invoice `status` also changes from `DRAFT` to a status
|
300
|
+
# based on the invoice configuration. For example, the status changes to
|
301
|
+
# `UNPAID` if
|
302
|
+
# Square emails the invoice or `PARTIALLY_PAID` if Square charge a card on
|
303
|
+
# file for a portion of the
|
304
|
+
# invoice amount).
|
305
|
+
# @param [String] invoice_id Required parameter: The id of the invoice to
|
306
|
+
# publish.
|
307
|
+
# @param [PublishInvoiceRequest] body Required parameter: An object
|
308
|
+
# containing the fields to POST for the request. See the corresponding
|
309
|
+
# object definition for field details.
|
310
|
+
# @return [PublishInvoiceResponse Hash] response from the API call
|
311
|
+
def publish_invoice(invoice_id:,
|
312
|
+
body:)
|
313
|
+
# Prepare query url.
|
314
|
+
_query_builder = config.get_base_uri
|
315
|
+
_query_builder << '/v2/invoices/{invoice_id}/publish'
|
316
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
317
|
+
_query_builder,
|
318
|
+
'invoice_id' => invoice_id
|
319
|
+
)
|
320
|
+
_query_url = APIHelper.clean_url _query_builder
|
321
|
+
|
322
|
+
# Prepare headers.
|
323
|
+
_headers = {
|
324
|
+
'accept' => 'application/json',
|
325
|
+
'content-type' => 'application/json; charset=utf-8'
|
326
|
+
}
|
327
|
+
|
328
|
+
# Prepare and execute HttpRequest.
|
329
|
+
_request = config.http_client.post(
|
330
|
+
_query_url,
|
331
|
+
headers: _headers,
|
332
|
+
parameters: body.to_json
|
333
|
+
)
|
334
|
+
OAuth2.apply(config, _request)
|
335
|
+
_response = execute_request(_request)
|
336
|
+
|
337
|
+
# Return appropriate response type.
|
338
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
339
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
340
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
341
|
+
end
|
342
|
+
end
|
343
|
+
end
|