Class: Square::InvoicesApi
- Defined in:
- lib/square/api/invoices_api.rb
Overview
InvoicesApi
Instance Attribute Summary
Attributes inherited from BaseApi
Instance Method Summary collapse
-
#cancel_invoice(invoice_id:, body:) ⇒ CancelInvoiceResponse Hash
Cancels an invoice.
-
#create_invoice(body:) ⇒ CreateInvoiceResponse Hash
Creates a draft [invoice]($m/Invoice) for an order created using the Orders API.
-
#delete_invoice(invoice_id:, version: nil) ⇒ DeleteInvoiceResponse Hash
Deletes the specified invoice.
-
#get_invoice(invoice_id:) ⇒ GetInvoiceResponse Hash
Retrieves an invoice by invoice ID.
-
#initialize(config, http_call_back: nil) ⇒ InvoicesApi
constructor
A new instance of InvoicesApi.
-
#list_invoices(location_id:, cursor: nil, limit: nil) ⇒ ListInvoicesResponse Hash
Returns a list of invoices for a given location.
-
#publish_invoice(invoice_id:, body:) ⇒ PublishInvoiceResponse Hash
Publishes the specified draft invoice.
-
#search_invoices(body:) ⇒ SearchInvoicesResponse Hash
Searches for invoices from a location specified in the filter.
-
#update_invoice(invoice_id:, body:) ⇒ UpdateInvoiceResponse Hash
Updates an invoice by modifying fields, clearing fields, or both.
Methods inherited from BaseApi
#execute_request, #get_user_agent, #validate_parameters
Constructor Details
#initialize(config, http_call_back: nil) ⇒ InvoicesApi
Returns a new instance of InvoicesApi.
4 5 6 |
# File 'lib/square/api/invoices_api.rb', line 4 def initialize(config, http_call_back: nil) super(config, http_call_back: http_call_back) end |
Instance Method Details
#cancel_invoice(invoice_id:, body:) ⇒ CancelInvoiceResponse Hash
Cancels an invoice. The seller cannot collect payments for the canceled invoice. You cannot cancel an invoice in the ‘DRAFT` state or in a terminal state: `PAID`, `REFUNDED`, `CANCELED`, or `FAILED`. [invoice]($m/Invoice) to cancel. containing the fields to POST for the request. See the corresponding object definition for field details.
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
# File 'lib/square/api/invoices_api.rb', line 275 def cancel_invoice(invoice_id:, body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/invoices/{invoice_id}/cancel' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'invoice_id' => { 'value' => invoice_id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'Content-Type' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.post( _query_url, headers: _headers, parameters: body.to_json ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#create_invoice(body:) ⇒ CreateInvoiceResponse Hash
Creates a draft [invoice]($m/Invoice) for an order created using the Orders API. A draft invoice remains in your account and no action is taken. You must publish the invoice before Square can process it (send it to the customer’s email address or charge the customer’s card on file). containing the fields to POST for the request. See the corresponding object definition for field details.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/square/api/invoices_api.rb', line 66 def create_invoice(body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/invoices' _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'Content-Type' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.post( _query_url, headers: _headers, parameters: body.to_json ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#delete_invoice(invoice_id:, version: nil) ⇒ DeleteInvoiceResponse Hash
Deletes the specified invoice. When an invoice is deleted, the associated order status changes to CANCELED. You can only delete a draft invoice (you cannot delete a published invoice, including one that is scheduled for processing). delete. [invoice]($m/Invoice) to delete. If you do not know the version, you can call [GetInvoice]($e/Invoices/GetInvoice) or [ListInvoices]($e/Invoices/ListInvoices).
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/square/api/invoices_api.rb', line 146 def delete_invoice(invoice_id:, version: nil) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/invoices/{invoice_id}' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'invoice_id' => { 'value' => invoice_id, 'encode' => true } ) _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, 'version' => version ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.delete( _query_url, headers: _headers ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#get_invoice(invoice_id:) ⇒ GetInvoiceResponse Hash
Retrieves an invoice by invoice ID. retrieve.
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/square/api/invoices_api.rb', line 186 def get_invoice(invoice_id:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/invoices/{invoice_id}' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'invoice_id' => { 'value' => invoice_id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.get( _query_url, headers: _headers ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#list_invoices(location_id:, cursor: nil, limit: nil) ⇒ ListInvoicesResponse Hash
Returns a list of invoices for a given location. The response is paginated. If truncated, the response includes a ‘cursor` that you use in a subsequent request to retrieve the next set of invoices. which to list invoices. a previous call to this endpoint. Provide this cursor to retrieve the next set of results for your original query. For more information, see [Pagination](developer.squareup.com/docs/working-with-apis/paginat ion). to return (200 is the maximum `limit`). If not provided, the server uses a default limit of 100 invoices.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/square/api/invoices_api.rb', line 22 def list_invoices(location_id:, cursor: nil, limit: nil) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/invoices' _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, 'location_id' => location_id, 'cursor' => cursor, 'limit' => limit ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.get( _query_url, headers: _headers ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#publish_invoice(invoice_id:, body:) ⇒ PublishInvoiceResponse Hash
Publishes the specified draft invoice. After an invoice is published, Square follows up based on the invoice configuration. For example, Square sends the invoice to the customer’s email address, charges the customer’s card on file, or does nothing. Square also makes the invoice available on a Square-hosted invoice page. The invoice ‘status` also changes from `DRAFT` to a status based on the invoice configuration. For example, the status changes to `UNPAID` if Square emails the invoice or `PARTIALLY_PAID` if Square charge a card on file for a portion of the invoice amount. publish. containing the fields to POST for the request. See the corresponding object definition for field details.
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/square/api/invoices_api.rb', line 328 def publish_invoice(invoice_id:, body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/invoices/{invoice_id}/publish' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'invoice_id' => { 'value' => invoice_id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'Content-Type' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.post( _query_url, headers: _headers, parameters: body.to_json ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#search_invoices(body:) ⇒ SearchInvoicesResponse Hash
Searches for invoices from a location specified in the filter. You can optionally specify customers in the filter for whom to retrieve invoices. In the current implementation, you can only specify one location and optionally one customer. The response is paginated. If truncated, the response includes a ‘cursor` that you use in a subsequent request to retrieve the next set of invoices. containing the fields to POST for the request. See the corresponding object definition for field details.
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/square/api/invoices_api.rb', line 106 def search_invoices(body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/invoices/search' _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'Content-Type' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.post( _query_url, headers: _headers, parameters: body.to_json ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#update_invoice(invoice_id:, body:) ⇒ UpdateInvoiceResponse Hash
Updates an invoice by modifying fields, clearing fields, or both. For most updates, you can use a sparse ‘Invoice` object to add fields or change values and use the `fields_to_clear` field to specify fields to clear. However, some restrictions apply. For example, you cannot change the `order_id` or `location_id` field and you must provide the complete `custom_fields` list to update a custom field. Published invoices have additional restrictions. update. containing the fields to POST for the request. See the corresponding object definition for field details.
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/square/api/invoices_api.rb', line 231 def update_invoice(invoice_id:, body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/invoices/{invoice_id}' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'invoice_id' => { 'value' => invoice_id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'Content-Type' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.put( _query_url, headers: _headers, parameters: body.to_json ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |