square.rb 8.1.0.20210121 → 18.1.0.20220316
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/LICENSE +1 -1
- data/README.md +59 -213
- data/lib/square/api/apple_pay_api.rb +9 -8
- data/lib/square/api/bank_accounts_api.rb +5 -5
- data/lib/square/api/base_api.rb +20 -9
- data/lib/square/api/bookings_api.rb +95 -12
- data/lib/square/api/cards_api.rb +170 -0
- data/lib/square/api/cash_drawers_api.rb +2 -2
- data/lib/square/api/catalog_api.rb +140 -66
- data/lib/square/api/checkout_api.rb +3 -3
- data/lib/square/api/customer_groups_api.rb +17 -8
- data/lib/square/api/customer_segments_api.rb +15 -6
- data/lib/square/api/customers_api.rb +61 -31
- data/lib/square/api/devices_api.rb +3 -2
- data/lib/square/api/disputes_api.rb +101 -92
- data/lib/square/api/gift_card_activities_api.rb +133 -0
- data/lib/square/api/gift_cards_api.rb +297 -0
- data/lib/square/api/inventory_api.rb +263 -24
- data/lib/square/api/invoices_api.rb +19 -19
- data/lib/square/api/labor_api.rb +70 -68
- data/lib/square/api/locations_api.rb +22 -14
- data/lib/square/api/loyalty_api.rb +86 -32
- data/lib/square/api/merchants_api.rb +11 -9
- data/lib/square/api/mobile_authorization_api.rb +4 -4
- data/lib/square/api/o_auth_api.rb +31 -25
- data/lib/square/api/orders_api.rb +78 -39
- data/lib/square/api/payments_api.rb +71 -23
- data/lib/square/api/refunds_api.rb +18 -7
- data/lib/square/api/sites_api.rb +43 -0
- data/lib/square/api/snippets_api.rb +146 -0
- data/lib/square/api/subscriptions_api.rb +190 -12
- data/lib/square/api/team_api.rb +46 -46
- data/lib/square/api/terminal_api.rb +19 -18
- data/lib/square/api/transactions_api.rb +15 -191
- data/lib/square/api/v1_transactions_api.rb +13 -85
- data/lib/square/api/vendors_api.rb +257 -0
- data/lib/square/api_helper.rb +45 -57
- data/lib/square/client.rb +54 -18
- data/lib/square/configuration.rb +59 -20
- data/lib/square/http/api_response.rb +1 -1
- data/lib/square/http/faraday_client.rb +24 -4
- data/lib/square/utilities/date_time_helper.rb +151 -0
- data/lib/square/utilities/file_wrapper.rb +1 -2
- data/lib/square.rb +49 -44
- data/test/api/test_locations_api.rb +2 -5
- data/test/test_helper.rb +1 -1
- metadata +11 -6
- data/lib/square/api/v1_employees_api.rb +0 -749
- data/lib/square/api/v1_items_api.rb +0 -1766
@@ -5,14 +5,14 @@ module Square
|
|
5
5
|
super(config, http_call_back: http_call_back)
|
6
6
|
end
|
7
7
|
|
8
|
-
# Creates a new [
|
8
|
+
# Creates a new [order]($m/Order) that can include information about
|
9
9
|
# products for
|
10
10
|
# purchase and settings to apply to the purchase.
|
11
|
-
# To pay for a created order,
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# You can modify open orders using the
|
15
|
-
#
|
11
|
+
# To pay for a created order, see
|
12
|
+
# [Pay for
|
13
|
+
# Orders](https://developer.squareup.com/docs/orders-api/pay-for-orders).
|
14
|
+
# You can modify open orders using the [UpdateOrder]($e/Orders/UpdateOrder)
|
15
|
+
# endpoint.
|
16
16
|
# @param [CreateOrderRequest] body Required parameter: An object containing
|
17
17
|
# the fields to POST for the request. See the corresponding object
|
18
18
|
# definition for field details.
|
@@ -26,7 +26,7 @@ module Square
|
|
26
26
|
# Prepare headers.
|
27
27
|
_headers = {
|
28
28
|
'accept' => 'application/json',
|
29
|
-
'
|
29
|
+
'Content-Type' => 'application/json'
|
30
30
|
}
|
31
31
|
|
32
32
|
# Prepare and execute HttpRequest.
|
@@ -46,8 +46,8 @@ module Square
|
|
46
46
|
)
|
47
47
|
end
|
48
48
|
|
49
|
-
# Retrieves a set of [
|
50
|
-
# If a given
|
49
|
+
# Retrieves a set of [orders]($m/Order) by their IDs.
|
50
|
+
# If a given order ID does not exist, the ID is ignored instead of
|
51
51
|
# generating an error.
|
52
52
|
# @param [BatchRetrieveOrdersRequest] body Required parameter: An object
|
53
53
|
# containing the fields to POST for the request. See the corresponding
|
@@ -62,7 +62,7 @@ module Square
|
|
62
62
|
# Prepare headers.
|
63
63
|
_headers = {
|
64
64
|
'accept' => 'application/json',
|
65
|
-
'
|
65
|
+
'Content-Type' => 'application/json'
|
66
66
|
}
|
67
67
|
|
68
68
|
# Prepare and execute HttpRequest.
|
@@ -82,7 +82,7 @@ module Square
|
|
82
82
|
)
|
83
83
|
end
|
84
84
|
|
85
|
-
#
|
85
|
+
# Enables applications to preview order pricing without creating an order.
|
86
86
|
# @param [CalculateOrderRequest] body Required parameter: An object
|
87
87
|
# containing the fields to POST for the request. See the corresponding
|
88
88
|
# object definition for field details.
|
@@ -96,7 +96,44 @@ module Square
|
|
96
96
|
# Prepare headers.
|
97
97
|
_headers = {
|
98
98
|
'accept' => 'application/json',
|
99
|
-
'
|
99
|
+
'Content-Type' => 'application/json'
|
100
|
+
}
|
101
|
+
|
102
|
+
# Prepare and execute HttpRequest.
|
103
|
+
_request = config.http_client.post(
|
104
|
+
_query_url,
|
105
|
+
headers: _headers,
|
106
|
+
parameters: body.to_json
|
107
|
+
)
|
108
|
+
OAuth2.apply(config, _request)
|
109
|
+
_response = execute_request(_request)
|
110
|
+
|
111
|
+
# Return appropriate response type.
|
112
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
113
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
114
|
+
ApiResponse.new(
|
115
|
+
_response, data: decoded, errors: _errors
|
116
|
+
)
|
117
|
+
end
|
118
|
+
|
119
|
+
# Creates a new order, in the `DRAFT` state, by duplicating an existing
|
120
|
+
# order. The newly created order has
|
121
|
+
# only the core fields (such as line items, taxes, and discounts) copied
|
122
|
+
# from the original order.
|
123
|
+
# @param [CloneOrderRequest] body Required parameter: An object containing
|
124
|
+
# the fields to POST for the request. See the corresponding object
|
125
|
+
# definition for field details.
|
126
|
+
# @return [CloneOrderResponse Hash] response from the API call
|
127
|
+
def clone_order(body:)
|
128
|
+
# Prepare query url.
|
129
|
+
_query_builder = config.get_base_uri
|
130
|
+
_query_builder << '/v2/orders/clone'
|
131
|
+
_query_url = APIHelper.clean_url _query_builder
|
132
|
+
|
133
|
+
# Prepare headers.
|
134
|
+
_headers = {
|
135
|
+
'accept' => 'application/json',
|
136
|
+
'Content-Type' => 'application/json'
|
100
137
|
}
|
101
138
|
|
102
139
|
# Prepare and execute HttpRequest.
|
@@ -118,17 +155,18 @@ module Square
|
|
118
155
|
|
119
156
|
# Search all orders for one or more locations. Orders include all sales,
|
120
157
|
# returns, and exchanges regardless of how or when they entered the Square
|
121
|
-
#
|
122
|
-
# SearchOrders requests need to specify which locations to search and
|
123
|
-
# a
|
124
|
-
# [
|
125
|
-
# how to sort or filter the results. Your SearchOrdersQuery can:
|
158
|
+
# ecosystem (such as Point of Sale, Invoices, and Connect APIs).
|
159
|
+
# `SearchOrders` requests need to specify which locations to search and
|
160
|
+
# define a
|
161
|
+
# [SearchOrdersQuery]($m/SearchOrdersQuery) object that controls
|
162
|
+
# how to sort or filter the results. Your `SearchOrdersQuery` can:
|
126
163
|
# Set filter criteria.
|
127
|
-
# Set sort order.
|
128
|
-
# Determine whether to return results as complete Order objects
|
129
|
-
# [OrderEntry](
|
164
|
+
# Set the sort order.
|
165
|
+
# Determine whether to return results as complete `Order` objects or as
|
166
|
+
# [OrderEntry]($m/OrderEntry) objects.
|
130
167
|
# Note that details for orders processed with Square Point of Sale while in
|
131
|
-
# offline mode
|
168
|
+
# offline mode might not be transmitted to Square for up to 72 hours.
|
169
|
+
# Offline
|
132
170
|
# orders have a `created_at` value that reflects the time the order was
|
133
171
|
# created,
|
134
172
|
# not the time it was subsequently transmitted to Square.
|
@@ -145,7 +183,7 @@ module Square
|
|
145
183
|
# Prepare headers.
|
146
184
|
_headers = {
|
147
185
|
'accept' => 'application/json',
|
148
|
-
'
|
186
|
+
'Content-Type' => 'application/json'
|
149
187
|
}
|
150
188
|
|
151
189
|
# Prepare and execute HttpRequest.
|
@@ -165,7 +203,7 @@ module Square
|
|
165
203
|
)
|
166
204
|
end
|
167
205
|
|
168
|
-
# Retrieves an [Order](
|
206
|
+
# Retrieves an [Order]($m/Order) by ID.
|
169
207
|
# @param [String] order_id Required parameter: The ID of the order to
|
170
208
|
# retrieve.
|
171
209
|
# @return [RetrieveOrderResponse Hash] response from the API call
|
@@ -200,23 +238,24 @@ module Square
|
|
200
238
|
)
|
201
239
|
end
|
202
240
|
|
203
|
-
# Updates an open [
|
241
|
+
# Updates an open [order]($m/Order) by adding, replacing, or deleting
|
204
242
|
# fields. Orders with a `COMPLETED` or `CANCELED` state cannot be updated.
|
205
|
-
# An UpdateOrder request requires the following:
|
243
|
+
# An `UpdateOrder` request requires the following:
|
206
244
|
# - The `order_id` in the endpoint path, identifying the order to update.
|
207
245
|
# - The latest `version` of the order to update.
|
208
246
|
# - The [sparse
|
209
247
|
# order](https://developer.squareup.com/docs/orders-api/manage-orders#sparse
|
210
248
|
# -order-objects)
|
211
|
-
# containing only the fields to update and the version the update
|
212
|
-
#
|
249
|
+
# containing only the fields to update and the version to which the update
|
250
|
+
# is
|
251
|
+
# being applied.
|
213
252
|
# - If deleting fields, the [dot notation
|
214
253
|
# paths](https://developer.squareup.com/docs/orders-api/manage-orders#on-dot
|
215
254
|
# -notation)
|
216
|
-
# identifying fields to clear.
|
217
|
-
# To pay for an order,
|
218
|
-
#
|
219
|
-
#
|
255
|
+
# identifying the fields to clear.
|
256
|
+
# To pay for an order, see
|
257
|
+
# [Pay for
|
258
|
+
# Orders](https://developer.squareup.com/docs/orders-api/pay-for-orders).
|
220
259
|
# @param [String] order_id Required parameter: The ID of the order to
|
221
260
|
# update.
|
222
261
|
# @param [UpdateOrderRequest] body Required parameter: An object containing
|
@@ -237,7 +276,7 @@ module Square
|
|
237
276
|
# Prepare headers.
|
238
277
|
_headers = {
|
239
278
|
'accept' => 'application/json',
|
240
|
-
'
|
279
|
+
'Content-Type' => 'application/json'
|
241
280
|
}
|
242
281
|
|
243
282
|
# Prepare and execute HttpRequest.
|
@@ -257,24 +296,24 @@ module Square
|
|
257
296
|
)
|
258
297
|
end
|
259
298
|
|
260
|
-
# Pay for an [order](
|
261
|
-
# [payments](
|
299
|
+
# Pay for an [order]($m/Order) using one or more approved
|
300
|
+
# [payments]($m/Payment)
|
262
301
|
# or settle an order with a total of `0`.
|
263
302
|
# The total of the `payment_ids` listed in the request must be equal to the
|
264
303
|
# order
|
265
304
|
# total. Orders with a total amount of `0` can be marked as paid by
|
266
305
|
# specifying an empty
|
267
306
|
# array of `payment_ids` in the request.
|
268
|
-
# To be used with PayOrder
|
307
|
+
# To be used with `PayOrder`, a payment must:
|
269
308
|
# - Reference the order by specifying the `order_id` when [creating the
|
270
|
-
# payment](
|
309
|
+
# payment]($e/Payments/CreatePayment).
|
271
310
|
# Any approved payments that reference the same `order_id` not specified in
|
272
311
|
# the
|
273
|
-
# `payment_ids`
|
312
|
+
# `payment_ids` is canceled.
|
274
313
|
# - Be approved with [delayed
|
275
314
|
# capture](https://developer.squareup.com/docs/payments-api/take-payments#de
|
276
315
|
# layed-capture).
|
277
|
-
# Using a delayed capture payment with PayOrder
|
316
|
+
# Using a delayed capture payment with `PayOrder` completes the approved
|
278
317
|
# payment.
|
279
318
|
# @param [String] order_id Required parameter: The ID of the order being
|
280
319
|
# paid.
|
@@ -296,7 +335,7 @@ module Square
|
|
296
335
|
# Prepare headers.
|
297
336
|
_headers = {
|
298
337
|
'accept' => 'application/json',
|
299
|
-
'
|
338
|
+
'Content-Type' => 'application/json'
|
300
339
|
}
|
301
340
|
|
302
341
|
# Prepare and execute HttpRequest.
|
@@ -6,6 +6,9 @@ module Square
|
|
6
6
|
end
|
7
7
|
|
8
8
|
# Retrieves a list of payments taken by the account making the request.
|
9
|
+
# Results are eventually consistent, and new payments or changes to payments
|
10
|
+
# might take several
|
11
|
+
# seconds to appear.
|
9
12
|
# The maximum results per page is 100.
|
10
13
|
# @param [String] begin_time Optional parameter: The timestamp for the
|
11
14
|
# beginning of the reporting period, in RFC 3339 format. Inclusive. Default:
|
@@ -83,16 +86,14 @@ module Square
|
|
83
86
|
)
|
84
87
|
end
|
85
88
|
|
86
|
-
#
|
87
|
-
#
|
88
|
-
#
|
89
|
-
#
|
90
|
-
#
|
91
|
-
#
|
92
|
-
#
|
93
|
-
#
|
94
|
-
# The `PAYMENTS_WRITE_ADDITIONAL_RECIPIENTS` OAuth permission is required
|
95
|
-
# to enable application fees.
|
89
|
+
# Creates a payment using the provided source. You can use this endpoint
|
90
|
+
# to charge a card (credit/debit card or
|
91
|
+
# Square gift card) or record a payment that the seller received outside of
|
92
|
+
# Square
|
93
|
+
# (cash payment from a buyer or a payment that an external entity
|
94
|
+
# processed on behalf of the seller).
|
95
|
+
# The endpoint creates a
|
96
|
+
# `Payment` object and returns it in the response.
|
96
97
|
# @param [CreatePaymentRequest] body Required parameter: An object
|
97
98
|
# containing the fields to POST for the request. See the corresponding
|
98
99
|
# object definition for field details.
|
@@ -106,7 +107,7 @@ module Square
|
|
106
107
|
# Prepare headers.
|
107
108
|
_headers = {
|
108
109
|
'accept' => 'application/json',
|
109
|
-
'
|
110
|
+
'Content-Type' => 'application/json'
|
110
111
|
}
|
111
112
|
|
112
113
|
# Prepare and execute HttpRequest.
|
@@ -154,7 +155,7 @@ module Square
|
|
154
155
|
# Prepare headers.
|
155
156
|
_headers = {
|
156
157
|
'accept' => 'application/json',
|
157
|
-
'
|
158
|
+
'Content-Type' => 'application/json'
|
158
159
|
}
|
159
160
|
|
160
161
|
# Prepare and execute HttpRequest.
|
@@ -209,11 +210,53 @@ module Square
|
|
209
210
|
)
|
210
211
|
end
|
211
212
|
|
212
|
-
#
|
213
|
-
#
|
214
|
-
#
|
215
|
-
#
|
216
|
-
#
|
213
|
+
# Updates a payment with the APPROVED status.
|
214
|
+
# You can update the `amount_money` and `tip_money` using this endpoint.
|
215
|
+
# @param [String] payment_id Required parameter: The ID of the payment to
|
216
|
+
# update.
|
217
|
+
# @param [UpdatePaymentRequest] body Required parameter: An object
|
218
|
+
# containing the fields to POST for the request. See the corresponding
|
219
|
+
# object definition for field details.
|
220
|
+
# @return [UpdatePaymentResponse Hash] response from the API call
|
221
|
+
def update_payment(payment_id:,
|
222
|
+
body:)
|
223
|
+
# Prepare query url.
|
224
|
+
_query_builder = config.get_base_uri
|
225
|
+
_query_builder << '/v2/payments/{payment_id}'
|
226
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
227
|
+
_query_builder,
|
228
|
+
'payment_id' => { 'value' => payment_id, 'encode' => true }
|
229
|
+
)
|
230
|
+
_query_url = APIHelper.clean_url _query_builder
|
231
|
+
|
232
|
+
# Prepare headers.
|
233
|
+
_headers = {
|
234
|
+
'accept' => 'application/json',
|
235
|
+
'Content-Type' => 'application/json'
|
236
|
+
}
|
237
|
+
|
238
|
+
# Prepare and execute HttpRequest.
|
239
|
+
_request = config.http_client.put(
|
240
|
+
_query_url,
|
241
|
+
headers: _headers,
|
242
|
+
parameters: body.to_json
|
243
|
+
)
|
244
|
+
OAuth2.apply(config, _request)
|
245
|
+
_response = execute_request(_request)
|
246
|
+
|
247
|
+
# Return appropriate response type.
|
248
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
249
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
250
|
+
ApiResponse.new(
|
251
|
+
_response, data: decoded, errors: _errors
|
252
|
+
)
|
253
|
+
end
|
254
|
+
|
255
|
+
# Cancels (voids) a payment. You can use this endpoint to cancel a payment
|
256
|
+
# with
|
257
|
+
# the APPROVED `status`.
|
258
|
+
# @param [String] payment_id Required parameter: The ID of the payment to
|
259
|
+
# cancel.
|
217
260
|
# @return [CancelPaymentResponse Hash] response from the API call
|
218
261
|
def cancel_payment(payment_id:)
|
219
262
|
# Prepare query url.
|
@@ -249,13 +292,16 @@ module Square
|
|
249
292
|
# Completes (captures) a payment.
|
250
293
|
# By default, payments are set to complete immediately after they are
|
251
294
|
# created.
|
252
|
-
#
|
253
|
-
#
|
254
|
-
# the payment using this endpoint.
|
295
|
+
# You can use this endpoint to complete a payment with the APPROVED
|
296
|
+
# `status`.
|
255
297
|
# @param [String] payment_id Required parameter: The unique ID identifying
|
256
298
|
# the payment to be completed.
|
299
|
+
# @param [CompletePaymentRequest] body Required parameter: An object
|
300
|
+
# containing the fields to POST for the request. See the corresponding
|
301
|
+
# object definition for field details.
|
257
302
|
# @return [CompletePaymentResponse Hash] response from the API call
|
258
|
-
def complete_payment(payment_id
|
303
|
+
def complete_payment(payment_id:,
|
304
|
+
body:)
|
259
305
|
# Prepare query url.
|
260
306
|
_query_builder = config.get_base_uri
|
261
307
|
_query_builder << '/v2/payments/{payment_id}/complete'
|
@@ -267,13 +313,15 @@ module Square
|
|
267
313
|
|
268
314
|
# Prepare headers.
|
269
315
|
_headers = {
|
270
|
-
'accept' => 'application/json'
|
316
|
+
'accept' => 'application/json',
|
317
|
+
'Content-Type' => 'application/json'
|
271
318
|
}
|
272
319
|
|
273
320
|
# Prepare and execute HttpRequest.
|
274
321
|
_request = config.http_client.post(
|
275
322
|
_query_url,
|
276
|
-
headers: _headers
|
323
|
+
headers: _headers,
|
324
|
+
parameters: body.to_json
|
277
325
|
)
|
278
326
|
OAuth2.apply(config, _request)
|
279
327
|
_response = execute_request(_request)
|
@@ -6,6 +6,9 @@ module Square
|
|
6
6
|
end
|
7
7
|
|
8
8
|
# Retrieves a list of refunds for the account making the request.
|
9
|
+
# Results are eventually consistent, and new refunds or changes to refunds
|
10
|
+
# might take several
|
11
|
+
# seconds to appear.
|
9
12
|
# The maximum results per page is 100.
|
10
13
|
# @param [String] begin_time Optional parameter: The timestamp for the
|
11
14
|
# beginning of the requested reporting period, in RFC 3339 format. Default:
|
@@ -26,12 +29,15 @@ module Square
|
|
26
29
|
# associated with the seller.
|
27
30
|
# @param [String] status Optional parameter: If provided, only refunds with
|
28
31
|
# the given status are returned. For a list of refund status values, see
|
29
|
-
# [PaymentRefund](
|
32
|
+
# [PaymentRefund]($m/PaymentRefund). Default: If omitted, refunds are
|
30
33
|
# returned regardless of their status.
|
31
|
-
# @param [String] source_type Optional parameter: If provided, only
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
34
|
+
# @param [String] source_type Optional parameter: If provided, only returns
|
35
|
+
# refunds whose payments have the indicated source type. Current values
|
36
|
+
# include `CARD`, `BANK_ACCOUNT`, `WALLET`, `CASH`, and `EXTERNAL`. For
|
37
|
+
# information about these payment source types, see [Take
|
38
|
+
# Payments](https://developer.squareup.com/docs/payments-api/take-payments).
|
39
|
+
# Default: If omitted, refunds are returned regardless of the source
|
40
|
+
# type.
|
35
41
|
# @param [Integer] limit Optional parameter: The maximum number of results
|
36
42
|
# to be returned in a single page. It is possible to receive fewer results
|
37
43
|
# than the specified limit on a given page. If the supplied value is
|
@@ -83,7 +89,12 @@ module Square
|
|
83
89
|
end
|
84
90
|
|
85
91
|
# Refunds a payment. You can refund the entire payment amount or a
|
86
|
-
# portion of it.
|
92
|
+
# portion of it. You can use this endpoint to refund a card payment or
|
93
|
+
# record a
|
94
|
+
# refund of a cash or external payment. For more information, see
|
95
|
+
# [Refund
|
96
|
+
# Payment](https://developer.squareup.com/docs/payments-api/refund-payments)
|
97
|
+
# .
|
87
98
|
# @param [RefundPaymentRequest] body Required parameter: An object
|
88
99
|
# containing the fields to POST for the request. See the corresponding
|
89
100
|
# object definition for field details.
|
@@ -97,7 +108,7 @@ module Square
|
|
97
108
|
# Prepare headers.
|
98
109
|
_headers = {
|
99
110
|
'accept' => 'application/json',
|
100
|
-
'
|
111
|
+
'Content-Type' => 'application/json'
|
101
112
|
}
|
102
113
|
|
103
114
|
# Prepare and execute HttpRequest.
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Square
|
2
|
+
# SitesApi
|
3
|
+
class SitesApi < BaseApi
|
4
|
+
def initialize(config, http_call_back: nil)
|
5
|
+
super(config, http_call_back: http_call_back)
|
6
|
+
end
|
7
|
+
|
8
|
+
# Lists the Square Online sites that belong to a seller. Sites are listed in
|
9
|
+
# descending order by the `created_at` date.
|
10
|
+
# __Note:__ Square Online APIs are publicly available as part of an early
|
11
|
+
# access program. For more information, see [Early access program for Square
|
12
|
+
# Online
|
13
|
+
# APIs](https://developer.squareup.com/docs/online-api#early-access-program-
|
14
|
+
# for-square-online-apis).
|
15
|
+
# @return [ListSitesResponse Hash] response from the API call
|
16
|
+
def list_sites
|
17
|
+
# Prepare query url.
|
18
|
+
_query_builder = config.get_base_uri
|
19
|
+
_query_builder << '/v2/sites'
|
20
|
+
_query_url = APIHelper.clean_url _query_builder
|
21
|
+
|
22
|
+
# Prepare headers.
|
23
|
+
_headers = {
|
24
|
+
'accept' => 'application/json'
|
25
|
+
}
|
26
|
+
|
27
|
+
# Prepare and execute HttpRequest.
|
28
|
+
_request = config.http_client.get(
|
29
|
+
_query_url,
|
30
|
+
headers: _headers
|
31
|
+
)
|
32
|
+
OAuth2.apply(config, _request)
|
33
|
+
_response = execute_request(_request)
|
34
|
+
|
35
|
+
# Return appropriate response type.
|
36
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
37
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
38
|
+
ApiResponse.new(
|
39
|
+
_response, data: decoded, errors: _errors
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
module Square
|
2
|
+
# SnippetsApi
|
3
|
+
class SnippetsApi < BaseApi
|
4
|
+
def initialize(config, http_call_back: nil)
|
5
|
+
super(config, http_call_back: http_call_back)
|
6
|
+
end
|
7
|
+
|
8
|
+
# Removes your snippet from a Square Online site.
|
9
|
+
# You can call [ListSites]($e/Sites/ListSites) to get the IDs of the sites
|
10
|
+
# that belong to a seller.
|
11
|
+
# __Note:__ Square Online APIs are publicly available as part of an early
|
12
|
+
# access program. For more information, see [Early access program for Square
|
13
|
+
# Online
|
14
|
+
# APIs](https://developer.squareup.com/docs/online-api#early-access-program-
|
15
|
+
# for-square-online-apis).
|
16
|
+
# @param [String] site_id Required parameter: The ID of the site that
|
17
|
+
# contains the snippet.
|
18
|
+
# @return [DeleteSnippetResponse Hash] response from the API call
|
19
|
+
def delete_snippet(site_id:)
|
20
|
+
# Prepare query url.
|
21
|
+
_query_builder = config.get_base_uri
|
22
|
+
_query_builder << '/v2/sites/{site_id}/snippet'
|
23
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
24
|
+
_query_builder,
|
25
|
+
'site_id' => { 'value' => site_id, 'encode' => true }
|
26
|
+
)
|
27
|
+
_query_url = APIHelper.clean_url _query_builder
|
28
|
+
|
29
|
+
# Prepare headers.
|
30
|
+
_headers = {
|
31
|
+
'accept' => 'application/json'
|
32
|
+
}
|
33
|
+
|
34
|
+
# Prepare and execute HttpRequest.
|
35
|
+
_request = config.http_client.delete(
|
36
|
+
_query_url,
|
37
|
+
headers: _headers
|
38
|
+
)
|
39
|
+
OAuth2.apply(config, _request)
|
40
|
+
_response = execute_request(_request)
|
41
|
+
|
42
|
+
# Return appropriate response type.
|
43
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
44
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
45
|
+
ApiResponse.new(
|
46
|
+
_response, data: decoded, errors: _errors
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Retrieves your snippet from a Square Online site. A site can contain
|
51
|
+
# snippets from multiple snippet applications, but you can retrieve only the
|
52
|
+
# snippet that was added by your application.
|
53
|
+
# You can call [ListSites]($e/Sites/ListSites) to get the IDs of the sites
|
54
|
+
# that belong to a seller.
|
55
|
+
# __Note:__ Square Online APIs are publicly available as part of an early
|
56
|
+
# access program. For more information, see [Early access program for Square
|
57
|
+
# Online
|
58
|
+
# APIs](https://developer.squareup.com/docs/online-api#early-access-program-
|
59
|
+
# for-square-online-apis).
|
60
|
+
# @param [String] site_id Required parameter: The ID of the site that
|
61
|
+
# contains the snippet.
|
62
|
+
# @return [RetrieveSnippetResponse Hash] response from the API call
|
63
|
+
def retrieve_snippet(site_id:)
|
64
|
+
# Prepare query url.
|
65
|
+
_query_builder = config.get_base_uri
|
66
|
+
_query_builder << '/v2/sites/{site_id}/snippet'
|
67
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
68
|
+
_query_builder,
|
69
|
+
'site_id' => { 'value' => site_id, 'encode' => true }
|
70
|
+
)
|
71
|
+
_query_url = APIHelper.clean_url _query_builder
|
72
|
+
|
73
|
+
# Prepare headers.
|
74
|
+
_headers = {
|
75
|
+
'accept' => 'application/json'
|
76
|
+
}
|
77
|
+
|
78
|
+
# Prepare and execute HttpRequest.
|
79
|
+
_request = config.http_client.get(
|
80
|
+
_query_url,
|
81
|
+
headers: _headers
|
82
|
+
)
|
83
|
+
OAuth2.apply(config, _request)
|
84
|
+
_response = execute_request(_request)
|
85
|
+
|
86
|
+
# Return appropriate response type.
|
87
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
88
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
89
|
+
ApiResponse.new(
|
90
|
+
_response, data: decoded, errors: _errors
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Adds a snippet to a Square Online site or updates the existing snippet on
|
95
|
+
# the site.
|
96
|
+
# The snippet code is appended to the end of the `head` element on every
|
97
|
+
# page of the site, except checkout pages. A snippet application can add one
|
98
|
+
# snippet to a given site.
|
99
|
+
# You can call [ListSites]($e/Sites/ListSites) to get the IDs of the sites
|
100
|
+
# that belong to a seller.
|
101
|
+
# __Note:__ Square Online APIs are publicly available as part of an early
|
102
|
+
# access program. For more information, see [Early access program for Square
|
103
|
+
# Online
|
104
|
+
# APIs](https://developer.squareup.com/docs/online-api#early-access-program-
|
105
|
+
# for-square-online-apis).
|
106
|
+
# @param [String] site_id Required parameter: The ID of the site where you
|
107
|
+
# want to add or update the snippet.
|
108
|
+
# @param [UpsertSnippetRequest] body Required parameter: An object
|
109
|
+
# containing the fields to POST for the request. See the corresponding
|
110
|
+
# object definition for field details.
|
111
|
+
# @return [UpsertSnippetResponse Hash] response from the API call
|
112
|
+
def upsert_snippet(site_id:,
|
113
|
+
body:)
|
114
|
+
# Prepare query url.
|
115
|
+
_query_builder = config.get_base_uri
|
116
|
+
_query_builder << '/v2/sites/{site_id}/snippet'
|
117
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
118
|
+
_query_builder,
|
119
|
+
'site_id' => { 'value' => site_id, 'encode' => true }
|
120
|
+
)
|
121
|
+
_query_url = APIHelper.clean_url _query_builder
|
122
|
+
|
123
|
+
# Prepare headers.
|
124
|
+
_headers = {
|
125
|
+
'accept' => 'application/json',
|
126
|
+
'Content-Type' => 'application/json'
|
127
|
+
}
|
128
|
+
|
129
|
+
# Prepare and execute HttpRequest.
|
130
|
+
_request = config.http_client.post(
|
131
|
+
_query_url,
|
132
|
+
headers: _headers,
|
133
|
+
parameters: body.to_json
|
134
|
+
)
|
135
|
+
OAuth2.apply(config, _request)
|
136
|
+
_response = execute_request(_request)
|
137
|
+
|
138
|
+
# Return appropriate response type.
|
139
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
140
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
141
|
+
ApiResponse.new(
|
142
|
+
_response, data: decoded, errors: _errors
|
143
|
+
)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|