square.rb 6.3.0.20200826 → 17.1.0.20220120

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