square.rb 8.0.0.20201216 → 26.1.0.20230119

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.md +79 -221
  4. data/lib/square/api/apple_pay_api.rb +15 -8
  5. data/lib/square/api/bank_accounts_api.rb +5 -5
  6. data/lib/square/api/base_api.rb +27 -9
  7. data/lib/square/api/booking_custom_attributes_api.rb +555 -0
  8. data/lib/square/api/bookings_api.rb +107 -15
  9. data/lib/square/api/cards_api.rb +171 -0
  10. data/lib/square/api/cash_drawers_api.rb +2 -2
  11. data/lib/square/api/catalog_api.rb +167 -73
  12. data/lib/square/api/checkout_api.rb +205 -3
  13. data/lib/square/api/customer_custom_attributes_api.rb +561 -0
  14. data/lib/square/api/customer_groups_api.rb +17 -8
  15. data/lib/square/api/customer_segments_api.rb +15 -6
  16. data/lib/square/api/customers_api.rb +67 -33
  17. data/lib/square/api/devices_api.rb +3 -2
  18. data/lib/square/api/disputes_api.rb +109 -105
  19. data/lib/square/api/gift_card_activities_api.rb +132 -0
  20. data/lib/square/api/gift_cards_api.rb +298 -0
  21. data/lib/square/api/inventory_api.rb +263 -24
  22. data/lib/square/api/invoices_api.rb +21 -21
  23. data/lib/square/api/labor_api.rb +70 -68
  24. data/lib/square/api/location_custom_attributes_api.rb +584 -0
  25. data/lib/square/api/locations_api.rb +21 -14
  26. data/lib/square/api/loyalty_api.rb +333 -50
  27. data/lib/square/api/merchants_api.rb +11 -9
  28. data/lib/square/api/mobile_authorization_api.rb +4 -4
  29. data/lib/square/api/o_auth_api.rb +78 -25
  30. data/lib/square/api/order_custom_attributes_api.rb +601 -0
  31. data/lib/square/api/orders_api.rb +84 -45
  32. data/lib/square/api/payments_api.rb +72 -24
  33. data/lib/square/api/payouts_api.rb +173 -0
  34. data/lib/square/api/refunds_api.rb +18 -7
  35. data/lib/square/api/sites_api.rb +43 -0
  36. data/lib/square/api/snippets_api.rb +146 -0
  37. data/lib/square/api/subscriptions_api.rb +190 -15
  38. data/lib/square/api/team_api.rb +46 -46
  39. data/lib/square/api/terminal_api.rb +172 -22
  40. data/lib/square/api/transactions_api.rb +15 -191
  41. data/lib/square/api/v1_transactions_api.rb +52 -124
  42. data/lib/square/api/vendors_api.rb +257 -0
  43. data/lib/square/api/webhook_subscriptions_api.rb +327 -0
  44. data/lib/square/api_helper.rb +217 -57
  45. data/lib/square/client.rb +90 -18
  46. data/lib/square/configuration.rb +64 -20
  47. data/lib/square/exceptions/validation_exception.rb +13 -0
  48. data/lib/square/http/api_response.rb +7 -9
  49. data/lib/square/http/faraday_client.rb +40 -9
  50. data/lib/square/http/http_client.rb +31 -12
  51. data/lib/square/http/http_request.rb +6 -2
  52. data/lib/square/utilities/date_time_helper.rb +151 -0
  53. data/lib/square/utilities/file_wrapper.rb +1 -2
  54. data/lib/square.rb +56 -44
  55. data/test/api/test_locations_api.rb +2 -5
  56. data/test/test_helper.rb +2 -2
  57. metadata +83 -15
  58. data/lib/square/api/v1_employees_api.rb +0 -751
  59. data/lib/square/api/v1_items_api.rb +0 -1766
