square.rb 5.2.1.20200422 → 6.2.0.20200812
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +319 -285
- data/lib/square.rb +4 -0
- data/lib/square/api/base_api.rb +2 -2
- data/lib/square/api/catalog_api.rb +76 -57
- data/lib/square/api/customers_api.rb +16 -3
- data/lib/square/api/disputes_api.rb +1 -11
- data/lib/square/api/inventory_api.rb +2 -2
- data/lib/square/api/invoices_api.rb +358 -0
- data/lib/square/api/locations_api.rb +7 -2
- data/lib/square/api/loyalty_api.rb +543 -0
- data/lib/square/api/merchants_api.rb +2 -1
- data/lib/square/api/orders_api.rb +32 -0
- data/lib/square/api/payments_api.rb +3 -9
- data/lib/square/api/refunds_api.rb +3 -2
- data/lib/square/api/subscriptions_api.rb +262 -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 -4
- data/lib/square/configuration.rb +12 -4
- metadata +7 -3
data/lib/square.rb
CHANGED
@@ -46,13 +46,17 @@ 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
52
|
require_relative 'square/api/reporting_api.rb'
|
52
53
|
require_relative 'square/api/checkout_api.rb'
|
53
54
|
require_relative 'square/api/orders_api.rb'
|
54
55
|
require_relative 'square/api/transactions_api.rb'
|
56
|
+
require_relative 'square/api/loyalty_api.rb'
|
55
57
|
require_relative 'square/api/merchants_api.rb'
|
56
58
|
require_relative 'square/api/payments_api.rb'
|
57
59
|
require_relative 'square/api/refunds_api.rb'
|
60
|
+
require_relative 'square/api/subscriptions_api.rb'
|
61
|
+
require_relative 'square/api/team_api.rb'
|
58
62
|
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.2.0.20200812',
|
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.
|
@@ -5,7 +5,13 @@ module Square
|
|
5
5
|
super(config, http_call_back: http_call_back)
|
6
6
|
end
|
7
7
|
|
8
|
-
# Lists a
|
8
|
+
# Lists customer profiles associated with a Square account.
|
9
|
+
# Under normal operating conditions, newly created or updated customer
|
10
|
+
# profiles become available
|
11
|
+
# for the listing operation in well under 30 seconds. Occasionally,
|
12
|
+
# propagation of the new or updated
|
13
|
+
# profiles can take closer to one minute or longer, espeically during
|
14
|
+
# network incidents and outages.
|
9
15
|
# @param [String] cursor Optional parameter: A pagination cursor returned by
|
10
16
|
# a previous call to this endpoint. Provide this to retrieve the next set of
|
11
17
|
# results for your original query. See the [Pagination
|
@@ -91,10 +97,17 @@ module Square
|
|
91
97
|
ApiResponse.new(_response, data: decoded, errors: _errors)
|
92
98
|
end
|
93
99
|
|
94
|
-
# Searches the customer profiles associated with a Square account
|
95
|
-
#
|
100
|
+
# Searches the customer profiles associated with a Square account using
|
101
|
+
# one or more supported query filters.
|
102
|
+
# Calling `SearchCustomers` without any explicit query filter returns all
|
96
103
|
# customer profiles ordered alphabetically based on `given_name` and
|
97
104
|
# `family_name`.
|
105
|
+
# Under normal operating conditions, newly created or updated customer
|
106
|
+
# profiles become available
|
107
|
+
# for the search operation in well under 30 seconds. Occasionally,
|
108
|
+
# propagation of the new or updated
|
109
|
+
# profiles can take closer to one minute or longer, espeically during
|
110
|
+
# network incidents and outages.
|
98
111
|
# @param [SearchCustomersRequest] body Required parameter: An object
|
99
112
|
# containing the fields to POST for the request. See the corresponding
|
100
113
|
# object definition for field details.
|
@@ -244,17 +244,7 @@ module Square
|
|
244
244
|
# Uploads a file to use as evidence in a dispute challenge. The endpoint
|
245
245
|
# accepts
|
246
246
|
# 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
|
-
# ```
|
247
|
+
# and TIFF formats.
|
258
248
|
# For more information, see [Challenge a
|
259
249
|
# Dispute](https://developer.squareup.com/docs/docs/disputes-api/process-dis
|
260
250
|
# putes#challenge-a-dispute).
|
@@ -253,8 +253,8 @@ module Square
|
|
253
253
|
# @param [String] cursor Optional parameter: A pagination cursor returned by
|
254
254
|
# a previous call to this endpoint. Provide this to retrieve the next set of
|
255
255
|
# results for the original query. See the
|
256
|
-
# [Pagination](https://developer.squareup.com/docs/
|
257
|
-
#
|
256
|
+
# [Pagination](https://developer.squareup.com/docs/working-with-apis/paginat
|
257
|
+
# ion) guide for more information.
|
258
258
|
# @return [RetrieveInventoryChangesResponse Hash] response from the API call
|
259
259
|
def retrieve_inventory_changes(catalog_object_id:,
|
260
260
|
location_ids: nil,
|
@@ -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
|