square.rb 6.0.0.20200625 → 6.5.0.20201028

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +37 -30
  3. data/lib/square.rb +61 -60
  4. data/lib/square/api/apple_pay_api.rb +3 -1
  5. data/lib/square/api/bank_accounts_api.rb +12 -15
  6. data/lib/square/api/base_api.rb +2 -2
  7. data/lib/square/api/cash_drawers_api.rb +11 -5
  8. data/lib/square/api/catalog_api.rb +119 -49
  9. data/lib/square/api/checkout_api.rb +4 -2
  10. data/lib/square/api/customer_groups_api.rb +18 -8
  11. data/lib/square/api/customer_segments_api.rb +7 -3
  12. data/lib/square/api/customers_api.rb +47 -27
  13. data/lib/square/api/devices_api.rb +17 -6
  14. data/lib/square/api/disputes_api.rb +39 -34
  15. data/lib/square/api/employees_api.rb +10 -5
  16. data/lib/square/api/inventory_api.rb +30 -15
  17. data/lib/square/api/invoices_api.rb +359 -0
  18. data/lib/square/api/labor_api.rb +131 -22
  19. data/lib/square/api/locations_api.rb +20 -12
  20. data/lib/square/api/loyalty_api.rb +59 -65
  21. data/lib/square/api/merchants_api.rb +9 -4
  22. data/lib/square/api/mobile_authorization_api.rb +3 -1
  23. data/lib/square/api/o_auth_api.rb +10 -4
  24. data/lib/square/api/orders_api.rb +111 -90
  25. data/lib/square/api/payments_api.rb +75 -65
  26. data/lib/square/api/refunds_api.rb +21 -11
  27. data/lib/square/api/subscriptions_api.rb +263 -0
  28. data/lib/square/api/team_api.rb +32 -16
  29. data/lib/square/api/terminal_api.rb +156 -7
  30. data/lib/square/api/transactions_api.rb +32 -18
  31. data/lib/square/api/v1_employees_api.rb +59 -27
  32. data/lib/square/api/v1_items_api.rb +195 -115
  33. data/lib/square/api/v1_locations_api.rb +6 -2
  34. data/lib/square/api/v1_transactions_api.rb +49 -27
  35. data/lib/square/api_helper.rb +14 -9
  36. data/lib/square/client.rb +23 -16
  37. data/lib/square/configuration.rb +12 -4
  38. data/lib/square/http/api_response.rb +2 -0
  39. data/lib/square/http/faraday_client.rb +1 -0
  40. data/spec/user_journey_spec.rb +2 -5
  41. data/test/api/api_test_base.rb +1 -6
  42. data/test/api/test_catalog_api.rb +1 -4
  43. data/test/api/test_customers_api.rb +1 -4
  44. data/test/api/test_employees_api.rb +1 -4
  45. data/test/api/test_labor_api.rb +2 -6
  46. data/test/api/test_locations_api.rb +22 -33
  47. data/test/api/test_merchants_api.rb +1 -4
  48. data/test/api/test_payments_api.rb +3 -6
  49. data/test/api/test_refunds_api.rb +3 -6
  50. data/test/http_response_catcher.rb +0 -5
  51. data/test/test_helper.rb +0 -5
  52. metadata +33 -14
  53. data/lib/square/api/reporting_api.rb +0 -138
@@ -6,8 +6,7 @@ module Square
6
6
  end
7
7
 
8
8
  # ListEmployees
9
- # @param [String] location_id Optional parameter: Filter employees returned
10
- # to only those that are associated with the specified location.
9
+ # @param [String] location_id Optional parameter: Example:
11
10
  # @param [EmployeeStatus] status Optional parameter: Specifies the
12
11
  # EmployeeStatus to filter the employee by.
13
12
  # @param [Integer] limit Optional parameter: The number of employees to be
@@ -19,6 +18,7 @@ module Square
19
18
  status: nil,
20
19
  limit: nil,
21
20
  cursor: nil)
21
+ warn 'Endpoint list_employees in EmployeesApi is deprecated'
22
22
  # Prepare query url.
23
23
  _query_builder = config.get_base_uri
24
24
  _query_builder << '/v2/employees'
@@ -47,7 +47,9 @@ module Square
47
47
  # Return appropriate response type.
48
48
  decoded = APIHelper.json_deserialize(_response.raw_body)
49
49
  _errors = APIHelper.map_response(decoded, ['errors'])