@@ -0,0 +1,132 @@
1
+ module Square
2
+ # GiftCardActivitiesApi
3
+ class GiftCardActivitiesApi < BaseApi
4
+ def initialize(config, http_call_back: nil)
5
+ super(config, http_call_back: http_call_back)
6
+ end
7
+
8
+ # Lists gift card activities. By default, you get gift card activities for
9
+ # all
10
+ # gift cards in the seller's account. You can optionally specify query
11
+ # parameters to
12
+ # filter the list. For example, you can get a list of gift card activities
13
+ # for a gift card,
14
+ # for all gift cards in a specific region, or for activities within a time
15
+ # window.
16
+ # @param [String] gift_card_id Optional parameter: If a gift card ID is
17
+ # provided, the endpoint returns activities related to the specified gift
18
+ # card. Otherwise, the endpoint returns all gift card activities for the
19
+ # seller.
20
+ # @param [String] type Optional parameter: If a
21
+ # [type]($m/GiftCardActivityType) is provided, the endpoint returns gift
22
+ # card activities of the specified type. Otherwise, the endpoint returns
23
+ # all types of gift card activities.
24
+ # @param [String] location_id Optional parameter: If a location ID is
25
+ # provided, the endpoint returns gift card activities for the specified
26
+ # location. Otherwise, the endpoint returns gift card activities for all
27
+ # locations.
28
+ # @param [String] begin_time Optional parameter: The timestamp for the
29
+ # beginning of the reporting period, in RFC 3339 format. This start time is
30
+ # inclusive. The default value is the current time minus one year.
31
+ # @param [String] end_time Optional parameter: The timestamp for the end of
32
+ # the reporting period, in RFC 3339 format. This end time is inclusive. The
33
+ # default value is the current time.
34
+ # @param [Integer] limit Optional parameter: If a limit is provided, the
35
+ # endpoint returns the specified number of results (or fewer) per page. The
36
+ # maximum value is 100. The default value is 50. For more information, see
37
+ # [Pagination](https://developer.squareup.com/docs/working-with-apis/paginat
38
+ # ion).
39
+ # @param [String] cursor Optional parameter: A pagination cursor returned by
40
+ # a previous call to this endpoint. Provide this cursor to retrieve the next
41
+ # set of results for the original query. If a cursor is not provided, the
42
+ # endpoint returns the first page of the results. For more information, see
43
+ # [Pagination](https://developer.squareup.com/docs/working-with-apis/paginat
44
+ # ion).
45
+ # @param [String] sort_order Optional parameter: The order in which the
46
+ # endpoint returns the activities, based on `created_at`. - `ASC` - Oldest
47
+ # to newest. - `DESC` - Newest to oldest (default).
48
+ # @return [ListGiftCardActivitiesResponse Hash] response from the API call
49
+ def list_gift_card_activities(gift_card_id: nil,
50
+ type: nil,
51
+ location_id: nil,
52
+ begin_time: nil,
53
+ end_time: nil,
54
+ limit: nil,
55
+ cursor: nil,
56
+ sort_order: nil)
57
+ # Prepare query url.
58
+ _query_builder = config.get_base_uri
59
+ _query_builder << '/v2/gift-cards/activities'
60
+ _query_builder = APIHelper.append_url_with_query_parameters(
61
+ _query_builder,
62
+ 'gift_card_id' => gift_card_id,
63
+ 'type' => type,
64
+ 'location_id' => location_id,
65
+ 'begin_time' => begin_time,
66
+ 'end_time' => end_time,
67
+ 'limit' => limit,
68
+ 'cursor' => cursor,
69
+ 'sort_order' => sort_order
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
+ # Creates a gift card activity to manage the balance or state of a [gift
95
+ # card]($m/GiftCard).
96
+ # For example, you create an `ACTIVATE` activity to activate a gift card
97
+ # with an initial balance
98
+ # before the gift card can be used.
99
+ # @param [CreateGiftCardActivityRequest] body Required parameter: An object
100
+ # containing the fields to POST for the request. See the corresponding
101
+ # object definition for field details.
102
+ # @return [CreateGiftCardActivityResponse Hash] response from the API call
103
+ def create_gift_card_activity(body:)
104
+ # Prepare query url.
105
+ _query_builder = config.get_base_uri
106
+ _query_builder << '/v2/gift-cards/activities'
107
+ _query_url = APIHelper.clean_url _query_builder
108
+
109
+ # Prepare headers.
110
+ _headers = {
111
+ 'accept' => 'application/json',
112
+ 'Content-Type' => 'application/json'
113
+ }
114
+
115
+ # Prepare and execute HttpRequest.
116
+ _request = config.http_client.post(
117
+ _query_url,
118
+ headers: _headers,
119
+ parameters: body.to_json
120
+ )
121
+ OAuth2.apply(config, _request)
122
+ _response = execute_request(_request)
123
+
124
+ # Return appropriate response type.
125
+ decoded = APIHelper.json_deserialize(_response.raw_body)
126
+ _errors = APIHelper.map_response(decoded, ['errors'])
127
+ ApiResponse.new(
128
+ _response, data: decoded, errors: _errors
129
+ )
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,298 @@
1
+ module Square
2
+ # GiftCardsApi
3
+ class GiftCardsApi < BaseApi
4
+ def initialize(config, http_call_back: nil)
5
+ super(config, http_call_back: http_call_back)
6
+ end
7
+
8
+ # Lists all gift cards. You can specify optional filters to retrieve
9
+ # a subset of the gift cards. Results are sorted by `created_at` in
10
+ # ascending order.
11
+ # @param [String] type Optional parameter: If a [type]($m/GiftCardType) is
12
+ # provided, the endpoint returns gift cards of the specified type.
13
+ # Otherwise, the endpoint returns gift cards of all types.
14
+ # @param [String] state Optional parameter: If a [state]($m/GiftCardStatus)
15
+ # is provided, the endpoint returns the gift cards in the specified state.
16
+ # Otherwise, the endpoint returns the gift cards of all states.
17
+ # @param [Integer] limit Optional parameter: If a limit is provided, the
18
+ # endpoint returns only the specified number of results per page. The
19
+ # maximum value is 50. The default value is 30. For more information, see
20
+ # [Pagination](https://developer.squareup.com/docs/working-with-apis/paginat
21
+ # ion).
22
+ # @param [String] cursor Optional parameter: A pagination cursor returned by
23
+ # a previous call to this endpoint. Provide this cursor to retrieve the next
24
+ # set of results for the original query. If a cursor is not provided, the
25
+ # endpoint returns the first page of the results. For more information, see
26
+ # [Pagination](https://developer.squareup.com/docs/working-with-apis/paginat
27
+ # ion).
28
+ # @param [String] customer_id Optional parameter: If a customer ID is
29
+ # provided, the endpoint returns only the gift cards linked to the specified
30
+ # customer.
31
+ # @return [ListGiftCardsResponse Hash] response from the API call
32
+ def list_gift_cards(type: nil,
33
+ state: nil,
34
+ limit: nil,
35
+ cursor: nil,
36
+ customer_id: nil)
37
+ # Prepare query url.
38
+ _query_builder = config.get_base_uri
39
+ _query_builder << '/v2/gift-cards'
40
+ _query_builder = APIHelper.append_url_with_query_parameters(
41
+ _query_builder,
42
+ 'type' => type,
43
+ 'state' => state,
44
+ 'limit' => limit,
45
+ 'cursor' => cursor,
46
+ 'customer_id' => customer_id
47
+ )
48
+ _query_url = APIHelper.clean_url _query_builder
49
+
50
+ # Prepare headers.
51
+ _headers = {
52
+ 'accept' => 'application/json'
53
+ }
54
+
55
+ # Prepare and execute HttpRequest.
56
+ _request = config.http_client.get(
57
+ _query_url,
58
+ headers: _headers
59
+ )
60
+ OAuth2.apply(config, _request)
61
+ _response = execute_request(_request)
62
+
63
+ # Return appropriate response type.
64
+ decoded = APIHelper.json_deserialize(_response.raw_body)
65
+ _errors = APIHelper.map_response(decoded, ['errors'])
66
+ ApiResponse.new(
67
+ _response, data: decoded, errors: _errors
68
+ )
69
+ end
70
+
71
+ # Creates a digital gift card or registers a physical (plastic) gift card.
72
+ # After the gift card
73
+ # is created, you must call
74
+ # [CreateGiftCardActivity]($e/GiftCardActivities/CreateGiftCardActivity)
75
+ # to activate the card with an initial balance before it can be used for
76
+ # payment.
77
+ # @param [CreateGiftCardRequest] body Required parameter: An object
78
+ # containing the fields to POST for the request. See the corresponding
79
+ # object definition for field details.
80
+ # @return [CreateGiftCardResponse Hash] response from the API call
81
+ def create_gift_card(body:)
82
+ # Prepare query url.
83
+ _query_builder = config.get_base_uri
84
+ _query_builder << '/v2/gift-cards'
85
+ _query_url = APIHelper.clean_url _query_builder
86
+
87
+ # Prepare headers.
88
+ _headers = {
89
+ 'accept' => 'application/json',
90
+ 'Content-Type' => 'application/json'
91
+ }
92
+
93
+ # Prepare and execute HttpRequest.
94
+ _request = config.http_client.post(
95
+ _query_url,
96
+ headers: _headers,
97
+ parameters: body.to_json
98
+ )
99
+ OAuth2.apply(config, _request)
100
+ _response = execute_request(_request)
101
+
102
+ # Return appropriate response type.
103
+ decoded = APIHelper.json_deserialize(_response.raw_body)
104
+ _errors = APIHelper.map_response(decoded, ['errors'])
105
+ ApiResponse.new(
106
+ _response, data: decoded, errors: _errors
107
+ )
108
+ end
109
+
110
+ # Retrieves a gift card using the gift card account number (GAN).
111
+ # @param [RetrieveGiftCardFromGANRequest] body Required parameter: An object
112
+ # containing the fields to POST for the request. See the corresponding
113
+ # object definition for field details.
114
+ # @return [RetrieveGiftCardFromGANResponse Hash] response from the API call
115
+ def retrieve_gift_card_from_gan(body:)
116
+ # Prepare query url.
117
+ _query_builder = config.get_base_uri
118
+ _query_builder << '/v2/gift-cards/from-gan'
119
+ _query_url = APIHelper.clean_url _query_builder
120
+
121
+ # Prepare headers.
122
+ _headers = {
123
+ 'accept' => 'application/json',
124
+ 'Content-Type' => 'application/json'
125
+ }
126
+
127
+ # Prepare and execute HttpRequest.
128
+ _request = config.http_client.post(
129
+ _query_url,
130
+ headers: _headers,
131
+ parameters: body.to_json
132
+ )
133
+ OAuth2.apply(config, _request)
134
+ _response = execute_request(_request)
135
+
136
+ # Return appropriate response type.
137
+ decoded = APIHelper.json_deserialize(_response.raw_body)
138
+ _errors = APIHelper.map_response(decoded, ['errors'])
139
+ ApiResponse.new(
140
+ _response, data: decoded, errors: _errors
141
+ )
142
+ end
143
+
144
+ # Retrieves a gift card using a secure payment token that represents the
145
+ # gift card.
146
+ # @param [RetrieveGiftCardFromNonceRequest] body Required parameter: An
147
+ # object containing the fields to POST for the request. See the
148
+ # corresponding object definition for field details.
149
+ # @return [RetrieveGiftCardFromNonceResponse Hash] response from the API call
150
+ def retrieve_gift_card_from_nonce(body:)
151
+ # Prepare query url.
152
+ _query_builder = config.get_base_uri
153
+ _query_builder << '/v2/gift-cards/from-nonce'
154
+ _query_url = APIHelper.clean_url _query_builder
155
+
156
+ # Prepare headers.
157
+ _headers = {
158
+ 'accept' => 'application/json',
159
+ 'Content-Type' => 'application/json'
160
+ }
161
+
162
+ # Prepare and execute HttpRequest.
163
+ _request = config.http_client.post(
164
+ _query_url,
165
+ headers: _headers,
166
+ parameters: body.to_json
167
+ )
168
+ OAuth2.apply(config, _request)
169
+ _response = execute_request(_request)
170
+
171
+ # Return appropriate response type.
172
+ decoded = APIHelper.json_deserialize(_response.raw_body)
173
+ _errors = APIHelper.map_response(decoded, ['errors'])
174
+ ApiResponse.new(
175
+ _response, data: decoded, errors: _errors
176
+ )
177
+ end
178
+
179
+ # Links a customer to a gift card, which is also referred to as adding a
180
+ # card on file.
181
+ # @param [String] gift_card_id Required parameter: The ID of the gift card
182
+ # to be linked.
183
+ # @param [LinkCustomerToGiftCardRequest] body Required parameter: An object
184
+ # containing the fields to POST for the request. See the corresponding
185
+ # object definition for field details.
186
+ # @return [LinkCustomerToGiftCardResponse Hash] response from the API call
187
+ def link_customer_to_gift_card(gift_card_id:,
188
+ body:)
189
+ # Prepare query url.
190
+ _query_builder = config.get_base_uri
191
+ _query_builder << '/v2/gift-cards/{gift_card_id}/link-customer'
192
+ _query_builder = APIHelper.append_url_with_template_parameters(
193
+ _query_builder,
194
+ 'gift_card_id' => { 'value' => gift_card_id, 'encode' => true }
195
+ )
196
+ _query_url = APIHelper.clean_url _query_builder
197
+
198
+ # Prepare headers.
199
+ _headers = {
200
+ 'accept' => 'application/json',
201
+ 'Content-Type' => 'application/json'
202
+ }
203
+
204
+ # Prepare and execute HttpRequest.
205
+ _request = config.http_client.post(
206
+ _query_url,
207
+ headers: _headers,
208
+ parameters: body.to_json
209
+ )
210
+ OAuth2.apply(config, _request)
211
+ _response = execute_request(_request)
212
+
213
+ # Return appropriate response type.
214
+ decoded = APIHelper.json_deserialize(_response.raw_body)
215
+ _errors = APIHelper.map_response(decoded, ['errors'])
216
+ ApiResponse.new(
217
+ _response, data: decoded, errors: _errors
218
+ )
219
+ end
220
+
221
+ # Unlinks a customer from a gift card, which is also referred to as removing
222
+ # a card on file.
223
+ # @param [String] gift_card_id Required parameter: The ID of the gift card
224
+ # to be unlinked.
225
+ # @param [UnlinkCustomerFromGiftCardRequest] body Required parameter: An
226
+ # object containing the fields to POST for the request. See the
227
+ # corresponding object definition for field details.
228
+ # @return [UnlinkCustomerFromGiftCardResponse Hash] response from the API call
229
+ def unlink_customer_from_gift_card(gift_card_id:,
230
+ body:)
231
+ # Prepare query url.
232
+ _query_builder = config.get_base_uri
233
+ _query_builder << '/v2/gift-cards/{gift_card_id}/unlink-customer'
234
+ _query_builder = APIHelper.append_url_with_template_parameters(
235
+ _query_builder,
236
+ 'gift_card_id' => { 'value' => gift_card_id, 'encode' => true }
237
+ )
238
+ _query_url = APIHelper.clean_url _query_builder
239
+
240
+ # Prepare headers.
241
+ _headers = {
242
+ 'accept' => 'application/json',
243
+ 'Content-Type' => 'application/json'
244
+ }
245
+
246
+ # Prepare and execute HttpRequest.
247
+ _request = config.http_client.post(
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(
259
+ _response, data: decoded, errors: _errors
260
+ )
261
+ end
262
+
263
+ # Retrieves a gift card using the gift card ID.
264
+ # @param [String] id Required parameter: The ID of the gift card to
265
+ # retrieve.
266
+ # @return [RetrieveGiftCardResponse Hash] response from the API call
267
+ def retrieve_gift_card(id:)
268
+ # Prepare query url.
269
+ _query_builder = config.get_base_uri
270
+ _query_builder << '/v2/gift-cards/{id}'
271
+ _query_builder = APIHelper.append_url_with_template_parameters(
272
+ _query_builder,
273
+ 'id' => { 'value' => id, 'encode' => true }
274
+ )
275
+ _query_url = APIHelper.clean_url _query_builder
276
+
277
+ # Prepare headers.
278
+ _headers = {
279
+ 'accept' => 'application/json'
280
+ }
281
+
282
+ # Prepare and execute HttpRequest.
283
+ _request = config.http_client.get(
284
+ _query_url,
285
+ headers: _headers
286
+ )
287
+ OAuth2.apply(config, _request)
288
+ _response = execute_request(_request)
289
+
290
+ # Return appropriate response type.
291
+ decoded = APIHelper.json_deserialize(_response.raw_body)
292
+ _errors = APIHelper.map_response(decoded, ['errors'])
293
+ ApiResponse.new(
294
+ _response, data: decoded, errors: _errors
295
+ )
296
+ end
297
+ end
298
+ end