square.rb 10.0.0.202104217 → 13.1.0.20210818

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b1c9c3a6b13fa697e2fffc362d766cb1b7ded51f360ad7fcf342039d2623911d
4
- data.tar.gz: 11954b03a0f85edec268ef6d4f7bb020386dfba4134f28a720c5b6c39b3c2315
3
+ metadata.gz: a624808dd5bb0375fef64adf65cbe8203c6b582bd38e34afb69b4b0c0f4fd8a4
4
+ data.tar.gz: 849966858b71f5a2b2f4abb9811561156172b591cf2a3c93886bee88c5ecff83
5
5
  SHA512:
6
- metadata.gz: cc03189601f3985171af4af574f987b31d4c3132ffb96b7d4ada0996056309183a50d1f02a8af602a9a63543f0737903f336185a7e4284db324df74ff114f6e5
7
- data.tar.gz: 042712b0f44ce7a117e7b1cd7f9286d4ada8c033d54b9e347e62a4dc491463fa984f5f0590c9a6d29ef0f3bade77199ee76eab60f4c7960c12a6e95d551acc15
6
+ metadata.gz: bcb9330214a8a813a1d6bf405db19dcd2264f70f1745b793c9cf7c844f340dc056cf7a141a0e12ca65187ee02d1c856ee59621ab2143f18e518bdc734bc9f35c
7
+ data.tar.gz: 5a93c48a1751fae253c1819fd0c4925b47e3998be01ad9af2acae45cbac6c4a6d9979bf4e0e36baa9475bd54c396135c5d136981fc4b87ec0c04d507cf259698
data/README.md CHANGED
@@ -2,12 +2,16 @@
2
2
 
3
3
  # Square Ruby SDK
4
4
 
