square.rb 9.1.0.20210317 → 12.0.0.20210616

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 (38) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -3
  3. data/lib/square.rb +5 -0
  4. data/lib/square/api/bank_accounts_api.rb +5 -5
  5. data/lib/square/api/base_api.rb +1 -1
  6. data/lib/square/api/bookings_api.rb +3 -5
  7. data/lib/square/api/cards_api.rb +170 -0
  8. data/lib/square/api/cash_drawers_api.rb +2 -2
  9. data/lib/square/api/catalog_api.rb +40 -41
  10. data/lib/square/api/customer_groups_api.rb +4 -4
  11. data/lib/square/api/customer_segments_api.rb +4 -4
  12. data/lib/square/api/customers_api.rb +45 -26
  13. data/lib/square/api/devices_api.rb +2 -1
  14. data/lib/square/api/disputes_api.rb +100 -91
  15. data/lib/square/api/gift_card_activities_api.rb +127 -0
  16. data/lib/square/api/gift_cards_api.rb +291 -0
  17. data/lib/square/api/inventory_api.rb +16 -16
  18. data/lib/square/api/invoices_api.rb +14 -14
  19. data/lib/square/api/locations_api.rb +1 -2
  20. data/lib/square/api/loyalty_api.rb +66 -14
  21. data/lib/square/api/merchants_api.rb +1 -1
  22. data/lib/square/api/o_auth_api.rb +8 -9
  23. data/lib/square/api/orders_api.rb +35 -33
  24. data/lib/square/api/payments_api.rb +4 -1
  25. data/lib/square/api/refunds_api.rb +4 -1
  26. data/lib/square/api/sites_api.rb +42 -0
  27. data/lib/square/api/snippets_api.rb +146 -0
  28. data/lib/square/api/subscriptions_api.rb +36 -1
  29. data/lib/square/api/team_api.rb +40 -40
  30. data/lib/square/api/transactions_api.rb +32 -20
  31. data/lib/square/api/v1_employees_api.rb +2 -1
  32. data/lib/square/api/v1_transactions_api.rb +9 -0
  33. data/lib/square/api_helper.rb +5 -5
  34. data/lib/square/client.rb +37 -3
  35. data/lib/square/configuration.rb +23 -8
  36. data/lib/square/http/faraday_client.rb +5 -2
  37. data/test/api/test_locations_api.rb +1 -1
  38. metadata +11 -6
@@ -0,0 +1,291 @@
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 is provided, gift cards
11
+ # of this type are returned (see [GiftCardType]($m/GiftCardType)). If no
12
+ # type is provided, it returns gift cards of all types.
13
+ # @param [String] state Optional parameter: If the state is provided, it
14
+ # returns the gift cards in the specified state (see
15
+ # [GiftCardStatus]($m/GiftCardStatus)). Otherwise, it returns the gift cards
16
+ # of all states.
17
+ # @param [Integer] limit Optional parameter: If a value is provided, it
18
+ # returns only that number of results per page. The maximum number of
19
+ # results allowed per page is 50. The default value is 30.
20
+ # @param [String] cursor Optional parameter: A pagination cursor returned by
21
+ # a previous call to this endpoint. Provide this cursor to retrieve the next
22
+ # set of results for the original query. If a cursor is not provided, it
23
+ # returns the first page of the results. For more information, see
24
+ # [Pagination](https://developer.squareup.com/docs/working-with-apis/paginat
25
+ # ion).
26
+ # @param [String] customer_id Optional parameter: If a value is provided,
27
+ # returns only the gift cards linked to the specified customer
28
+ # @return [ListGiftCardsResponse Hash] response from the API call
29
+ def list_gift_cards(type: nil,
30
+ state: nil,
31
+ limit: nil,
32
+ cursor: nil,
33
+ customer_id: nil)
34
+ # Prepare query url.
35
+ _query_builder = config.get_base_uri
36
+ _query_builder << '/v2/gift-cards'
37
+ _query_builder = APIHelper.append_url_with_query_parameters(
38
+ _query_builder,
39
+ 'type' => type,
40
+ 'state' => state,
41
+ 'limit' => limit,
42
+ 'cursor' => cursor,
43
+ 'customer_id' => customer_id
44
+ )
45
+ _query_url = APIHelper.clean_url _query_builder
46
+
47
+ # Prepare headers.
48
+ _headers = {
49
+ 'accept' => 'application/json'
50
+ }
51
+
52
+ # Prepare and execute HttpRequest.
53
+ _request = config.http_client.get(
54
+ _query_url,
55
+ headers: _headers
56
+ )
57
+ OAuth2.apply(config, _request)
58
+ _response = execute_request(_request)
59
+
60
+ # Return appropriate response type.
61
+ decoded = APIHelper.json_deserialize(_response.raw_body)
62
+ _errors = APIHelper.map_response(decoded, ['errors'])
63
+ ApiResponse.new(
64
+ _response, data: decoded, errors: _errors
65
+ )
66
+ end
67
+
68
+ # Creates a digital gift card. You must activate the gift card before
69
+ # it can be used. For more information, see
70
+ # [Selling gift
71
+ # cards](https://developer.squareup.com/docs/gift-cards/using-gift-cards-api
72
+ # #selling-square-gift-cards).
73
+ # @param [CreateGiftCardRequest] body Required parameter: An object
74
+ # containing the fields to POST for the request. See the corresponding
75
+ # object definition for field details.
76
+ # @return [CreateGiftCardResponse Hash] response from the API call
77
+ def create_gift_card(body:)
78
+ # Prepare query url.
79
+ _query_builder = config.get_base_uri
80
+ _query_builder << '/v2/gift-cards'
81
+ _query_url = APIHelper.clean_url _query_builder
82
+
83
+ # Prepare headers.
84
+ _headers = {
85
+ 'accept' => 'application/json',
86
+ 'content-type' => 'application/json; charset=utf-8'
87
+ }
88
+
89
+ # Prepare and execute HttpRequest.
90
+ _request = config.http_client.post(
91
+ _query_url,
92
+ headers: _headers,
93
+ parameters: body.to_json
94
+ )
95
+ OAuth2.apply(config, _request)
96
+ _response = execute_request(_request)
97
+
98
+ # Return appropriate response type.
99
+ decoded = APIHelper.json_deserialize(_response.raw_body)
100
+ _errors = APIHelper.map_response(decoded, ['errors'])
101
+ ApiResponse.new(
102
+ _response, data: decoded, errors: _errors
103
+ )
104
+ end
105
+
106
+ # Retrieves a gift card using the gift card account number (GAN).
107
+ # @param [RetrieveGiftCardFromGANRequest] body Required parameter: An object
108
+ # containing the fields to POST for the request. See the corresponding
109
+ # object definition for field details.
110
+ # @return [RetrieveGiftCardFromGANResponse Hash] response from the API call
111
+ def retrieve_gift_card_from_gan(body:)
112
+ # Prepare query url.
113
+ _query_builder = config.get_base_uri
114
+ _query_builder << '/v2/gift-cards/from-gan'
115
+ _query_url = APIHelper.clean_url _query_builder
116
+
117
+ # Prepare headers.
118
+ _headers = {
119
+ 'accept' => 'application/json',
120
+ 'content-type' => 'application/json; charset=utf-8'
121
+ }
122
+
123
+ # Prepare and execute HttpRequest.
124
+ _request = config.http_client.post(
125
+ _query_url,
126
+ headers: _headers,
127
+ parameters: body.to_json
128
+ )
129
+ OAuth2.apply(config, _request)
130
+ _response = execute_request(_request)
131
+
132
+ # Return appropriate response type.
133
+ decoded = APIHelper.json_deserialize(_response.raw_body)
134
+ _errors = APIHelper.map_response(decoded, ['errors'])
135
+ ApiResponse.new(
136
+ _response, data: decoded, errors: _errors
137
+ )
138
+ end
139
+
140
+ # Retrieves a gift card using a nonce (a secure token) that represents the
141
+ # gift card.
142
+ # @param [RetrieveGiftCardFromNonceRequest] body Required parameter: An
143
+ # object containing the fields to POST for the request. See the
144
+ # corresponding object definition for field details.
145
+ # @return [RetrieveGiftCardFromNonceResponse Hash] response from the API call
146
+ def retrieve_gift_card_from_nonce(body:)
147
+ # Prepare query url.
148
+ _query_builder = config.get_base_uri
149
+ _query_builder << '/v2/gift-cards/from-nonce'
150
+ _query_url = APIHelper.clean_url _query_builder
151
+
152
+ # Prepare headers.
153
+ _headers = {
154
+ 'accept' => 'application/json',
155
+ 'content-type' => 'application/json; charset=utf-8'
156
+ }
157
+
158
+ # Prepare and execute HttpRequest.
159
+ _request = config.http_client.post(
160
+ _query_url,
161
+ headers: _headers,
162
+ parameters: body.to_json
163
+ )
164
+ OAuth2.apply(config, _request)
165
+ _response = execute_request(_request)
166
+
167
+ # Return appropriate response type.
168
+ decoded = APIHelper.json_deserialize(_response.raw_body)
169
+ _errors = APIHelper.map_response(decoded, ['errors'])
170
+ ApiResponse.new(
171
+ _response, data: decoded, errors: _errors
172
+ )
173
+ end
174
+
175
+ # Links a customer to a gift card
176
+ # @param [String] gift_card_id Required parameter: The ID of the gift card
177
+ # to link.
178
+ # @param [LinkCustomerToGiftCardRequest] body Required parameter: An object
179
+ # containing the fields to POST for the request. See the corresponding
180
+ # object definition for field details.
181
+ # @return [LinkCustomerToGiftCardResponse Hash] response from the API call
182
+ def link_customer_to_gift_card(gift_card_id:,
183
+ body:)
184
+ # Prepare query url.
185
+ _query_builder = config.get_base_uri
186
+ _query_builder << '/v2/gift-cards/{gift_card_id}/link-customer'
187
+ _query_builder = APIHelper.append_url_with_template_parameters(
188
+ _query_builder,
189
+ 'gift_card_id' => { 'value' => gift_card_id, 'encode' => true }
190
+ )
191
+ _query_url = APIHelper.clean_url _query_builder
192
+
193
+ # Prepare headers.
194
+ _headers = {
195
+ 'accept' => 'application/json',
196
+ 'content-type' => 'application/json; charset=utf-8'
197
+ }
198
+
199
+ # Prepare and execute HttpRequest.
200
+ _request = config.http_client.post(
201
+ _query_url,
202
+ headers: _headers,
203
+ parameters: body.to_json
204
+ )
205
+ OAuth2.apply(config, _request)
206
+ _response = execute_request(_request)
207
+
208
+ # Return appropriate response type.
209
+ decoded = APIHelper.json_deserialize(_response.raw_body)
210
+ _errors = APIHelper.map_response(decoded, ['errors'])
211
+ ApiResponse.new(
212
+ _response, data: decoded, errors: _errors
213
+ )
214
+ end
215
+
216
+ # Unlinks a customer from a gift card
217
+ # @param [String] gift_card_id Required parameter: Example:
218
+ # @param [UnlinkCustomerFromGiftCardRequest] body Required parameter: An
219
+ # object containing the fields to POST for the request. See the
220
+ # corresponding object definition for field details.
221
+ # @return [UnlinkCustomerFromGiftCardResponse Hash] response from the API call
222
+ def unlink_customer_from_gift_card(gift_card_id:,
223
+ body:)
224
+ # Prepare query url.
225
+ _query_builder = config.get_base_uri
226
+ _query_builder << '/v2/gift-cards/{gift_card_id}/unlink-customer'
227
+ _query_builder = APIHelper.append_url_with_template_parameters(
228
+ _query_builder,
229
+ 'gift_card_id' => { 'value' => gift_card_id, 'encode' => true }
230
+ )
231
+ _query_url = APIHelper.clean_url _query_builder
232
+
233
+ # Prepare headers.
234
+ _headers = {
235
+ 'accept' => 'application/json',
236
+ 'content-type' => 'application/json; charset=utf-8'
237
+ }
238
+
239
+ # Prepare and execute HttpRequest.
240
+ _request = config.http_client.post(
241
+ _query_url,
242
+ headers: _headers,
243
+ parameters: body.to_json
244
+ )
245
+ OAuth2.apply(config, _request)
246
+ _response = execute_request(_request)
247
+
248
+ # Return appropriate response type.
249
+ decoded = APIHelper.json_deserialize(_response.raw_body)
250
+ _errors = APIHelper.map_response(decoded, ['errors'])
251
+ ApiResponse.new(
252
+ _response, data: decoded, errors: _errors
253
+ )
254
+ end
255
+
256
+ # Retrieves a gift card using its ID.
257
+ # @param [String] id Required parameter: The ID of the gift card to
258
+ # retrieve.
259
+ # @return [RetrieveGiftCardResponse Hash] response from the API call
260
+ def retrieve_gift_card(id:)
261
+ # Prepare query url.
262
+ _query_builder = config.get_base_uri
263
+ _query_builder << '/v2/gift-cards/{id}'
264
+ _query_builder = APIHelper.append_url_with_template_parameters(
265
+ _query_builder,
266
+ 'id' => { 'value' => id, 'encode' => true }
267
+ )
268
+ _query_url = APIHelper.clean_url _query_builder
269
+
270
+ # Prepare headers.
271
+ _headers = {
272
+ 'accept' => 'application/json'
273
+ }
274
+
275
+ # Prepare and execute HttpRequest.
276
+ _request = config.http_client.get(
277
+ _query_url,
278
+ headers: _headers
279
+ )
280
+ OAuth2.apply(config, _request)
281
+ _response = execute_request(_request)
282
+
283
+ # Return appropriate response type.
284
+ decoded = APIHelper.json_deserialize(_response.raw_body)
285
+ _errors = APIHelper.map_response(decoded, ['errors'])
286
+ ApiResponse.new(
287
+ _response, data: decoded, errors: _errors
288
+ )
289
+ end
290
+ end
291
+ end
@@ -5,10 +5,10 @@ module Square
5
5
  super(config, http_call_back: http_call_back)
6
6
  end
7
7
 
8
- # Returns the [InventoryAdjustment](#type-inventoryadjustment) object
8
+ # Returns the [InventoryAdjustment]($m/InventoryAdjustment) object
9
9
  # with the provided `adjustment_id`.
10
10
  # @param [String] adjustment_id Required parameter: ID of the
11
- # [InventoryAdjustment](#type-inventoryadjustment) to retrieve.
11
+ # [InventoryAdjustment]($m/InventoryAdjustment) to retrieve.
12
12
  # @return [RetrieveInventoryAdjustmentResponse Hash] response from the API call
13
13
  def retrieve_inventory_adjustment(adjustment_id:)
14
14
  # Prepare query url.
@@ -118,8 +118,8 @@ module Square
118
118
  end
119
119
 
120
120
  # Returns current counts for the provided
121
- # [CatalogObject](#type-catalogobject)s at the requested
122
- # [Location](#type-location)s.
121
+ # [CatalogObject]($m/CatalogObject)s at the requested
122
+ # [Location]($m/Location)s.
123
123
  # Results are paginated and sorted in descending order according to their
124
124
  # `calculated_at` timestamp (newest first).
125
125
  # When `updated_after` is specified, only counts that have changed since
@@ -160,10 +160,10 @@ module Square
160
160
  )
161
161
  end
162
162
 
163
- # Returns the [InventoryPhysicalCount](#type-inventoryphysicalcount)
163
+ # Returns the [InventoryPhysicalCount]($m/InventoryPhysicalCount)
164
164
  # object with the provided `physical_count_id`.
165
165
  # @param [String] physical_count_id Required parameter: ID of the
166
- # [InventoryPhysicalCount](#type-inventoryphysicalcount) to retrieve.
166
+ # [InventoryPhysicalCount]($m/InventoryPhysicalCount) to retrieve.
167
167
  # @return [RetrieveInventoryPhysicalCountResponse Hash] response from the API call
168
168
  def retrieve_inventory_physical_count(physical_count_id:)
169
169
  # Prepare query url.
@@ -197,14 +197,14 @@ module Square
197
197
  end
198
198
 
199
199
  # Retrieves the current calculated stock count for a given
200
- # [CatalogObject](#type-catalogobject) at a given set of
201
- # [Location](#type-location)s. Responses are paginated and unsorted.
200
+ # [CatalogObject]($m/CatalogObject) at a given set of
201
+ # [Location]($m/Location)s. Responses are paginated and unsorted.
202
202
  # For more sophisticated queries, use a batch endpoint.
203
203
  # @param [String] catalog_object_id Required parameter: ID of the