50
- ApiResponse.new(_response, data: decoded, errors: _errors)
50
+ ApiResponse.new(
51
+ _response, data: decoded, errors: _errors
52
+ )
51
53
  end
52
54
 
53
55
  # RetrieveEmployee
@@ -55,12 +57,13 @@ module Square
55
57
  # requested.
56
58
  # @return [RetrieveEmployeeResponse Hash] response from the API call
57
59
  def retrieve_employee(id:)
60
+ warn 'Endpoint retrieve_employee in EmployeesApi is deprecated'
58
61
  # Prepare query url.
59
62
  _query_builder = config.get_base_uri
60
63
  _query_builder << '/v2/employees/{id}'
61
64
  _query_builder = APIHelper.append_url_with_template_parameters(
62
65
  _query_builder,
63
- 'id' => id
66
+ 'id' => { 'value' => id, 'encode' => true }
64
67
  )
65
68
  _query_url = APIHelper.clean_url _query_builder
66
69
 
@@ -80,7 +83,9 @@ module Square
80
83
  # Return appropriate response type.
81
84
  decoded = APIHelper.json_deserialize(_response.raw_body)
82
85
  _errors = APIHelper.map_response(decoded, ['errors'])
83
- ApiResponse.new(_response, data: decoded, errors: _errors)
86
+ ApiResponse.new(
87
+ _response, data: decoded, errors: _errors
88
+ )
84
89
  end
85
90
  end
86
91
  end
@@ -16,7 +16,7 @@ module Square
16
16
  _query_builder << '/v2/inventory/adjustment/{adjustment_id}'
17
17
  _query_builder = APIHelper.append_url_with_template_parameters(
18
18
  _query_builder,
19
- 'adjustment_id' => adjustment_id
19
+ 'adjustment_id' => { 'value' => adjustment_id, 'encode' => true }
20
20
  )
21
21
  _query_url = APIHelper.clean_url _query_builder
22
22
 
@@ -36,7 +36,9 @@ module Square
36
36
  # Return appropriate response type.
37
37
  decoded = APIHelper.json_deserialize(_response.raw_body)
38
38
  _errors = APIHelper.map_response(decoded, ['errors'])
39
- ApiResponse.new(_response, data: decoded, errors: _errors)
39
+ ApiResponse.new(
40
+ _response, data: decoded, errors: _errors
41
+ )
40
42
  end
41
43
 
42
44
  # Applies adjustments and counts to the provided item quantities.
@@ -71,7 +73,9 @@ module Square
71
73
  # Return appropriate response type.
72
74
  decoded = APIHelper.json_deserialize(_response.raw_body)
73
75
  _errors = APIHelper.map_response(decoded, ['errors'])
74
- ApiResponse.new(_response, data: decoded, errors: _errors)
76
+ ApiResponse.new(
77
+ _response, data: decoded, errors: _errors
78
+ )
75
79
  end
76
80
 
77
81
  # Returns historical physical counts and adjustments based on the
@@ -108,7 +112,9 @@ module Square
108
112
  # Return appropriate response type.
109
113
  decoded = APIHelper.json_deserialize(_response.raw_body)
110
114
  _errors = APIHelper.map_response(decoded, ['errors'])
111
- ApiResponse.new(_response, data: decoded, errors: _errors)
115
+ ApiResponse.new(
116
+ _response, data: decoded, errors: _errors
117
+ )
112
118
  end
113
119
 
114
120
  # Returns current counts for the provided
@@ -149,7 +155,9 @@ module Square
149
155
  # Return appropriate response type.
150
156
  decoded = APIHelper.json_deserialize(_response.raw_body)
151
157
  _errors = APIHelper.map_response(decoded, ['errors'])
152
- ApiResponse.new(_response, data: decoded, errors: _errors)
158
+ ApiResponse.new(
159
+ _response, data: decoded, errors: _errors
160
+ )
153
161
  end
154
162
 
155
163
  # Returns the [InventoryPhysicalCount](#type-inventoryphysicalcount)
@@ -163,7 +171,7 @@ module Square
163
171
  _query_builder << '/v2/inventory/physical-count/{physical_count_id}'
164
172
  _query_builder = APIHelper.append_url_with_template_parameters(
165
173
  _query_builder,
166
- 'physical_count_id' => physical_count_id
174
+ 'physical_count_id' => { 'value' => physical_count_id, 'encode' => true }
167
175
  )
