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:) ⇒ ApiResponse
Cancels an invoice.
-
#create_invoice(body:) ⇒ ApiResponse
Creates a draft [invoice]($m/Invoice) for an order created using the Orders API.
-
#create_invoice_attachment(invoice_id:, request: nil, image_file: nil) ⇒ ApiResponse
Uploads a file and attaches it to an invoice.
-
#delete_invoice(invoice_id:, version: nil) ⇒ ApiResponse
Deletes the specified invoice.
-
#delete_invoice_attachment(invoice_id:, attachment_id:) ⇒ ApiResponse
Removes an attachment from an invoice and permanently deletes the file.
-
#get_invoice(invoice_id:) ⇒ ApiResponse
Retrieves an invoice by invoice ID.
-
#list_invoices(location_id:, cursor: nil, limit: nil) ⇒ ApiResponse
Returns a list of invoices for a given location.
-
#publish_invoice(invoice_id:, body:) ⇒ ApiResponse
Publishes the specified draft invoice.
-
#search_invoices(body:) ⇒ ApiResponse
Searches for invoices from a location specified in the filter.
-
#update_invoice(invoice_id:, body:) ⇒ ApiResponse
Updates an invoice.
Methods inherited from BaseApi
#initialize, #new_api_call_builder, #new_parameter, #new_request_builder, #new_response_handler, user_agent, user_agent_parameters
Constructor Details
This class inherits a constructor from Square::BaseApi
Instance Method Details
#cancel_invoice(invoice_id:, body:) ⇒ ApiResponse
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](entity:Invoice) to cancel. containing the fields to POST for the request. See the corresponding object definition for field details.
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/square/api/invoices_api.rb', line 248 def cancel_invoice(invoice_id:, body:) new_api_call_builder .request(new_request_builder(HttpMethodEnum::POST, '/v2/invoices/{invoice_id}/cancel', 'default') .template_param(new_parameter(invoice_id, key: 'invoice_id') .should_encode(true)) .header_param(new_parameter('application/json', key: 'Content-Type')) .body_param(new_parameter(body)) .header_param(new_parameter('application/json', key: 'accept')) .body_serializer(proc do |param| param.to_json unless param.nil? end) .auth(Single.new('global'))) .response(new_response_handler .deserializer(APIHelper.method(:json_deserialize)) .is_api_response(true) .convertor(ApiResponse.method(:create))) .execute end |
#create_invoice(body:) ⇒ ApiResponse
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.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/square/api/invoices_api.rb', line 46 def create_invoice(body:) new_api_call_builder .request(new_request_builder(HttpMethodEnum::POST, '/v2/invoices', 'default') .header_param(new_parameter('application/json', key: 'Content-Type')) .body_param(new_parameter(body)) .header_param(new_parameter('application/json', key: 'accept')) .body_serializer(proc do |param| param.to_json unless param.nil? end) .auth(Single.new('global'))) .response(new_response_handler .deserializer(APIHelper.method(:json_deserialize)) .is_api_response(true) .convertor(ApiResponse.method(:create))) .execute end |
#create_invoice_attachment(invoice_id:, request: nil, image_file: nil) ⇒ ApiResponse
Uploads a file and attaches it to an invoice. This endpoint accepts HTTP multipart/form-data file uploads with a JSON ‘request` part and a `file` part. The `file` part must be a `readable stream` that contains a file in a supported format: GIF, JPEG, PNG, TIFF, BMP, or PDF. Invoices can have up to 10 attachments with a total file size of 25 MB. Attachments can be added only to invoices in the `DRAFT`, `SCHEDULED`, `UNPAID`, or `PARTIALLY_PAID` state. [invoice](entity:Invoice) to attach the file to. Represents a [CreateInvoiceAttachment]($e/Invoices/CreateInvoiceAttachment) request.
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/square/api/invoices_api.rb', line 188 def (invoice_id:, request: nil, image_file: nil) new_api_call_builder .request(new_request_builder(HttpMethodEnum::POST, '/v2/invoices/{invoice_id}/attachments', 'default') .template_param(new_parameter(invoice_id, key: 'invoice_id') .should_encode(true)) .multipart_param(new_parameter(StringIO.new(request.to_json), key: 'request') .default_content_type('application/json; charset=utf-8')) .multipart_param(new_parameter(image_file, key: 'image_file') .default_content_type('image/jpeg')) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('global'))) .response(new_response_handler .deserializer(APIHelper.method(:json_deserialize)) .is_api_response(true) .convertor(ApiResponse.method(:create))) .execute end |
#delete_invoice(invoice_id:, version: nil) ⇒ ApiResponse
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](entity:Invoice) to delete. If you do not know the version, you can call [GetInvoice](api-endpoint:Invoices-GetInvoice) or [ListInvoices](api-endpoint:Invoices-ListInvoices).
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/square/api/invoices_api.rb', line 102 def delete_invoice(invoice_id:, version: nil) new_api_call_builder .request(new_request_builder(HttpMethodEnum::DELETE, '/v2/invoices/{invoice_id}', 'default') .template_param(new_parameter(invoice_id, key: 'invoice_id') .should_encode(true)) .query_param(new_parameter(version, key: 'version')) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('global'))) .response(new_response_handler .deserializer(APIHelper.method(:json_deserialize)) .is_api_response(true) .convertor(ApiResponse.method(:create))) .execute end |
#delete_invoice_attachment(invoice_id:, attachment_id:) ⇒ ApiResponse
Removes an attachment from an invoice and permanently deletes the file. Attachments can be removed only from invoices in the ‘DRAFT`, `SCHEDULED`, `UNPAID`, or `PARTIALLY_PAID` state. [invoice](entity:Invoice) to delete the attachment from. [attachment](entity:InvoiceAttachment) to delete.
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/square/api/invoices_api.rb', line 219 def (invoice_id:, attachment_id:) new_api_call_builder .request(new_request_builder(HttpMethodEnum::DELETE, '/v2/invoices/{invoice_id}/attachments/{attachment_id}', 'default') .template_param(new_parameter(invoice_id, key: 'invoice_id') .should_encode(true)) .template_param(new_parameter(, key: 'attachment_id') .should_encode(true)) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('global'))) .response(new_response_handler .deserializer(APIHelper.method(:json_deserialize)) .is_api_response(true) .convertor(ApiResponse.method(:create))) .execute end |
#get_invoice(invoice_id:) ⇒ ApiResponse
Retrieves an invoice by invoice ID. retrieve.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/square/api/invoices_api.rb', line 124 def get_invoice(invoice_id:) new_api_call_builder .request(new_request_builder(HttpMethodEnum::GET, '/v2/invoices/{invoice_id}', 'default') .template_param(new_parameter(invoice_id, key: 'invoice_id') .should_encode(true)) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('global'))) .response(new_response_handler .deserializer(APIHelper.method(:json_deserialize)) .is_api_response(true) .convertor(ApiResponse.method(:create))) .execute end |
#list_invoices(location_id:, cursor: nil, limit: nil) ⇒ ApiResponse
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/build-basics/common-api-p atterns/pagination). to return (200 is the maximum `limit`). If not provided, the server uses a default limit of 100 invoices.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/square/api/invoices_api.rb', line 18 def list_invoices(location_id:, cursor: nil, limit: nil) new_api_call_builder .request(new_request_builder(HttpMethodEnum::GET, '/v2/invoices', 'default') .query_param(new_parameter(location_id, key: 'location_id')) .query_param(new_parameter(cursor, key: 'cursor')) .query_param(new_parameter(limit, key: 'limit')) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('global'))) .response(new_response_handler .deserializer(APIHelper.method(:json_deserialize)) .is_api_response(true) .convertor(ApiResponse.method(:create))) .execute end |
#publish_invoice(invoice_id:, body:) ⇒ ApiResponse
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 charges a card on file for a portion of the invoice amount. In addition to the required `ORDERS_WRITE` and `INVOICES_WRITE` permissions, `CUSTOMERS_READ` and `PAYMENTS_WRITE` are required when publishing invoices configured for card-on-file payments. publish. containing the fields to POST for the request. See the corresponding object definition for field details.
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'lib/square/api/invoices_api.rb', line 291 def publish_invoice(invoice_id:, body:) new_api_call_builder .request(new_request_builder(HttpMethodEnum::POST, '/v2/invoices/{invoice_id}/publish', 'default') .template_param(new_parameter(invoice_id, key: 'invoice_id') .should_encode(true)) .header_param(new_parameter('application/json', key: 'Content-Type')) .body_param(new_parameter(body)) .header_param(new_parameter('application/json', key: 'accept')) .body_serializer(proc do |param| param.to_json unless param.nil? end) .auth(Single.new('global'))) .response(new_response_handler .deserializer(APIHelper.method(:json_deserialize)) .is_api_response(true) .convertor(ApiResponse.method(:create))) .execute end |
#search_invoices(body:) ⇒ ApiResponse
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.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/square/api/invoices_api.rb', line 74 def search_invoices(body:) new_api_call_builder .request(new_request_builder(HttpMethodEnum::POST, '/v2/invoices/search', 'default') .header_param(new_parameter('application/json', key: 'Content-Type')) .body_param(new_parameter(body)) .header_param(new_parameter('application/json', key: 'accept')) .body_serializer(proc do |param| param.to_json unless param.nil? end) .auth(Single.new('global'))) .response(new_response_handler .deserializer(APIHelper.method(:json_deserialize)) .is_api_response(true) .convertor(ApiResponse.method(:create))) .execute end |
#update_invoice(invoice_id:, body:) ⇒ ApiResponse
Updates an invoice. This endpoint supports sparse updates, so you only need to specify the fields you want to change along with the required ‘version` field. Some restrictions apply to updating invoices. For example, you cannot change the `order_id` or `location_id` field. update. containing the fields to POST for the request. See the corresponding object definition for field details.
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/square/api/invoices_api.rb', line 153 def update_invoice(invoice_id:, body:) new_api_call_builder .request(new_request_builder(HttpMethodEnum::PUT, '/v2/invoices/{invoice_id}', 'default') .template_param(new_parameter(invoice_id, key: 'invoice_id') .should_encode(true)) .header_param(new_parameter('application/json', key: 'Content-Type')) .body_param(new_parameter(body)) .header_param(new_parameter('application/json', key: 'accept')) .body_serializer(proc do |param| param.to_json unless param.nil? end) .auth(Single.new('global'))) .response(new_response_handler .deserializer(APIHelper.method(:json_deserialize)) .is_api_response(true) .convertor(ApiResponse.method(:create))) .execute end |