204
- # [CatalogObject](#type-catalogobject) to retrieve.
204
+ # [CatalogObject]($m/CatalogObject) to retrieve.
205
205
  # @param [String] location_ids Optional parameter: The
206
- # [Location](#type-location) IDs to look up as a comma-separated list. An
207
- # empty list queries all locations.
206
+ # [Location]($m/Location) IDs to look up as a comma-separated list. An empty
207
+ # list queries all locations.
208
208
  # @param [String] cursor Optional parameter: A pagination cursor returned by
209
209
  # a previous call to this endpoint. Provide this to retrieve the next set of
210
210
  # results for the original query. See the
@@ -250,8 +250,8 @@ module Square
250
250
  end
251
251
 
252
252
  # Returns a set of physical counts and inventory adjustments for the
253
- # provided [CatalogObject](#type-catalogobject) at the requested
254
- # [Location](#type-location)s.
253
+ # provided [CatalogObject]($m/CatalogObject) at the requested
254
+ # [Location]($m/Location)s.
255
255
  # Results are paginated and sorted in descending order according to their
256
256
  # `occurred_at` timestamp (newest first).
257
257
  # There are no limits on how far back the caller can page. This endpoint can
@@ -259,10 +259,10 @@ module Square
259
259
  # used to display recent changes for a specific item. For more
260
260
  # sophisticated queries, use a batch endpoint.
261
261
  # @param [String] catalog_object_id Required parameter: ID of the
262
- # [CatalogObject](#type-catalogobject) to retrieve.
262
+ # [CatalogObject]($m/CatalogObject) to retrieve.
263
263
  # @param [String] location_ids Optional parameter: The
264
- # [Location](#type-location) IDs to look up as a comma-separated list. An
265
- # empty list queries all locations.
264
+ # [Location]($m/Location) IDs to look up as a comma-separated list. An empty
265
+ # list queries all locations.
266
266
  # @param [String] cursor Optional parameter: A pagination cursor returned by
267
267
  # a previous call to this endpoint. Provide this to retrieve the next set of
268
268
  # results for the original query. See the
@@ -7,7 +7,7 @@ module Square
7
7
 
8
8
  # Returns a list of invoices for a given location. The response
9
9
  # is paginated. If truncated, the response includes a `cursor` that you
10
- # use in a subsequent request to fetch the next set of invoices.
10
+ # use in a subsequent request to retrieve the next set of invoices.
11
11
  # @param [String] location_id Required parameter: The ID of the location for
12
12
  # which to list invoices.
13
13
  # @param [String] cursor Optional parameter: A pagination cursor returned by
@@ -16,7 +16,7 @@ module Square
16
16
  # [Pagination](https://developer.squareup.com/docs/working-with-apis/paginat
17
17
  # ion).
18
18
  # @param [Integer] limit Optional parameter: The maximum number of invoices
19
- # to return (200 is the maximum `limit`). If not provided, the server uses
19
+ # to return (200 is the maximum `limit`). If not provided, the server uses
20
20
  # a default limit of 100 invoices.
21
21
  # @return [ListInvoicesResponse Hash] response from the API call
22
22
  def list_invoices(location_id:,
@@ -54,7 +54,7 @@ module Square
54
54
  )
55
55
  end
56
56
 
57
- # Creates a draft [invoice](#type-invoice)
57
+ # Creates a draft [invoice]($m/Invoice)
58
58
  # for an order created using the Orders API.
59
59
  # A draft invoice remains in your account and no action is taken.