168
176
  _query_url = APIHelper.clean_url _query_builder
169
177
 
@@ -183,7 +191,9 @@ module Square
183
191
  # Return appropriate response type.
184
192
  decoded = APIHelper.json_deserialize(_response.raw_body)
185
193
  _errors = APIHelper.map_response(decoded, ['errors'])
186
- ApiResponse.new(_response, data: decoded, errors: _errors)
194
+ ApiResponse.new(
195
+ _response, data: decoded, errors: _errors
196
+ )
187
197
  end
188
198
 
189
199
  # Retrieves the current calculated stock count for a given
@@ -209,7 +219,7 @@ module Square
209
219
  _query_builder << '/v2/inventory/{catalog_object_id}'
210
220
  _query_builder = APIHelper.append_url_with_template_parameters(
211
221
  _query_builder,
212
- 'catalog_object_id' => catalog_object_id
222
+ 'catalog_object_id' => { 'value' => catalog_object_id, 'encode' => true }
213
223
  )
214
224
  _query_builder = APIHelper.append_url_with_query_parameters(
215
225
  _query_builder,
@@ -234,7 +244,9 @@ module Square
234
244
  # Return appropriate response type.
235
245
  decoded = APIHelper.json_deserialize(_response.raw_body)
236
246
  _errors = APIHelper.map_response(decoded, ['errors'])
237
- ApiResponse.new(_response, data: decoded, errors: _errors)
247
+ ApiResponse.new(
248
+ _response, data: decoded, errors: _errors
249
+ )
238
250
  end
239
251
 
240
252
  # Returns a set of physical counts and inventory adjustments for the
@@ -242,8 +254,9 @@ module Square
242
254
  # [Location](#type-location)s.
243
255
  # Results are paginated and sorted in descending order according to their
244
256
  # `occurred_at` timestamp (newest first).
245
- # There are no limits on how far back the caller can page. This endpoint is
246
- # useful when displaying recent changes for a specific item. For more
257
+ # There are no limits on how far back the caller can page. This endpoint can
258
+ # be
259
+ # used to display recent changes for a specific item. For more
247
260
  # sophisticated queries, use a batch endpoint.
248
261
  # @param [String] catalog_object_id Required parameter: ID of the
249
262
  # [CatalogObject](#type-catalogobject) to retrieve.
@@ -253,8 +266,8 @@ module Square
253
266
  # @param [String] cursor Optional parameter: A pagination cursor returned by
254
267
  # a previous call to this endpoint. Provide this to retrieve the next set of
255
268
  # results for the original query. See the
256
- # [Pagination](https://developer.squareup.com/docs/docs/working-with-apis/pa
257
- # gination) guide for more information.
269
+ # [Pagination](https://developer.squareup.com/docs/working-with-apis/paginat
270
+ # ion) guide for more information.
258
271
  # @return [RetrieveInventoryChangesResponse Hash] response from the API call
259
272
  def retrieve_inventory_changes(catalog_object_id:,
260
273
  location_ids: nil,
@@ -264,7 +277,7 @@ module Square
264
277
  _query_builder << '/v2/inventory/{catalog_object_id}/changes'
265
278
  _query_builder = APIHelper.append_url_with_template_parameters(
266
279
  _query_builder,
267
- 'catalog_object_id' => catalog_object_id
280
+ 'catalog_object_id' => { 'value' => catalog_object_id, 'encode' => true }
268
281
  )
269
282
  _query_builder = APIHelper.append_url_with_query_parameters(
270
283
  _query_builder,
@@ -289,7 +302,9 @@ module Square
289
302
  # Return appropriate response type.
290
303
  decoded = APIHelper.json_deserialize(_response.raw_body)
291
304
  _errors = APIHelper.map_response(decoded, ['errors'])
292
- ApiResponse.new(_response, data: decoded, errors: _errors)
305
+ ApiResponse.new(
306
+ _response, data: decoded, errors: _errors
307
+ )
293
308
  end
294
309
  end
295
310
  end
@@ -0,0 +1,359 @@
1
+ module Square
2
+ # InvoicesApi
3
+ class InvoicesApi < BaseApi
4
+ def initialize(config, http_call_back: nil)
5
+ super(config, http_call_back: http_call_back)
6
+ end
7
+
8
+ # Returns a list of invoices for a given location. The response
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.
11
+ # @param [String] location_id Required parameter: The ID of the location for
12
+ # which to list invoices.
13
+ # @param [String] cursor Optional parameter: A pagination cursor returned by
14
+ # a previous call to this endpoint. Provide this cursor to retrieve the
15
+ # next set of results for your original query. For more information, see
16
+ # [Pagination](https://developer.squareup.com/docs/docs/working-with-apis/pa
17
+ # gination).
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
20
+ # a default limit of 100 invoices.
21
+ # @return [ListInvoicesResponse Hash] response from the API call
22
+ def list_invoices(location_id:,
23
+ cursor: nil,
24
+ limit: nil)
25
+ # Prepare query url.
26
+ _query_builder = config.get_base_uri
27
+ _query_builder << '/v2/invoices'
28
+ _query_builder = APIHelper.append_url_with_query_parameters(
29
+ _query_builder,
30
+ 'location_id' => location_id,
31
+ 'cursor' => cursor,
32
+ 'limit' => limit
33
+ )
34
+ _query_url = APIHelper.clean_url _query_builder
35
+
36
+ # Prepare headers.
37
+ _headers = {
38
+ 'accept' => 'application/json'
39
+ }
40
+
41
+ # Prepare and execute HttpRequest.
42
+ _request = config.http_client.get(
43
+ _query_url,
44
+ headers: _headers
45
+ )
46
+ OAuth2.apply(config, _request)
47
+ _response = execute_request(_request)
48
+
49
+ # Return appropriate response type.
50
+ decoded = APIHelper.json_deserialize(_response.raw_body)
51
+ _errors = APIHelper.map_response(decoded, ['errors'])
52
+ ApiResponse.new(
53
+ _response, data: decoded, errors: _errors
54
+ )
55
+ end
56
+
57
+ # Creates a draft [invoice](#type-invoice)
58
+ # for an order created using the Orders API.
59
+ # A draft invoice remains in your account and no action is taken.
60
+ # You must publish the invoice before Square can process it (send it to the
61
+ # customer's email address or charge the customer’s card on file).
62
+ # @param [CreateInvoiceRequest] body Required parameter: An object
63
+ # containing the fields to POST for the request. See the corresponding
64
+ # object definition for field details.
65
+ # @return [CreateInvoiceResponse Hash] response from the API call
66
+ def create_invoice(body:)
67
+ # Prepare query url.
68
+ _query_builder = config.get_base_uri
69
+ _query_builder << '/v2/invoices'
70
+ _query_url = APIHelper.clean_url _query_builder
71
+
72
+ # Prepare headers.
73
+ _headers = {
74
+ 'accept' => 'application/json',
75
+ 'content-type' => 'application/json; charset=utf-8'
76
+ }
77
+
78
+ # Prepare and execute HttpRequest.
79
+ _request = config.http_client.post(
80
+ _query_url,
81
+ headers: _headers,
82
+ parameters: body.to_json
83
+ )
84
+ OAuth2.apply(config, _request)
85
+ _response = execute_request(_request)
86
+
87
+ # Return appropriate response type.
88
+ decoded = APIHelper.json_deserialize(_response.raw_body)
89
+ _errors = APIHelper.map_response(decoded, ['errors'])
90
+ ApiResponse.new(
91
+ _response, data: decoded, errors: _errors
92
+ )
93
+ end
94
+
95
+ # Searches for invoices from a location specified in
96
+ # the filter. You can optionally specify customers in the filter for whom to
97
+ # retrieve invoices. In the current implementation, you can only specify one
98
+ # location and
99
+ # optionally one customer.
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.
102
+ # @param [SearchInvoicesRequest] body Required parameter: An object
103
+ # containing the fields to POST for the request. See the corresponding
104
+ # object definition for field details.
105
+ # @return [SearchInvoicesResponse Hash] response from the API call
106
+ def search_invoices(body:)
107
+ # Prepare query url.
108
+ _query_builder = config.get_base_uri
109
+ _query_builder << '/v2/invoices/search'
110
+ _query_url = APIHelper.clean_url _query_builder
111
+
112
+ # Prepare headers.
113
+ _headers = {
114
+ 'accept' => 'application/json',
115
+ 'content-type' => 'application/json; charset=utf-8'
116
+ }
117
+
118
+ # Prepare and execute HttpRequest.
119
+ _request = config.http_client.post(
120
+ _query_url,
121
+ headers: _headers,
122
+ parameters: body.to_json
123
+ )
124
+ OAuth2.apply(config, _request)
125
+ _response = execute_request(_request)
126
+
127
+ # Return appropriate response type.
128
+ decoded = APIHelper.json_deserialize(_response.raw_body)
129
+ _errors = APIHelper.map_response(decoded, ['errors'])
130
+ ApiResponse.new(
131
+ _response, data: decoded, errors: _errors
132
+ )
133
+ end
134
+
135
+ # Deletes the specified invoice. When an invoice is deleted, the
136
+ # associated Order status changes to CANCELED. You can only delete a draft
137
+ # invoice (you cannot delete an invoice scheduled for publication, or a
138
+ # published invoice).
139
+ # @param [String] invoice_id Required parameter: The ID of the invoice to
140
+ # delete.
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).
145
+ # @return [DeleteInvoiceResponse Hash] response from the API call
146
+ def delete_invoice(invoice_id:,
147
+ version: nil)
148
+ # Prepare query url.
149
+ _query_builder = config.get_base_uri
150
+ _query_builder << '/v2/invoices/{invoice_id}'
151
+ _query_builder = APIHelper.append_url_with_template_parameters(
152
+ _query_builder,
153
+ 'invoice_id' => { 'value' => invoice_id, 'encode' => true }
154
+ )
155
+ _query_builder = APIHelper.append_url_with_query_parameters(
156
+ _query_builder,
157
+ 'version' => version
158
+ )
159
+ _query_url = APIHelper.clean_url _query_builder
160
+
161
+ # Prepare headers.
162
+ _headers = {
163
+ 'accept' => 'application/json'
164
+ }
165
+
166
+ # Prepare and execute HttpRequest.
167
+ _request = config.http_client.delete(
168
+ _query_url,
169
+ headers: _headers
170
+ )
171
+ OAuth2.apply(config, _request)
172
+ _response = execute_request(_request)
173
+
174
+ # Return appropriate response type.
175
+ decoded = APIHelper.json_deserialize(_response.raw_body)
176
+ _errors = APIHelper.map_response(decoded, ['errors'])
177
+ ApiResponse.new(
178
+ _response, data: decoded, errors: _errors
179
+ )
180
+ end
181
+
182
+ # Retrieves an invoice by invoice ID.
183
+ # @param [String] invoice_id Required parameter: The id of the invoice to
184
+ # retrieve.
185
+ # @return [GetInvoiceResponse Hash] response from the API call
186
+ def get_invoice(invoice_id:)
187
+ # Prepare query url.
188
+ _query_builder = config.get_base_uri
189
+ _query_builder << '/v2/invoices/{invoice_id}'
190
+ _query_builder = APIHelper.append_url_with_template_parameters(
191
+ _query_builder,
192
+ 'invoice_id' => { 'value' => invoice_id, 'encode' => true }
193
+ )
194
+ _query_url = APIHelper.clean_url _query_builder
195
+
196
+ # Prepare headers.
197
+ _headers = {
198
+ 'accept' => 'application/json'
199
+ }
200
+
201
+ # Prepare and execute HttpRequest.
202
+ _request = config.http_client.get(
203
+ _query_url,
204
+ headers: _headers
205
+ )
206
+ OAuth2.apply(config, _request)
207
+ _response = execute_request(_request)
208
+
209
+ # Return appropriate response type.
210
+ decoded = APIHelper.json_deserialize(_response.raw_body)
211
+ _errors = APIHelper.map_response(decoded, ['errors'])
212
+ ApiResponse.new(
213
+ _response, data: decoded, errors: _errors
214
+ )
215
+ end
216
+
217
+ # Updates an invoice by modifying field values, clearing field values, or
218
+ # both
219
+ # as specified in the request.
220
+ # There are no restrictions to updating an invoice in a draft state.
221
+ # However, there are guidelines for updating a published invoice.
222
+ # @param [String] invoice_id Required parameter: The id of the invoice to
223
+ # update.
224
+ # @param [UpdateInvoiceRequest] body Required parameter: An object
225
+ # containing the fields to POST for the request. See the corresponding
226
+ # object definition for field details.
227
+ # @return [UpdateInvoiceResponse Hash] response from the API call
228
+ def update_invoice(invoice_id:,
229
+ body:)
230
+ # Prepare query url.
231
+ _query_builder = config.get_base_uri
232
+ _query_builder << '/v2/invoices/{invoice_id}'
233
+ _query_builder = APIHelper.append_url_with_template_parameters(
234
+ _query_builder,
235
+ 'invoice_id' => { 'value' => invoice_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; charset=utf-8'
243
+ }
244
+
245
+ # Prepare and execute HttpRequest.
246
+ _request = config.http_client.put(
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
+ # Cancels an invoice. The seller cannot collect payments for
263
+ # the canceled invoice.
264
+ # You cannot cancel an invoice in a terminal state: `PAID`, `REFUNDED`,
265
+ # `CANCELED`, or `FAILED`.
266
+ # @param [String] invoice_id Required parameter: The ID of the
267
+ # [invoice](#type-invoice) to cancel.
268
+ # @param [CancelInvoiceRequest] body Required parameter: An object
269
+ # containing the fields to POST for the request. See the corresponding
270
+ # object definition for field details.
271
+ # @return [CancelInvoiceResponse Hash] response from the API call
272
+ def cancel_invoice(invoice_id:,
273
+ body:)
274
+ # Prepare query url.
275
+ _query_builder = config.get_base_uri
276
+ _query_builder << '/v2/invoices/{invoice_id}/cancel'
277
+ _query_builder = APIHelper.append_url_with_template_parameters(
278
+ _query_builder,
279
+ 'invoice_id' => { 'value' => invoice_id, 'encode' => true }
280
+ )
281
+ _query_url = APIHelper.clean_url _query_builder
282
+
283
+ # Prepare headers.
284
+ _headers = {
285
+ 'accept' => 'application/json',
286
+ 'content-type' => 'application/json; charset=utf-8'
287
+ }
288
+
289
+ # Prepare and execute HttpRequest.
290
+ _request = config.http_client.post(
291
+ _query_url,
292
+ headers: _headers,
293
+ parameters: body.to_json
294
+ )
295
+ OAuth2.apply(config, _request)
296
+ _response = execute_request(_request)
297
+
298
+ # Return appropriate response type.
299
+ decoded = APIHelper.json_deserialize(_response.raw_body)
300
+ _errors = APIHelper.map_response(decoded, ['errors'])
301
+ ApiResponse.new(
302
+ _response, data: decoded, errors: _errors
303
+ )
304
+ end
305
+
306
+ # Publishes the specified draft invoice.
307
+ # After an invoice is published, Square
308
+ # follows up based on the invoice configuration. For example, Square
309
+ # sends the invoice to the customer's email address, charges the customer's
310
+ # card on file, or does
311
+ # nothing. Square also makes the invoice available on a Square-hosted
312
+ # invoice page.
313
+ # The invoice `status` also changes from `DRAFT` to a status
314
+ # based on the invoice configuration. For example, the status changes to
315
+ # `UNPAID` if
316
+ # Square emails the invoice or `PARTIALLY_PAID` if Square charge a card on
317
+ # file for a portion of the
318
+ # invoice amount).
319
+ # @param [String] invoice_id Required parameter: The id of the invoice to
320
+ # publish.
321
+ # @param [PublishInvoiceRequest] body Required parameter: An object
322
+ # containing the fields to POST for the request. See the corresponding
323
+ # object definition for field details.
324
+ # @return [PublishInvoiceResponse Hash] response from the API call
325
+ def publish_invoice(invoice_id:,
326
+ body:)
327
+ # Prepare query url.
328
+ _query_builder = config.get_base_uri
329
+ _query_builder << '/v2/invoices/{invoice_id}/publish'
330
+ _query_builder = APIHelper.append_url_with_template_parameters(
331
+ _query_builder,
332
+ 'invoice_id' => { 'value' => invoice_id, 'encode' => true }
333
+ )
334
+ _query_url = APIHelper.clean_url _query_builder
335
+
336
+ # Prepare headers.
337
+ _headers = {
338
+ 'accept' => 'application/json',
339
+ 'content-type' => 'application/json; charset=utf-8'
340
+ }
341
+
342
+ # Prepare and execute HttpRequest.
343
+ _request = config.http_client.post(
344
+ _query_url,
345
+ headers: _headers,
346
+ parameters: body.to_json
347
+ )
348
+ OAuth2.apply(config, _request)
349
+ _response = execute_request(_request)
350
+
351
+ # Return appropriate response type.
352
+ decoded = APIHelper.json_deserialize(_response.raw_body)
353
+ _errors = APIHelper.map_response(decoded, ['errors'])
354
+ ApiResponse.new(
355
+ _response, data: decoded, errors: _errors
356
+ )
357
+ end
358
+ end
359
+ end