square.rb 16.0.0.20211117 → 18.0.0.20220216
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 +1 -1
- data/lib/square/api/base_api.rb +16 -1
- data/lib/square/api/bookings_api.rb +28 -3
- data/lib/square/api/catalog_api.rb +101 -26
- data/lib/square/api/locations_api.rb +20 -11
- data/lib/square/api/loyalty_api.rb +5 -14
- data/lib/square/api/merchants_api.rb +10 -8
- data/lib/square/api/mobile_authorization_api.rb +3 -3
- data/lib/square/api/o_auth_api.rb +7 -7
- data/lib/square/api/refunds_api.rb +7 -4
- data/lib/square/api_helper.rb +29 -31
- data/lib/square/client.rb +11 -6
- data/lib/square/configuration.rb +25 -15
- data/lib/square/http/faraday_client.rb +13 -15
- data/test/api/test_locations_api.rb +2 -5
- data/test/test_helper.rb +1 -1
- metadata +2 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d63ad56661f521ead949670191ddb004cf944daedf7836047c9281e8e6600ecf
|
4
|
+
data.tar.gz: 548171c3a90103f2a2492166e6b69f9c0dd7855f1c20d656e4c7c1f922053e86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d5f5cdb0c4992a16eca7327a67642d9fcb807ae040b7c3426d5635ac3ef9f40ab9d144fe011b60c5ad996b81b098e49a3e4cf8a3e6aa3dd4742fab08fd6e1b3
|
7
|
+
data.tar.gz: 56b7b2f269877ec3b2f867d608e0a803a066e74bc958d2e0f60e156a034360e872d0c7eccefa5d552a35b700f2c9cb83b364a942e96968a713ab33013069dea5
|
data/LICENSE
CHANGED
data/README.md
CHANGED
data/lib/square/api/base_api.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'erb'
|
1
2
|
module Square
|
2
3
|
# BaseApi.
|
3
4
|
class BaseApi
|
@@ -8,7 +9,7 @@ module Square
|
|
8
9
|
@http_call_back = http_call_back
|
9
10
|
|
10
11
|
@global_headers = {
|
11
|
-
'user-agent' =>
|
12
|
+
'user-agent' => get_user_agent,
|
12
13
|
'Square-Version' => config.square_version
|
13
14
|
}
|
14
15
|
end
|
@@ -35,5 +36,19 @@ module Square
|
|
35
36
|
|
36
37
|
response
|
37
38
|
end
|
39
|
+
|
40
|
+
def get_user_agent
|
41
|
+
user_agent = 'Square-Ruby-SDK/18.0.0.20220216 ({api-version}) {engine}/{engine-version} ({os-info}) {detail}'
|
42
|
+
user_agent['{engine}'] = RUBY_ENGINE
|
43
|
+
user_agent['{engine-version}'] = RUBY_ENGINE_VERSION
|
44
|
+
user_agent['{os-info}'] = RUBY_PLATFORM
|
45
|
+
user_agent['{api-version}'] = config.square_version
|
46
|
+
if config.user_agent_detail.nil? || config.user_agent_detail.empty?
|
47
|
+
user_agent = user_agent.gsub('{detail}', '')
|
48
|
+
else
|
49
|
+
user_agent['{detail}'] = ERB::Util.url_encode(config.user_agent_detail.to_s)
|
50
|
+
end
|
51
|
+
user_agent
|
52
|
+
end
|
38
53
|
end
|
39
54
|
end
|
@@ -6,6 +6,10 @@ module Square
|
|
6
6
|
end
|
7
7
|
|
8
8
|
# Retrieve a collection of bookings.
|
9
|
+
# To call this endpoint with buyer-level permissions, set
|
10
|
+
# `APPOINTMENTS_READ` for the OAuth scope.
|
11
|
+
# To call this endpoint with seller-level permissions, set
|
12
|
+
# `APPOINTMENTS_ALL_READ` and `APPOINTMENTS_READ` for the OAuth scope.
|
9
13
|
# @param [Integer] limit Optional parameter: The maximum number of results
|
10
14
|
# per page to return in a paged response.
|
11
15
|
# @param [String] cursor Optional parameter: The pagination cursor from the
|
@@ -66,6 +70,10 @@ module Square
|
|
66
70
|
end
|
67
71
|
|
68
72
|
# Creates a booking.
|
73
|
+
# To call this endpoint with buyer-level permissions, set
|
74
|
+
# `APPOINTMENTS_WRITE` for the OAuth scope.
|
75
|
+
# To call this endpoint with seller-level permissions, set
|
76
|
+
# `APPOINTMENTS_ALL_WRITE` and `APPOINTMENTS_WRITE` for the OAuth scope.
|
69
77
|
# @param [CreateBookingRequest] body Required parameter: An object
|
70
78
|
# containing the fields to POST for the request. See the corresponding
|
71
79
|
# object definition for field details.
|
@@ -100,6 +108,10 @@ module Square
|
|
100
108
|
end
|
101
109
|
|
102
110
|
# Searches for availabilities for booking.
|
111
|
+
# To call this endpoint with buyer-level permissions, set
|
112
|
+
# `APPOINTMENTS_READ` for the OAuth scope.
|
113
|
+
# To call this endpoint with seller-level permissions, set
|
114
|
+
# `APPOINTMENTS_ALL_READ` and `APPOINTMENTS_READ` for the OAuth scope.
|
103
115
|
# @param [SearchAvailabilityRequest] body Required parameter: An object
|
104
116
|
# containing the fields to POST for the request. See the corresponding
|
105
117
|
# object definition for field details.
|
@@ -167,9 +179,10 @@ module Square
|
|
167
179
|
# include only bookable team members in the returned result (`true`) or not
|
168
180
|
# (`false`).
|
169
181
|
# @param [Integer] limit Optional parameter: The maximum number of results
|
170
|
-
# to return.
|
171
|
-
# @param [String] cursor Optional parameter: The cursor
|
172
|
-
#
|
182
|
+
# to return in a paged response.
|
183
|
+
# @param [String] cursor Optional parameter: The pagination cursor from the
|
184
|
+
# preceding response to return the next page of the results. Do not set this
|
185
|
+
# when retrieving the first page of the results.
|
173
186
|
# @param [String] location_id Optional parameter: Indicates whether to
|
174
187
|
# include only team members enabled at the given location in the returned
|
175
188
|
# result.
|
@@ -247,6 +260,10 @@ module Square
|
|
247
260
|
end
|
248
261
|
|
249
262
|
# Retrieves a booking.
|
263
|
+
# To call this endpoint with buyer-level permissions, set
|
264
|
+
# `APPOINTMENTS_READ` for the OAuth scope.
|
265
|
+
# To call this endpoint with seller-level permissions, set
|
266
|
+
# `APPOINTMENTS_ALL_READ` and `APPOINTMENTS_READ` for the OAuth scope.
|
250
267
|
# @param [String] booking_id Required parameter: The ID of the
|
251
268
|
# [Booking]($m/Booking) object representing the to-be-retrieved booking.
|
252
269
|
# @return [RetrieveBookingResponse Hash] response from the API call
|
@@ -282,6 +299,10 @@ module Square
|
|
282
299
|
end
|
283
300
|
|
284
301
|
# Updates a booking.
|
302
|
+
# To call this endpoint with buyer-level permissions, set
|
303
|
+
# `APPOINTMENTS_WRITE` for the OAuth scope.
|
304
|
+
# To call this endpoint with seller-level permissions, set
|
305
|
+
# `APPOINTMENTS_ALL_WRITE` and `APPOINTMENTS_WRITE` for the OAuth scope.
|
285
306
|
# @param [String] booking_id Required parameter: The ID of the
|
286
307
|
# [Booking]($m/Booking) object representing the to-be-updated booking.
|
287
308
|
# @param [UpdateBookingRequest] body Required parameter: An object
|
@@ -323,6 +344,10 @@ module Square
|
|
323
344
|
end
|
324
345
|
|
325
346
|
# Cancels an existing booking.
|
347
|
+
# To call this endpoint with buyer-level permissions, set
|
348
|
+
# `APPOINTMENTS_WRITE` for the OAuth scope.
|
349
|
+
# To call this endpoint with seller-level permissions, set
|
350
|
+
# `APPOINTMENTS_ALL_WRITE` and `APPOINTMENTS_WRITE` for the OAuth scope.
|
326
351
|
# @param [String] booking_id Required parameter: The ID of the
|
327
352
|
# [Booking]($m/Booking) object representing the to-be-cancelled booking.
|
328
353
|
# @param [CancelBookingRequest] body Required parameter: An object
|
@@ -136,10 +136,10 @@ module Square
|
|
136
136
|
end
|
137
137
|
|
138
138
|
# Uploads an image file to be represented by a
|
139
|
-
# [CatalogImage]($m/CatalogImage) object linked to an existing
|
140
|
-
# [CatalogObject]($m/CatalogObject) instance.
|
141
|
-
#
|
142
|
-
#
|
139
|
+
# [CatalogImage]($m/CatalogImage) object that can be linked to an existing
|
140
|
+
# [CatalogObject]($m/CatalogObject) instance. The resulting `CatalogImage`
|
141
|
+
# is unattached to any `CatalogObject` if the `object_id`
|
142
|
+
# is not specified.
|
143
143
|
# This `CreateCatalogImage` endpoint accepts HTTP multipart/form-data
|
144
144
|
# requests with a JSON part and an image file part in
|
145
145
|
# JPEG, PJPEG, PNG, or GIF format. The maximum file size is 15MB.
|
@@ -196,6 +196,71 @@ module Square
|
|
196
196
|
)
|
197
197
|
end
|
198
198
|
|
199
|
+
# Uploads a new image file to replace the existing one in the specified
|
200
|
+
# [CatalogImage]($m/CatalogImage) object.
|
201
|
+
# This `UpdateCatalogImage` endpoint accepts HTTP multipart/form-data
|
202
|
+
# requests with a JSON part and an image file part in
|
203
|
+
# JPEG, PJPEG, PNG, or GIF format. The maximum file size is 15MB.
|
204
|
+
# @param [String] image_id Required parameter: The ID of the `CatalogImage`
|
205
|
+
# object to update the encapsulated image file.
|
206
|
+
# @param [UpdateCatalogImageRequest] request Optional parameter: Example:
|
207
|
+
# @param [File | UploadIO] image_file Optional parameter: Example:
|
208
|
+
# @return [UpdateCatalogImageResponse Hash] response from the API call
|
209
|
+
def update_catalog_image(image_id:,
|
210
|
+
request: nil,
|
211
|
+
image_file: nil)
|
212
|
+
# Prepare query url.
|
213
|
+
_query_builder = config.get_base_uri
|
214
|
+
_query_builder << '/v2/catalog/images/{image_id}'
|
215
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
216
|
+
_query_builder,
|
217
|
+
'image_id' => { 'value' => image_id, 'encode' => true }
|
218
|
+
)
|
219
|
+
_query_url = APIHelper.clean_url _query_builder
|
220
|
+
|
221
|
+
if image_file.is_a? FileWrapper
|
222
|
+
image_file_wrapper = image_file.file
|
223
|
+
image_file_content_type = image_file.content_type
|
224
|
+
else
|
225
|
+
image_file_wrapper = image_file
|
226
|
+
image_file_content_type = 'image/jpeg'
|
227
|
+
end
|
228
|
+
|
229
|
+
# Prepare headers.
|
230
|
+
_headers = {
|
231
|
+
'accept' => 'application/json'
|
232
|
+
}
|
233
|
+
|
234
|
+
# Prepare form parameters.
|
235
|
+
_parameters = {
|
236
|
+
'request' => Faraday::UploadIO.new(
|
237
|
+
StringIO.new(request.to_json),
|
238
|
+
'application/json'
|
239
|
+
),
|
240
|
+
'image_file' => Faraday::UploadIO.new(
|
241
|
+
image_file_wrapper,
|
242
|
+
image_file_content_type
|
243
|
+
)
|
244
|
+
}
|
245
|
+
_parameters = APIHelper.form_encode_parameters(_parameters)
|
246
|
+
|
247
|
+
# Prepare and execute HttpRequest.
|
248
|
+
_request = config.http_client.put(
|
249
|
+
_query_url,
|
250
|
+
headers: _headers,
|
251
|
+
parameters: _parameters
|
252
|
+
)
|
253
|
+
OAuth2.apply(config, _request)
|
254
|
+
_response = execute_request(_request)
|
255
|
+
|
256
|
+
# Return appropriate response type.
|
257
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
258
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
259
|
+
ApiResponse.new(
|
260
|
+
_response, data: decoded, errors: _errors
|
261
|
+
)
|
262
|
+
end
|
263
|
+
|
199
264
|
# Retrieves information about the Square Catalog API, such as batch size
|
200
265
|
# limits that can be used by the `BatchUpsertCatalogObjects` endpoint.
|
201
266
|
# @return [CatalogInfoResponse Hash] response from the API call
|
@@ -226,15 +291,12 @@ module Square
|
|
226
291
|
)
|
227
292
|
end
|
228
293
|
|
229
|
-
# Returns a list of [CatalogObject]($m/CatalogObject)s
|
230
|
-
#
|
231
|
-
#
|
232
|
-
#
|
233
|
-
#
|
234
|
-
#
|
235
|
-
# [CatalogObject]($m/CatalogObject) types:
|
236
|
-
# `ITEM`, `ITEM_VARIATION`, `MODIFIER`, `MODIFIER_LIST`, `CATEGORY`,
|
237
|
-
# `DISCOUNT`, `TAX`, `IMAGE`.
|
294
|
+
# Returns a list of all [CatalogObject]($m/CatalogObject)s of the specified
|
295
|
+
# types in the catalog.
|
296
|
+
# The `types` parameter is specified as a comma-separated list of the
|
297
|
+
# [CatalogObjectType]($m/CatalogObjectType) values,
|
298
|
+
# for example, "`ITEM`, `ITEM_VARIATION`, `MODIFIER`, `MODIFIER_LIST`,
|
299
|
+
# `CATEGORY`, `DISCOUNT`, `TAX`, `IMAGE`".
|
238
300
|
# __Important:__ ListCatalog does not return deleted catalog items. To
|
239
301
|
# retrieve
|
240
302
|
# deleted catalog items, use
|
@@ -247,16 +309,22 @@ module Square
|
|
247
309
|
# for more information.
|
248
310
|
# @param [String] types Optional parameter: An optional case-insensitive,
|
249
311
|
# comma-separated list of object types to retrieve. The valid values are
|
250
|
-
# defined in the [CatalogObjectType]($m/CatalogObjectType) enum,
|
251
|
-
# `ITEM`, `ITEM_VARIATION`, `CATEGORY`, `DISCOUNT`, `TAX`,
|
252
|
-
# `MODIFIER_LIST`,
|
253
|
-
# returns objects of all the types at the version of the
|
254
|
-
# make the request.
|
312
|
+
# defined in the [CatalogObjectType]($m/CatalogObjectType) enum, for
|
313
|
+
# example, `ITEM`, `ITEM_VARIATION`, `CATEGORY`, `DISCOUNT`, `TAX`,
|
314
|
+
# `MODIFIER`, `MODIFIER_LIST`, `IMAGE`, etc. If this is unspecified, the
|
315
|
+
# operation returns objects of all the top level types at the version of the
|
316
|
+
# Square API used to make the request. Object types that are nested onto
|
317
|
+
# other object types are not included in the defaults. At the current API
|
318
|
+
# version the default object types are: ITEM, CATEGORY, TAX, DISCOUNT,
|
319
|
+
# MODIFIER_LIST, DINING_OPTION, TAX_EXEMPTION, SERVICE_CHARGE, PRICING_RULE,
|
320
|
+
# PRODUCT_SET, TIME_PERIOD, MEASUREMENT_UNIT, SUBSCRIPTION_PLAN,
|
321
|
+
# ITEM_OPTION, CUSTOM_ATTRIBUTE_DEFINITION, QUICK_AMOUNT_SETTINGS.
|
255
322
|
# @param [Long] catalog_version Optional parameter: The specific version of
|
256
323
|
# the catalog objects to be included in the response. This allows you to
|
257
324
|
# retrieve historical versions of objects. The specified version value is
|
258
325
|
# matched against the [CatalogObject]($m/CatalogObject)s' `version`
|
259
|
-
# attribute.
|
326
|
+
# attribute. If not included, results will be from the current version of
|
327
|
+
# the catalog.
|
260
328
|
# @return [ListCatalogResponse Hash] response from the API call
|
261
329
|
def list_catalog(cursor: nil,
|
262
330
|
types: nil,
|
@@ -382,17 +450,24 @@ module Square
|
|
382
450
|
# catalog objects to be retrieved.
|
383
451
|
# @param [Boolean] include_related_objects Optional parameter: If `true`,
|
384
452
|
# the response will include additional objects that are related to the
|
385
|
-
# requested
|
386
|
-
#
|
387
|
-
#
|
388
|
-
#
|
389
|
-
#
|
390
|
-
# be
|
391
|
-
#
|
453
|
+
# requested objects. Related objects are defined as any objects referenced
|
454
|
+
# by ID by the results in the `objects` field of the response. These objects
|
455
|
+
# are put in the `related_objects` field. Setting this to `true` is helpful
|
456
|
+
# when the objects are needed for immediate display to a user. This process
|
457
|
+
# only goes one level deep. Objects referenced by the related objects will
|
458
|
+
# not be included. For example, if the `objects` field of the response
|
459
|
+
# contains a CatalogItem, its associated CatalogCategory objects, CatalogTax
|
460
|
+
# objects, CatalogImage objects and CatalogModifierLists will be returned in
|
461
|
+
# the `related_objects` field of the response. If the `objects` field of the
|
462
|
+
# response contains a CatalogItemVariation, its parent CatalogItem will be
|
463
|
+
# returned in the `related_objects` field of the response. Default value:
|
464
|
+
# `false`
|
392
465
|
# @param [Long] catalog_version Optional parameter: Requests objects as of a
|
393
466
|
# specific version of the catalog. This allows you to retrieve historical
|
394
467
|
# versions of objects. The value to retrieve a specific version of an object
|
395
468
|
# can be found in the version field of [CatalogObject]($m/CatalogObject)s.
|
469
|
+
# If not included, results will be from the current version of the
|
470
|
+
# catalog.
|
396
471
|
# @return [RetrieveCatalogObjectResponse Hash] response from the API call
|
397
472
|
def retrieve_catalog_object(object_id:,
|
398
473
|
include_related_objects: false,
|
@@ -5,10 +5,9 @@ module Square
|
|
5
5
|
super(config, http_call_back: http_call_back)
|
6
6
|
end
|
7
7
|
|
8
|
-
# Provides
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# endpoint correspond to that `location_id` parameter.
|
8
|
+
# Provides details about all of the seller's
|
9
|
+
# [locations](https://developer.squareup.com/docs/locations-api),
|
10
|
+
# including those with an inactive status.
|
12
11
|
# @return [ListLocationsResponse Hash] response from the API call
|
13
12
|
def list_locations
|
14
13
|
# Prepare query url.
|
@@ -37,7 +36,17 @@ module Square
|
|
37
36
|
)
|
38
37
|
end
|
39
38
|
|
40
|
-
# Creates a location.
|
39
|
+
# Creates a [location](https://developer.squareup.com/docs/locations-api).
|
40
|
+
# Creating new locations allows for separate configuration of receipt
|
41
|
+
# layouts, item prices,
|
42
|
+
# and sales reports. Developers can use locations to separate sales activity
|
43
|
+
# via applications
|
44
|
+
# that integrate with Square from sales activity elsewhere in a seller's
|
45
|
+
# account.
|
46
|
+
# Locations created programmatically with the Locations API will last
|
47
|
+
# forever and
|
48
|
+
# are visible to the seller for their own management, so ensure that
|
49
|
+
# each location has a sensible and unique name.
|
41
50
|
# @param [CreateLocationRequest] body Required parameter: An object
|
42
51
|
# containing the fields to POST for the request. See the corresponding
|
43
52
|
# object definition for field details.
|
@@ -71,12 +80,12 @@ module Square
|
|
71
80
|
)
|
72
81
|
end
|
73
82
|
|
74
|
-
# Retrieves details of a location.
|
75
|
-
# as the location ID to retrieve details of the
|
76
|
-
#
|
83
|
+
# Retrieves details of a single location. Specify "main"
|
84
|
+
# as the location ID to retrieve details of the [main
|
85
|
+
# location](https://developer.squareup.com/docs/locations-api#about-the-main
|
86
|
+
# -location).
|
77
87
|
# @param [String] location_id Required parameter: The ID of the location to
|
78
|
-
# retrieve.
|
79
|
-
# main location.
|
88
|
+
# retrieve. Specify the string "main" to return the main location.
|
80
89
|
# @return [RetrieveLocationResponse Hash] response from the API call
|
81
90
|
def retrieve_location(location_id:)
|
82
91
|
# Prepare query url.
|
@@ -109,7 +118,7 @@ module Square
|
|
109
118
|
)
|
110
119
|
end
|
111
120
|
|
112
|
-
# Updates a location.
|
121
|
+
# Updates a [location](https://developer.squareup.com/docs/locations-api).
|
113
122
|
# @param [String] location_id Required parameter: The ID of the location to
|
114
123
|
# update.
|
115
124
|
# @param [UpdateLocationRequest] body Required parameter: An object
|
@@ -124,12 +124,6 @@ module Square
|
|
124
124
|
# [CalculateLoyaltyPoints]($e/Loyalty/CalculateLoyaltyPoints) to compute the
|
125
125
|
# points
|
126
126
|
# that you provide to this endpoint.
|
127
|
-
# __Note:__ The country of the seller's Square account determines whether
|
128
|
-
# tax is included in the purchase amount when accruing points for
|
129
|
-
# spend-based and visit-based programs.
|
130
|
-
# For more information, see [Availability of Square
|
131
|
-
# Loyalty](https://developer.squareup.com/docs/loyalty-api/overview#loyalty-
|
132
|
-
# market-availability).
|
133
127
|
# @param [String] account_id Required parameter: The [loyalty
|
134
128
|
# account]($m/LoyaltyAccount) ID to which to add the points.
|
135
129
|
# @param [AccumulateLoyaltyPointsRequest] body Required parameter: An object
|
@@ -336,8 +330,8 @@ module Square
|
|
336
330
|
end
|
337
331
|
|
338
332
|
# Calculates the points a purchase earns.
|
339
|
-
# - If you are using the Orders API to manage orders, you provide
|
340
|
-
# in the request. The
|
333
|
+
# - If you are using the Orders API to manage orders, you provide the
|
334
|
+
# `order_id` in the request. The
|
341
335
|
# endpoint calculates the points by reading the order.
|
342
336
|
# - If you are not using the Orders API to manage orders, you provide the
|
343
337
|
# purchase amount in
|
@@ -345,12 +339,9 @@ module Square
|
|
345
339
|
# An application might call this endpoint to show the points that a buyer
|
346
340
|
# can earn with the
|
347
341
|
# specific purchase.
|
348
|
-
#
|
349
|
-
#
|
350
|
-
#
|
351
|
-
# For more information, see [Availability of Square
|
352
|
-
# Loyalty](https://developer.squareup.com/docs/loyalty-api/overview#loyalty-
|
353
|
-
# market-availability).
|
342
|
+
# For spend-based and visit-based programs, the `tax_mode` setting of the
|
343
|
+
# accrual rule indicates how taxes should be treated for loyalty points
|
344
|
+
# accrual.
|
354
345
|
# @param [String] program_id Required parameter: The [loyalty
|
355
346
|
# program]($m/LoyaltyProgram) ID, which defines the rules for accruing
|
356
347
|
# points.
|
@@ -5,15 +5,17 @@ module Square
|
|
5
5
|
super(config, http_call_back: http_call_back)
|
6
6
|
end
|
7
7
|
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
8
|
+
# Provides details about the merchant associated with a given access token.
|
9
|
+
# The access token used to connect your application to a Square seller is
|
10
|
+
# associated
|
11
|
+
# with a single merchant. That means that `ListMerchants` returns a list
|
12
|
+
# with a single `Merchant` object. You can specify your personal access
|
13
|
+
# token
|
14
|
+
# to get your own merchant information or specify an OAuth token to get the
|
15
|
+
# information for the merchant that granted your application access.
|
14
16
|
# If you know the merchant ID, you can also use the
|
15
17
|
# [RetrieveMerchant]($e/Merchants/RetrieveMerchant)
|
16
|
-
# endpoint to
|
18
|
+
# endpoint to retrieve the merchant information.
|
17
19
|
# @param [Integer] cursor Optional parameter: The cursor generated by the
|
18
20
|
# previous response.
|
19
21
|
# @return [ListMerchantsResponse Hash] response from the API call
|
@@ -48,7 +50,7 @@ module Square
|
|
48
50
|
)
|
49
51
|
end
|
50
52
|
|
51
|
-
#
|
53
|
+
# Retrieves the `Merchant` object for the given `merchant_id`.
|
52
54
|
# @param [String] merchant_id Required parameter: The ID of the merchant to
|
53
55
|
# retrieve. If the string "me" is supplied as the ID, then retrieve the
|
54
56
|
# merchant that is currently accessible to this call.
|
@@ -6,9 +6,9 @@ module Square
|
|
6
6
|
end
|
7
7
|
|
8
8
|
# Generates code to authorize a mobile application to connect to a Square
|
9
|
-
# card reader
|
10
|
-
# Authorization codes are one-time-use and expire
|
11
|
-
# issued.
|
9
|
+
# card reader.
|
10
|
+
# Authorization codes are one-time-use codes and expire 60 minutes after
|
11
|
+
# being issued.
|
12
12
|
# __Important:__ The `Authorization` header you provide to this endpoint
|
13
13
|
# must have the following format:
|
14
14
|
# ```
|
@@ -12,11 +12,11 @@ module Square
|
|
12
12
|
# okens).
|
13
13
|
# Renews an OAuth access token before it expires.
|
14
14
|
# OAuth access tokens besides your application's personal access token
|
15
|
-
# expire after
|
16
|
-
# You can also renew expired tokens within
|
15
|
+
# expire after 30 days.
|
16
|
+
# You can also renew expired tokens within 15 days of their expiration.
|
17
17
|
# You cannot renew an access token that has been expired for more than 15
|
18
18
|
# days.
|
19
|
-
# Instead, the associated user must
|
19
|
+
# Instead, the associated user must recomplete the OAuth flow from the
|
20
20
|
# beginning.
|
21
21
|
# __Important:__ The `Authorization` header for this endpoint must have the
|
22
22
|
# following format:
|
@@ -25,10 +25,10 @@ module Square
|
|
25
25
|
# ```
|
26
26
|
# Replace `APPLICATION_SECRET` with the application secret on the
|
27
27
|
# Credentials
|
28
|
-
# page in the [
|
29
|
-
# @param [String] client_id Required parameter: Your application ID,
|
30
|
-
# available
|
31
|
-
# Dashboard.
|
28
|
+
# page in the [Developer Dashboard](https://developer.squareup.com/apps).
|
29
|
+
# @param [String] client_id Required parameter: Your application ID, which
|
30
|
+
# is available in the OAuth page in the [Developer
|
31
|
+
# Dashboard](https://developer.squareup.com/apps).
|
32
32
|
# @param [RenewTokenRequest] body Required parameter: An object containing
|
33
33
|
# the fields to POST for the request. See the corresponding object
|
34
34
|
# definition for field details.
|
@@ -31,10 +31,13 @@ module Square
|
|
31
31
|
# the given status are returned. For a list of refund status values, see
|
32
32
|
# [PaymentRefund]($m/PaymentRefund). Default: If omitted, refunds are
|
33
33
|
# returned regardless of their status.
|
34
|
-
# @param [String] source_type Optional parameter: If provided, only
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
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.
|
38
41
|
# @param [Integer] limit Optional parameter: The maximum number of results
|
39
42
|
# to be returned in a single page. It is possible to receive fewer results
|
40
43
|
# than the specified limit on a given page. If the supplied value is
|
data/lib/square/api_helper.rb
CHANGED
@@ -8,18 +8,16 @@ module Square
|
|
8
8
|
def self.serialize_array(key, array, formatting: 'indexed')
|
9
9
|
tuples = []
|
10
10
|
|
11
|
-
case formatting
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
raise ArgumentError, 'Invalid format provided.'
|
22
|
-
end
|
11
|
+
tuples += case formatting
|
12
|
+
when 'csv'
|
13
|
+
[[key, array.map { |element| CGI.escape(element.to_s) }.join(',')]]
|
14
|
+
when 'psv'
|
15
|
+
[[key, array.map { |element| CGI.escape(element.to_s) }.join('|')]]
|
16
|
+
when 'tsv'
|
17
|
+
[[key, array.map { |element| CGI.escape(element.to_s) }.join("\t")]]
|
18
|
+
else
|
19
|
+
array.map { |element| [key, element] }
|
20
|
+
end
|
23
21
|
tuples
|
24
22
|
end
|
25
23
|
|
@@ -75,31 +73,19 @@ module Square
|
|
75
73
|
return query_builder if parameters.nil?
|
76
74
|
|
77
75
|
array_serialization = 'indexed'
|
76
|
+
parameters = process_complex_types_parameters(parameters, array_serialization)
|
78
77
|
|
79
78
|
parameters.each do |key, value|
|
80
79
|
seperator = query_builder.include?('?') ? '&' : '?'
|
81
80
|
unless value.nil?
|
82
81
|
if value.instance_of? Array
|
83
82
|
value.compact!
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
"#{seperator}#{key}=#{value.map do |element|
|
91
|
-
CGI.escape(element.to_s)
|
92
|
-
end.join('|')}"
|
93
|
-
when 'tsv'
|
94
|
-
"#{seperator}#{key}=#{value.map do |element|
|
95
|
-
CGI.escape(element.to_s)
|
96
|
-
end.join("\t")}"
|
97
|
-
else
|
98
|
-
"#{seperator}#{APIHelper.serialize_array(
|
99
|
-
key, value, formatting: array_serialization
|
100
|
-
).map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }
|
101
|
-
.join('&')}"
|
102
|
-
end
|
83
|
+
APIHelper.serialize_array(
|
84
|
+
key, value, formatting: array_serialization
|
85
|
+
).each do |element|
|
86
|
+
seperator = query_builder.include?('?') ? '&' : '?'
|
87
|
+
query_builder += "#{seperator}#{element[0]}=#{element[1]}"
|
88
|
+
end
|
103
89
|
else
|
104
90
|
query_builder += "#{seperator}#{key}=#{CGI.escape(value.to_s)}"
|
105
91
|
end
|
@@ -163,6 +149,18 @@ module Square
|
|
163
149
|
encoded
|
164
150
|
end
|
165
151
|
|
152
|
+
# Process complex types in query_params.
|
153
|
+
# @param [Hash] The hash of query parameters.
|
154
|
+
# @return [Hash] A hash with the processed query parameters.
|
155
|
+
def self.process_complex_types_parameters(query_parameters, array_serialization)
|
156
|
+
processed_params = {}
|
157
|
+
query_parameters.each do |key, value|
|
158
|
+
processed_params.merge!(APIHelper.form_encode(value, key, formatting:
|
159
|
+
array_serialization))
|
160
|
+
end
|
161
|
+
processed_params
|
162
|
+
end
|
163
|
+
|
166
164
|
def self.custom_merge(a, b)
|
167
165
|
x = {}
|
168
166
|
a.each do |key, value_a|
|
data/lib/square/client.rb
CHANGED
@@ -4,13 +4,17 @@ module Square
|
|
4
4
|
attr_reader :config
|
5
5
|
|
6
6
|
def sdk_version
|
7
|
-
'
|
7
|
+
'18.0.0.20220216'
|
8
8
|
end
|
9
9
|
|
10
10
|
def square_version
|
11
11
|
config.square_version
|
12
12
|
end
|
13
13
|
|
14
|
+
def user_agent_detail
|
15
|
+
config.user_agent_detail
|
16
|
+
end
|
17
|
+
|
14
18
|
# Access to mobile_authorization controller.
|
15
19
|
# @return [MobileAuthorizationApi] Returns the controller instance.
|
16
20
|
def mobile_authorization
|
@@ -209,16 +213,16 @@ module Square
|
|
209
213
|
@terminal ||= TerminalApi.new config
|
210
214
|
end
|
211
215
|
|
212
|
-
def initialize(
|
216
|
+
def initialize(connection: nil, timeout: 60, max_retries: 0,
|
213
217
|
retry_interval: 1, backoff_factor: 2,
|
214
218
|
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
|
215
219
|
retry_methods: %i[get put], environment: 'production',
|
216
220
|
custom_url: 'https://connect.squareup.com',
|
217
|
-
square_version: '
|
218
|
-
additional_headers: {}, config: nil)
|
221
|
+
square_version: '2022-02-16', access_token: '',
|
222
|
+
user_agent_detail: '', additional_headers: {}, config: nil)
|
219
223
|
@config = if config.nil?
|
220
|
-
Configuration.new(
|
221
|
-
|
224
|
+
Configuration.new(connection: connection, timeout: timeout,
|
225
|
+
max_retries: max_retries,
|
222
226
|
retry_interval: retry_interval,
|
223
227
|
backoff_factor: backoff_factor,
|
224
228
|
retry_statuses: retry_statuses,
|
@@ -227,6 +231,7 @@ module Square
|
|
227
231
|
custom_url: custom_url,
|
228
232
|
square_version: square_version,
|
229
233
|
access_token: access_token,
|
234
|
+
user_agent_detail: user_agent_detail,
|
230
235
|
additional_headers: additional_headers)
|
231
236
|
else
|
232
237
|
config
|
data/lib/square/configuration.rb
CHANGED
@@ -3,9 +3,9 @@ module Square
|
|
3
3
|
# are configured in this class.
|
4
4
|
class Configuration
|
5
5
|
# The attribute readers for properties.
|
6
|
-
attr_reader :http_client, :
|
7
|
-
:
|
8
|
-
:
|
6
|
+
attr_reader :http_client, :connection, :timeout, :max_retries, :retry_interval, :backoff_factor,
|
7
|
+
:retry_statuses, :retry_methods, :environment, :custom_url, :square_version,
|
8
|
+
:access_token, :user_agent_detail
|
9
9
|
|
10
10
|
def additional_headers
|
11
11
|
@additional_headers.clone
|
@@ -15,15 +15,15 @@ module Square
|
|
15
15
|
attr_reader :environments
|
16
16
|
end
|
17
17
|
|
18
|
-
def initialize(
|
18
|
+
def initialize(connection: nil, timeout: 60, max_retries: 0,
|
19
19
|
retry_interval: 1, backoff_factor: 2,
|
20
20
|
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
|
21
21
|
retry_methods: %i[get put], environment: 'production',
|
22
22
|
custom_url: 'https://connect.squareup.com',
|
23
|
-
square_version: '
|
24
|
-
additional_headers: {})
|
25
|
-
# The
|
26
|
-
@
|
23
|
+
square_version: '2022-02-16', access_token: '',
|
24
|
+
user_agent_detail: '', additional_headers: {})
|
25
|
+
# The Faraday connection object passed by the SDK user for making requests
|
26
|
+
@connection = connection
|
27
27
|
|
28
28
|
# The value to use for connection timeout
|
29
29
|
@timeout = timeout
|
@@ -61,14 +61,17 @@ module Square
|
|
61
61
|
|
62
62
|
# The Http Client to use for making requests.
|
63
63
|
@http_client = create_http_client
|
64
|
+
|
65
|
+
# User agent detail, to be appended with user-agent header.
|
66
|
+
@user_agent_detail = get_user_agent(user_agent_detail)
|
64
67
|
end
|
65
68
|
|
66
|
-
def clone_with(
|
69
|
+
def clone_with(connection: nil, timeout: nil, max_retries: nil,
|
67
70
|
retry_interval: nil, backoff_factor: nil,
|
68
71
|
retry_statuses: nil, retry_methods: nil, environment: nil,
|
69
72
|
custom_url: nil, square_version: nil, access_token: nil,
|
70
|
-
additional_headers: nil)
|
71
|
-
|
73
|
+
user_agent_detail: nil, additional_headers: nil)
|
74
|
+
connection ||= self.connection
|
72
75
|
timeout ||= self.timeout
|
73
76
|
max_retries ||= self.max_retries
|
74
77
|
retry_interval ||= self.retry_interval
|
@@ -79,16 +82,18 @@ module Square
|
|
79
82
|
custom_url ||= self.custom_url
|
80
83
|
square_version ||= self.square_version
|
81
84
|
access_token ||= self.access_token
|
85
|
+
user_agent_detail ||= self.user_agent_detail
|
82
86
|
additional_headers ||= self.additional_headers
|
83
87
|
|
84
|
-
Configuration.new(
|
85
|
-
|
88
|
+
Configuration.new(connection: connection, timeout: timeout,
|
89
|
+
max_retries: max_retries,
|
86
90
|
retry_interval: retry_interval,
|
87
91
|
backoff_factor: backoff_factor,
|
88
92
|
retry_statuses: retry_statuses,
|
89
93
|
retry_methods: retry_methods, environment: environment,
|
90
94
|
custom_url: custom_url, square_version: square_version,
|
91
95
|
access_token: access_token,
|
96
|
+
user_agent_detail: user_agent_detail,
|
92
97
|
additional_headers: additional_headers)
|
93
98
|
end
|
94
99
|
|
@@ -97,8 +102,13 @@ module Square
|
|
97
102
|
retry_interval: retry_interval,
|
98
103
|
backoff_factor: backoff_factor,
|
99
104
|
retry_statuses: retry_statuses,
|
100
|
-
retry_methods: retry_methods,
|
101
|
-
|
105
|
+
retry_methods: retry_methods, connection: connection)
|
106
|
+
end
|
107
|
+
|
108
|
+
def get_user_agent(user_agent_detail)
|
109
|
+
raise ArgumentError, 'The length of user-agent detail should not exceed 128 characters.' unless user_agent_detail.length < 128
|
110
|
+
|
111
|
+
user_agent_detail
|
102
112
|
end
|
103
113
|
|
104
114
|
# All the environments the SDK can run in.
|
@@ -4,29 +4,28 @@ require 'faraday_middleware'
|
|
4
4
|
module Square
|
5
5
|
# An implementation of HttpClient.
|
6
6
|
class FaradayClient < HttpClient
|
7
|
+
# The attribute readers for properties.
|
8
|
+
attr_reader :connection
|
9
|
+
|
7
10
|
# The constructor.
|
8
11
|
def initialize(timeout:, max_retries:, retry_interval:,
|
9
12
|
backoff_factor:, retry_statuses:, retry_methods:,
|
10
|
-
|
11
|
-
if
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
"`connection` cannot be nil in `#{self.class}`. Please specify a valid value."
|
20
|
-
end
|
21
|
-
@connection = http_client_instance.instance_variable_get('@connection')
|
22
|
-
end
|
13
|
+
connection: nil, cache: false, verify: true)
|
14
|
+
@connection = if connection.nil?
|
15
|
+
create_connection(timeout: timeout, max_retries: max_retries,
|
16
|
+
retry_interval: retry_interval, backoff_factor: backoff_factor,
|
17
|
+
retry_statuses: retry_statuses, retry_methods: retry_methods,
|
18
|
+
cache: cache, verify: verify)
|
19
|
+
else
|
20
|
+
connection
|
21
|
+
end
|
23
22
|
end
|
24
23
|
|
25
24
|
# Method to initialize connection.
|
26
25
|
def create_connection(timeout:, max_retries:, retry_interval:,
|
27
26
|
backoff_factor:, retry_statuses:, retry_methods:,
|
28
27
|
cache: false, verify: true)
|
29
|
-
|
28
|
+
Faraday.new do |faraday|
|
30
29
|
faraday.use Faraday::HttpCache, serializer: Marshal if cache
|
31
30
|
faraday.use FaradayMiddleware::FollowRedirects
|
32
31
|
faraday.use :gzip
|
@@ -42,7 +41,6 @@ module Square
|
|
42
41
|
faraday.options[:params_encoder] = Faraday::FlatParamsEncoder
|
43
42
|
faraday.options[:timeout] = timeout if timeout.positive?
|
44
43
|
end
|
45
|
-
@connection
|
46
44
|
end
|
47
45
|
|
48
46
|
# Method overridden from HttpClient.
|
@@ -7,11 +7,8 @@ class LocationsApiTests < ApiTestBase
|
|
7
7
|
@controller = LocationsApi.new CONFIG, http_call_back: @response_catcher
|
8
8
|
end
|
9
9
|
|
10
|
-
# Provides
|
11
|
-
#
|
12
|
-
#Many Square API endpoints require a `location_id` parameter.
|
13
|
-
#The `id` field of the [`Location`]($m/Location) objects returned by this
|
14
|
-
#endpoint correspond to that `location_id` parameter.
|
10
|
+
# Provides details about all of the seller's [locations](https://developer.squareup.com/docs/locations-api),
|
11
|
+
#including those with an inactive status.
|
15
12
|
def test_list_locations()
|
16
13
|
|
17
14
|
# Perform the API call through the SDK function
|
data/test/test_helper.rb
CHANGED
@@ -82,7 +82,7 @@ class TestHelper
|
|
82
82
|
unless @cache.keys.include? url
|
83
83
|
@cache[url] = Tempfile.new('APIMatic')
|
84
84
|
@cache[url].binmode
|
85
|
-
@cache[url].write(open(url, {ssl_ca_cert: Certifi.where}).read)
|
85
|
+
@cache[url].write(URI.open(url, {ssl_ca_cert: Certifi.where}).read)
|
86
86
|
end
|
87
87
|
return @cache[url].path
|
88
88
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: square.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 18.0.0.20220216
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Square Developer Platform
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logging
|
@@ -209,9 +209,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
209
209
|
- - ">="
|
210
210
|
- !ruby/object:Gem::Version
|
211
211
|
version: '2.5'
|
212
|
-
- - "<"
|
213
|
-
- !ruby/object:Gem::Version
|
214
|
-
version: '3.0'
|
215
212
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
216
213
|
requirements:
|
217
214
|
- - ">="
|