5
- [![Travis status](https://travis-ci.org/square/square-ruby-sdk.svg?branch=master)](https://travis-ci.org/square/square-ruby-sdk)
5
+ [![Build](https://github.com/square/square-ruby-sdk/actions/workflows/ruby.yml/badge.svg)](https://github.com/square/square-ruby-sdk/actions/workflows/ruby.yml)
6
6
  [![Gem version](https://badge.fury.io/rb/square.rb.svg?new)](https://badge.fury.io/rb/square.rb)
7
7
  [![Apache-2 license](https://img.shields.io/badge/license-Apache2-brightgreen.svg)](https://www.apache.org/licenses/LICENSE-2.0)
8
8
 
9
9
  Use this gem to integrate Square payments into your app and grow your business with Square APIs including Catalog, Customers, Employees, Inventory, Labor, Locations, and Orders.
10
10
 
11
+ ## Requirements
12
+
13
+ We support Ruby 2.5.x, 2.6.x, and 2.7.x.
14
+
11
15
  ## Installation
12
16
 
13
17
  Install the gem from the command line:
@@ -73,9 +77,13 @@ gem 'square.rb'
73
77
  ### Financials
74
78
  * [Bank Accounts]
75
79
 
80
+ ### Online
81
+ * [Sites]
82
+ * [Snippets]
83
+
76
84
  ### Authorization APIs
77
85
  * [Mobile Authorization]
78
- * [O Auth]
86
+ * [OAuth]
79
87
 
80
88
  ### Deprecated APIs
81
89
  * [V1 Employees]
@@ -322,8 +330,10 @@ You can also use the Square API to create applications or services that work wit
322
330
  [Refunds]: doc/api/refunds.md
323
331
  [Subscriptions]: doc/api/subscriptions.md
324
332
  [Mobile Authorization]: doc/api/mobile-authorization.md
325
- [O Auth]: doc/api/o-auth.md
333
+ [OAuth]: doc/api/o-auth.md
326
334
  [V1 Employees]: doc/api/v1-employees.md
327
335
  [V1 Transactions]: doc/api/v1-transactions.md
328
336
  [V1 Items]: doc/api/v1-items.md
329
337
  [Transactions]: doc/api/transactions.md
338
+ [Sites]: doc/api/sites.md
339
+ [Snippets]: doc/api/snippets.md
data/lib/square.rb CHANGED
@@ -9,6 +9,7 @@ require_relative 'square/client.rb'
9
9
 
10
10
  # Utilities
11
11
  require_relative 'square/utilities/file_wrapper.rb'
12
+ require_relative 'square/utilities/date_time_helper.rb'
12
13
 
13
14
  # Http
14
15
  require_relative 'square/http/api_response.rb'
@@ -36,6 +37,7 @@ require_relative 'square/api/v1_transactions_api.rb'
36
37
  require_relative 'square/api/apple_pay_api.rb'
37
38
  require_relative 'square/api/bank_accounts_api.rb'
38
39
  require_relative 'square/api/bookings_api.rb'
40
+ require_relative 'square/api/cards_api.rb'
39
41
  require_relative 'square/api/cash_drawers_api.rb'
40
42
  require_relative 'square/api/catalog_api.rb'
41
43
  require_relative 'square/api/customers_api.rb'
@@ -44,6 +46,8 @@ require_relative 'square/api/customer_segments_api.rb'
44
46
  require_relative 'square/api/devices_api.rb'
45
47
  require_relative 'square/api/disputes_api.rb'
46
48
  require_relative 'square/api/employees_api.rb'
49
+ require_relative 'square/api/gift_cards_api.rb'
50
+ require_relative 'square/api/gift_card_activities_api.rb'
47
51
  require_relative 'square/api/inventory_api.rb'
48
52
  require_relative 'square/api/invoices_api.rb'
49
53
  require_relative 'square/api/labor_api.rb'
@@ -55,6 +59,8 @@ require_relative 'square/api/merchants_api.rb'
55
59
  require_relative 'square/api/orders_api.rb'
56
60
  require_relative 'square/api/payments_api.rb'
57
61
  require_relative 'square/api/refunds_api.rb'
62
+ require_relative 'square/api/sites_api.rb'
63
+ require_relative 'square/api/snippets_api.rb'
58
64
  require_relative 'square/api/subscriptions_api.rb'
59
65
  require_relative 'square/api/team_api.rb'
60
66
  require_relative 'square/api/terminal_api.rb'
@@ -8,21 +8,19 @@ module Square
8
8
  @http_call_back = http_call_back
9
9
 
10
10
  @global_headers = {
11
- 'user-agent' => 'Square-Ruby-SDK/10.0.0.202104217',
11
+ 'user-agent' => 'Square-Ruby-SDK/13.1.0.20210818',
12
12
  'Square-Version' => config.square_version
13
13
  }
14
14
  end
15
15
 
16
16
  def validate_parameters(args)
17
17
  args.each do |_name, value|
18
- if value.nil?
19
- raise ArgumentError, "Required parameter #{_name} cannot be nil."
20
- end
18
+ raise ArgumentError, "Required parameter #{_name} cannot be nil." if value.nil?
21
19
  end
22
20
  end
23
21
 
24
22
  def execute_request(request, binary: false)
25
- @http_call_back.on_before_request(request) if @http_call_back
23
+ @http_call_back&.on_before_request(request)
26
24
 
27
25
  APIHelper.clean_hash(request.headers)
28
26
  request.headers.merge!(@global_headers)
@@ -35,7 +33,7 @@ module Square
35
33
  else
36
34
  config.http_client.execute_as_string(request)
37
35
  end
38
- @http_call_back.on_after_response(response) if @http_call_back
36
+ @http_call_back&.on_after_response(response)
39
37
 
40
38
  response
41
39
  end
@@ -0,0 +1,170 @@
1
+ module Square
2
+ # CardsApi
3
+ class CardsApi < BaseApi
4
+ def initialize(config, http_call_back: nil)
5
+ super(config, http_call_back: http_call_back)
6
+ end
7
+
8
+ # Retrieves a list of cards owned by the account making the request.
9
+ # A max of 25 cards will be returned.
10
+ # @param [String] cursor Optional parameter: A pagination cursor returned by
11
+ # a previous call to this endpoint. Provide this to retrieve the next set of
12
+ # results for your original query. See
13
+ # [Pagination](https://developer.squareup.com/docs/basics/api101/pagination)
14
+ # for more information.
15
+ # @param [String] customer_id Optional parameter: Limit results to cards
16
+ # associated with the customer supplied. By default, all cards owned by the
17
+ # merchant are returned.
18
+ # @param [Boolean] include_disabled Optional parameter: Includes disabled
19
+ # cards. By default, all enabled cards owned by the merchant are returned.
20
+ # @param [String] reference_id Optional parameter: Limit results to cards
21
+ # associated with the reference_id supplied.
22
+ # @param [SortOrder] sort_order Optional parameter: Sorts the returned list
23
+ # by when the card was created with the specified order. This field defaults
24
+ # to ASC.
25
+ # @return [ListCardsResponse Hash] response from the API call
26
+ def list_cards(cursor: nil,
27
+ customer_id: nil,
28
+ include_disabled: false,
29
+ reference_id: nil,
30
+ sort_order: nil)
31
+ # Prepare query url.
32
+ _query_builder = config.get_base_uri
33
+ _query_builder << '/v2/cards'
34
+ _query_builder = APIHelper.append_url_with_query_parameters(
35
+ _query_builder,
36
+ 'cursor' => cursor,
37
+ 'customer_id' => customer_id,
38
+ 'include_disabled' => include_disabled,
39
+ 'reference_id' => reference_id,
40
+ 'sort_order' => sort_order
41
+ )
42
+ _query_url = APIHelper.clean_url _query_builder
43
+
44
+ # Prepare headers.
45
+ _headers = {
46
+ 'accept' => 'application/json'
47
+ }
48
+
49
+ # Prepare and execute HttpRequest.
50
+ _request = config.http_client.get(
51
+ _query_url,
52
+ headers: _headers
53
+ )
54
+ OAuth2.apply(config, _request)
55
+ _response = execute_request(_request)
56
+
57
+ # Return appropriate response type.
58
+ decoded = APIHelper.json_deserialize(_response.raw_body)
59
+ _errors = APIHelper.map_response(decoded, ['errors'])
60
+ ApiResponse.new(
61
+ _response, data: decoded, errors: _errors
62
+ )
63
+ end
64
+
65
+ # Adds a card on file to an existing merchant.
66
+ # @param [CreateCardRequest] body Required parameter: An object containing
67
+ # the fields to POST for the request. See the corresponding object
68
+ # definition for field details.
69
+ # @return [CreateCardResponse Hash] response from the API call
70
+ def create_card(body:)
71
+ # Prepare query url.
72
+ _query_builder = config.get_base_uri
73
+ _query_builder << '/v2/cards'
74
+ _query_url = APIHelper.clean_url _query_builder
75
+
76
+ # Prepare headers.
77
+ _headers = {
78
+ 'accept' => 'application/json',
79
+ 'content-type' => 'application/json; charset=utf-8'
80
+ }
81
+
82
+ # Prepare and execute HttpRequest.
83
+ _request = config.http_client.post(
84
+ _query_url,
85
+ headers: _headers,
86
+ parameters: body.to_json
87
+ )
88
+ OAuth2.apply(config, _request)
89
+ _response = execute_request(_request)
90
+
91
+ # Return appropriate response type.
92
+ decoded = APIHelper.json_deserialize(_response.raw_body)
93
+ _errors = APIHelper.map_response(decoded, ['errors'])
94
+ ApiResponse.new(
95
+ _response, data: decoded, errors: _errors
96
+ )
97
+ end
98
+
99
+ # Retrieves details for a specific Card.
100
+ # @param [String] card_id Required parameter: Unique ID for the desired
101
+ # Card.
102
+ # @return [RetrieveCardResponse Hash] response from the API call
103
+ def retrieve_card(card_id:)
104
+ # Prepare query url.
105
+ _query_builder = config.get_base_uri
106
+ _query_builder << '/v2/cards/{card_id}'
107
+ _query_builder = APIHelper.append_url_with_template_parameters(
108
+ _query_builder,
109
+ 'card_id' => { 'value' => card_id, 'encode' => true }
110
+ )
111
+ _query_url = APIHelper.clean_url _query_builder
112
+
113
+ # Prepare headers.
114
+ _headers = {
115
+ 'accept' => 'application/json'
116
+ }
117
+
118
+ # Prepare and execute HttpRequest.
119
+ _request = config.http_client.get(
120
+ _query_url,
121
+ headers: _headers
122
+ )
123
+ OAuth2.apply(config, _request)
124
+ _response = execute_request(_request)
125
+
126
+ # Return appropriate response type.
127
+ decoded = APIHelper.json_deserialize(_response.raw_body)
128
+ _errors = APIHelper.map_response(decoded, ['errors'])
129
+ ApiResponse.new(
130
+ _response, data: decoded, errors: _errors
131
+ )
132
+ end
133
+
134
+ # Disables the card, preventing any further updates or charges.
135
+ # Disabling an already disabled card is allowed but has no effect.
136
+ # @param [String] card_id Required parameter: Unique ID for the desired
137
+ # Card.
138
+ # @return [DisableCardResponse Hash] response from the API call
139
+ def disable_card(card_id:)
140
+ # Prepare query url.
141
+ _query_builder = config.get_base_uri
142
+ _query_builder << '/v2/cards/{card_id}/disable'
143
+ _query_builder = APIHelper.append_url_with_template_parameters(
144
+ _query_builder,
145
+ 'card_id' => { 'value' => card_id, 'encode' => true }
146
+ )
147
+ _query_url = APIHelper.clean_url _query_builder
148
+
149
+ # Prepare headers.
150
+ _headers = {
151
+ 'accept' => 'application/json'
152
+ }
153
+
154
+ # Prepare and execute HttpRequest.
155
+ _request = config.http_client.post(
156
+ _query_url,
157
+ headers: _headers
158
+ )
159
+ OAuth2.apply(config, _request)
160
+ _response = execute_request(_request)
161
+
162
+ # Return appropriate response type.
163
+ decoded = APIHelper.json_deserialize(_response.raw_body)
164
+ _errors = APIHelper.map_response(decoded, ['errors'])
165
+ ApiResponse.new(
166
+ _response, data: decoded, errors: _errors
167
+ )
168
+ end
169
+ end
170
+ end
@@ -241,14 +241,17 @@ module Square
241
241
  # [SearchCatalogObjects]($e/Catalog/SearchCatalogObjects)
242
242
  # and set the `include_deleted_objects` attribute value to `true`.
243
243
  # @param [String] cursor Optional parameter: The pagination cursor returned
244
- # in the previous response. Leave unset for an initial request. See
244
+ # in the previous response. Leave unset for an initial request. The page
245
+ # size is currently set to be 100. See
245
246
  # [Pagination](https://developer.squareup.com/docs/basics/api101/pagination)
246
247
  # for more information.
247
248
  # @param [String] types Optional parameter: An optional case-insensitive,
248
- # comma-separated list of object types to retrieve, for example
249
- # `ITEM,ITEM_VARIATION,CATEGORY,IMAGE`. The legal values are taken from the
250
- # CatalogObjectType enum: `ITEM`, `ITEM_VARIATION`, `CATEGORY`, `DISCOUNT`,
251
- # `TAX`, `MODIFIER`, `MODIFIER_LIST`, or `IMAGE`.
249
+ # comma-separated list of object types to retrieve. The valid values are
250
+ # defined in the [CatalogObjectType]($m/CatalogObjectType) enum, including
251
+ # `ITEM`, `ITEM_VARIATION`, `CATEGORY`, `DISCOUNT`, `TAX`, `MODIFIER`,
252
+ # `MODIFIER_LIST`, or `IMAGE`. If this is unspecified, the operation
253
+ # returns objects of all the types at the version of the Square API used to
254
+ # make the request.
252
255
  # @param [Long] catalog_version Optional parameter: The specific version of
253
256
  # the catalog objects to be included in the response. This allows you to
254
257
  # retrieve historical versions of objects. The specified version value is
@@ -11,14 +11,22 @@ module Square
11
11
  # set of results for your original query. For more information, see
12
12
  # [Pagination](https://developer.squareup.com/docs/working-with-apis/paginat
13
13
  # ion).
14
+ # @param [Integer] limit Optional parameter: The maximum number of results
15
+ # to return in a single page. This limit is advisory. The response might
16
+ # contain more or fewer results. The limit is ignored if it is less than 1
17
+ # or greater than 50. The default value is 50. For more information, see
18
+ # [Pagination](https://developer.squareup.com/docs/working-with-apis/paginat
19
+ # ion).
14
20
  # @return [ListCustomerGroupsResponse Hash] response from the API call
15
- def list_customer_groups(cursor: nil)
21
+ def list_customer_groups(cursor: nil,
22
+ limit: nil)
16
23
  # Prepare query url.
17
24
  _query_builder = config.get_base_uri
18
25
  _query_builder << '/v2/customers/groups'
19
26
  _query_builder = APIHelper.append_url_with_query_parameters(
20
27
  _query_builder,
21
- 'cursor' => cursor
28
+ 'cursor' => cursor,
29
+ 'limit' => limit
22
30
  )
23
31
  _query_url = APIHelper.clean_url _query_builder
24
32
 
@@ -11,14 +11,22 @@ module Square
11
11
  # the next set of query results. For more information, see
12
12
  # [Pagination](https://developer.squareup.com/docs/working-with-apis/paginat
13
13
  # ion).
14
+ # @param [Integer] limit Optional parameter: The maximum number of results
15
+ # to return in a single page. This limit is advisory. The response might
16
+ # contain more or fewer results. The limit is ignored if it is less than 1
17
+ # or greater than 50. The default value is 50. For more information, see
18
+ # [Pagination](https://developer.squareup.com/docs/working-with-apis/paginat
19
+ # ion).
14
20
  # @return [ListCustomerSegmentsResponse Hash] response from the API call
15
- def list_customer_segments(cursor: nil)
21
+ def list_customer_segments(cursor: nil,
22
+ limit: nil)
16
23
  # Prepare query url.
17
24
  _query_builder = config.get_base_uri
18
25
  _query_builder << '/v2/customers/segments'
19
26
  _query_builder = APIHelper.append_url_with_query_parameters(
20
27
  _query_builder,
21
- 'cursor' => cursor
28
+ 'cursor' => cursor,
29
+ 'limit' => limit
22
30
  )
23
31
  _query_url = APIHelper.clean_url _query_builder
24
32
 
@@ -17,13 +17,20 @@ module Square
17
17
  # set of results for your original query. For more information, see
18
18
  # [Pagination](https://developer.squareup.com/docs/working-with-apis/paginat
19
19
  # ion).
20
+ # @param [Integer] limit Optional parameter: The maximum number of results
21
+ # to return in a single page. This limit is advisory. The response might
22
+ # contain more or fewer results. The limit is ignored if it is less than 1
23
+ # or greater than 100. The default value is 100. For more information, see
24
+ # [Pagination](https://developer.squareup.com/docs/working-with-apis/paginat
25
+ # ion).
20
26
  # @param [CustomerSortField] sort_field Optional parameter: Indicates how
21
- # customers should be sorted. Default: `DEFAULT`.
27
+ # customers should be sorted. The default value is `DEFAULT`.
22
28
  # @param [SortOrder] sort_order Optional parameter: Indicates whether
23
29
  # customers should be sorted in ascending (`ASC`) or descending (`DESC`)
24
- # order. Default: `ASC`.
30
+ # order. The default value is `ASC`.
25
31
  # @return [ListCustomersResponse Hash] response from the API call
26
32
  def list_customers(cursor: nil,
33
+ limit: nil,
27
34
  sort_field: nil,
28
35
  sort_order: nil)
29
36
  # Prepare query url.
@@ -32,6 +39,7 @@ module Square
32
39
  _query_builder = APIHelper.append_url_with_query_parameters(
33
40
  _query_builder,
34
41
  'cursor' => cursor,
42
+ 'limit' => limit,
35
43
  'sort_field' => sort_field,
36
44
  'sort_order' => sort_order
37
45
  )
@@ -58,8 +66,7 @@ module Square
58
66
  )
59
67
  end
60
68
 
61
- # Creates a new customer for a business, which can have associated cards on
62
- # file.
69
+ # Creates a new customer for a business.
63
70
  # You must provide at least one of the following values in your request to
64
71
  # this
65
72
  # endpoint:
@@ -145,8 +152,8 @@ module Square
145
152
  )
146
153
  end
147
154
 
148
- # Deletes a customer profile from a business, including any linked cards on
149
- # file.
155
+ # Deletes a customer profile from a business. This operation also unlinks
156
+ # any associated cards on file.
150
157
  # As a best practice, you should include the `version` field in the request
151
158
  # to enable [optimistic
152
159
  # concurrency](https://developer.squareup.com/docs/working-with-apis/optimis
@@ -157,7 +164,7 @@ module Square
157
164
  # @param [String] customer_id Required parameter: The ID of the customer to
158
165
  # delete.
159
166
  # @param [Long] version Optional parameter: The current version of the
160
- # customer profile. As a best practice, you should include this parameter
167
+ # customer profile. As a best practice, you should include this parameter
161
168
  # to enable [optimistic
162
169
  # concurrency](https://developer.squareup.com/docs/working-with-apis/optimis
163
170
  # tic-concurrency) control. For more information, see [Delete a customer
@@ -245,11 +252,8 @@ module Square
245
252
  # the customer profile.
246
253
  # To update a customer profile that was created by merging existing
247
254
  # profiles, you must use the ID of the newly created profile.
248
- # You cannot use this endpoint to change cards on file. To change a card on
249
- # file, call [DeleteCustomerCard]($e/Customers/DeleteCustomerCard) to delete
250
- # the existing card and then call
251
- # [CreateCustomerCard]($e/Customers/CreateCustomerCard) to create a new
252
- # card.
255
+ # You cannot use this endpoint to change cards on file. To make changes, use
256
+ # the [Cards API]($e/Cards) or [Gift Cards API]($e/GiftCards).
253
257
  # @param [String] customer_id Required parameter: The ID of the customer to
254
258
  # update.
255
259
  # @param [UpdateCustomerRequest] body Required parameter: An object
@@ -303,6 +307,7 @@ module Square
303
307
  # @return [CreateCustomerCardResponse Hash] response from the API call
304
308
  def create_customer_card(customer_id:,
305
309
  body:)
310
+ warn 'Endpoint create_customer_card in CustomersApi is deprecated'
306
311
  # Prepare query url.
307
312
  _query_builder = config.get_base_uri
308
313
  _query_builder << '/v2/customers/{customer_id}/cards'
@@ -343,6 +348,7 @@ module Square
343
348
  # @return [DeleteCustomerCardResponse Hash] response from the API call
344
349
  def delete_customer_card(customer_id:,
345
350
  card_id:)
351
+ warn 'Endpoint delete_customer_card in CustomersApi is deprecated'
346
352
  # Prepare query url.
347
353
  _query_builder = config.get_base_uri
348
354
  _query_builder << '/v2/customers/{customer_id}/cards/{card_id}'