60
60
  # You must publish the invoice before Square can process it (send it to the
@@ -98,7 +98,7 @@ module Square
98
98
  # location and
99
99
  # optionally one customer.
100
100
  # The response is paginated. If truncated, the response includes a `cursor`
101
- # that you use in a subsequent request to fetch the next set of invoices.
101
+ # that you use in a subsequent request to retrieve the next set of invoices.
102
102
  # @param [SearchInvoicesRequest] body Required parameter: An object
103
103
  # containing the fields to POST for the request. See the corresponding
104
104
  # object definition for field details.
@@ -133,15 +133,15 @@ module Square
133
133
  end
134
134
 
135
135
  # Deletes the specified invoice. When an invoice is deleted, the
136
- # associated Order status changes to CANCELED. You can only delete a draft
136
+ # associated order status changes to CANCELED. You can only delete a draft
137
137
  # invoice (you cannot delete a published invoice, including one that is
138
138
  # scheduled for processing).
139
139
  # @param [String] invoice_id Required parameter: The ID of the invoice to
140
140
  # delete.
141
141
  # @param [Integer] version Optional parameter: The version of the
142
- # [invoice](#type-invoice) to delete. If you do not know the version, you
143
- # can call [GetInvoice](#endpoint-Invoices-GetInvoice) or
144
- # [ListInvoices](#endpoint-Invoices-ListInvoices).
142
+ # [invoice]($m/Invoice) to delete. If you do not know the version, you can
143
+ # call [GetInvoice]($e/Invoices/GetInvoice) or
144
+ # [ListInvoices]($e/Invoices/ListInvoices).
145
145
  # @return [DeleteInvoiceResponse Hash] response from the API call
146
146
  def delete_invoice(invoice_id:,
147
147
  version: nil)
@@ -180,7 +180,7 @@ module Square
180
180
  end
181
181
 
182
182
  # Retrieves an invoice by invoice ID.
183
- # @param [String] invoice_id Required parameter: The id of the invoice to
183
+ # @param [String] invoice_id Required parameter: The ID of the invoice to
184
184
  # retrieve.
185
185
  # @return [GetInvoiceResponse Hash] response from the API call
186
186
  def get_invoice(invoice_id:)
@@ -216,10 +216,10 @@ module Square
216
216
 
217
217
  # Updates an invoice by modifying fields, clearing fields, or both. For most
218
218
  # updates, you can use a sparse
219
- # `Invoice` object to add fields or change values, and use the
219
+ # `Invoice` object to add fields or change values and use the
220
220
  # `fields_to_clear` field to specify fields to clear.
221
221
  # However, some restrictions apply. For example, you cannot change the
222
- # `order_id` or `location_id` field, and you
222
+ # `order_id` or `location_id` field and you
223
223
  # must provide the complete `custom_fields` list to update a custom field.
224
224
  # Published invoices have additional restrictions.
225
225
  # @param [String] invoice_id Required parameter: The ID of the invoice to
@@ -267,7 +267,7 @@ module Square
267
267
  # You cannot cancel an invoice in the `DRAFT` state or in a terminal state:
268
268
  # `PAID`, `REFUNDED`, `CANCELED`, or `FAILED`.
269
269
  # @param [String] invoice_id Required parameter: The ID of the
270
- # [invoice](#type-invoice) to cancel.
270
+ # [invoice]($m/Invoice) to cancel.
271
271
  # @param [CancelInvoiceRequest] body Required parameter: An object
272
272
  # containing the fields to POST for the request. See the corresponding
273
273
  # object definition for field details.
@@ -318,8 +318,8 @@ module Square
318
318
  # `UNPAID` if
319
319
  # Square emails the invoice or `PARTIALLY_PAID` if Square charge a card on
320
320
  # file for a portion of the
321
- # invoice amount).
322
- # @param [String] invoice_id Required parameter: The id of the invoice to
321
+ # invoice amount.
322
+ # @param [String] invoice_id Required parameter: The ID of the invoice to
323
323
  # publish.
324
324
  # @param [PublishInvoiceRequest] body Required parameter: An object
325
325
  # containing the fields to POST for the request. See the corresponding