Class: Square::OrdersApi
- Defined in:
- lib/square/api/orders_api.rb
Overview
OrdersApi
Instance Attribute Summary
Attributes inherited from BaseApi
Instance Method Summary collapse
-
#batch_retrieve_orders(body:) ⇒ BatchRetrieveOrdersResponse Hash
Retrieves a set of [orders]($m/Order) by their IDs.
-
#calculate_order(body:) ⇒ CalculateOrderResponse Hash
Enables applications to preview order pricing without creating an order.
-
#clone_order(body:) ⇒ CloneOrderResponse Hash
Creates a new order, in the ‘DRAFT` state, by duplicating an existing order.
-
#create_order(body:) ⇒ CreateOrderResponse Hash
Creates a new [order]($m/Order) that can include information about products for purchase and settings to apply to the purchase.
-
#initialize(config, http_call_back: nil) ⇒ OrdersApi
constructor
A new instance of OrdersApi.
-
#pay_order(order_id:, body:) ⇒ PayOrderResponse Hash
Pay for an [order]($m/Order) using one or more approved [payments]($m/Payment) or settle an order with a total of ‘0`.
-
#retrieve_order(order_id:) ⇒ RetrieveOrderResponse Hash
Retrieves an [Order]($m/Order) by ID.
-
#search_orders(body:) ⇒ SearchOrdersResponse Hash
Search all orders for one or more locations.
-
#update_order(order_id:, body:) ⇒ UpdateOrderResponse Hash
Updates an open [order]($m/Order) by adding, replacing, or deleting fields.
Methods inherited from BaseApi
#execute_request, #get_user_agent, #validate_parameters
Constructor Details
#initialize(config, http_call_back: nil) ⇒ OrdersApi
Returns a new instance of OrdersApi.
4 5 6 |
# File 'lib/square/api/orders_api.rb', line 4 def initialize(config, http_call_back: nil) super(config, http_call_back: http_call_back) end |
Instance Method Details
#batch_retrieve_orders(body:) ⇒ BatchRetrieveOrdersResponse Hash
Retrieves a set of [orders]($m/Order) by their IDs. If a given order ID does not exist, the ID is ignored instead of generating an error. containing the fields to POST for the request. See the corresponding object definition for field details.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/square/api/orders_api.rb', line 56 def batch_retrieve_orders(body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/orders/batch-retrieve' _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 |
#calculate_order(body:) ⇒ CalculateOrderResponse Hash
Enables applications to preview order pricing without creating an order. containing the fields to POST for the request. See the corresponding object definition for field details.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/square/api/orders_api.rb', line 90 def calculate_order(body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/orders/calculate' _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 |
#clone_order(body:) ⇒ CloneOrderResponse Hash
Creates a new order, in the ‘DRAFT` state, by duplicating an existing order. The newly created order has only the core fields (such as line items, taxes, and discounts) copied from the original order. the fields to POST for the request. See the corresponding object definition for field details.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/square/api/orders_api.rb', line 127 def clone_order(body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/orders/clone' _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_order(body:) ⇒ CreateOrderResponse Hash
Creates a new [order]($m/Order) that can include information about products for purchase and settings to apply to the purchase. To pay for a created order, see [Pay for Orders](developer.squareup.com/docs/orders-api/pay-for-orders). You can modify open orders using the [UpdateOrder]($e/Orders/UpdateOrder) endpoint. the fields to POST for the request. See the corresponding object definition for field details.
20 21 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 |
# File 'lib/square/api/orders_api.rb', line 20 def create_order(body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/orders' _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 |
#pay_order(order_id:, body:) ⇒ PayOrderResponse Hash
Pay for an [order]($m/Order) using one or more approved [payments]($m/Payment) or settle an order with a total of ‘0`. The total of the `payment_ids` listed in the request must be equal to the order total. Orders with a total amount of `0` can be marked as paid by specifying an empty array of `payment_ids` in the request. To be used with `PayOrder`, a payment must:
-
Reference the order by specifying the ‘order_id` when [creating the
payment]($e/Payments/CreatePayment). Any approved payments that reference the same ‘order_id` not specified in the `payment_ids` is canceled.
-
Be approved with [delayed
capture](developer.squareup.com/docs/payments-api/take-payments/ca rd-payments/delayed-capture). Using a delayed capture payment with ‘PayOrder` completes the approved payment. paid. fields to POST for the request. See the corresponding object definition for field details.
324 325 326 327 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 |
# File 'lib/square/api/orders_api.rb', line 324 def pay_order(order_id:, body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/orders/{order_id}/pay' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'order_id' => { 'value' => order_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 |
#retrieve_order(order_id:) ⇒ RetrieveOrderResponse Hash
Retrieves an [Order]($m/Order) by ID. retrieve.
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/square/api/orders_api.rb', line 210 def retrieve_order(order_id:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/orders/{order_id}' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'order_id' => { 'value' => order_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 |
#search_orders(body:) ⇒ SearchOrdersResponse Hash
Search all orders for one or more locations. Orders include all sales, returns, and exchanges regardless of how or when they entered the Square ecosystem (such as Point of Sale, Invoices, and Connect APIs). ‘SearchOrders` requests need to specify which locations to search and define a [SearchOrdersQuery]($m/SearchOrdersQuery) object that controls how to sort or filter the results. Your `SearchOrdersQuery` can:
Set filter criteria.
Set the sort order.
Determine whether to return results as complete `Order` objects or as
[OrderEntry]($m/OrderEntry) objects. Note that details for orders processed with Square Point of Sale while in offline mode might not be transmitted to Square for up to 72 hours. Offline orders have a ‘created_at` value that reflects the time the order was created, not the time it was subsequently transmitted to Square. the fields to POST for the request. See the corresponding object definition for field details.
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/square/api/orders_api.rb', line 177 def search_orders(body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/orders/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_order(order_id:, body:) ⇒ UpdateOrderResponse Hash
Updates an open [order]($m/Order) by adding, replacing, or deleting fields. Orders with a ‘COMPLETED` or `CANCELED` state cannot be updated. An `UpdateOrder` request requires the following:
-
The ‘order_id` in the endpoint path, identifying the order to update.
-
The latest ‘version` of the order to update.
-
The [sparse
order](developer.squareup.com/docs/orders-api/manage-orders#sparse -order-objects) containing only the fields to update and the version to which the update is being applied.
-
If deleting fields, the [dot notation
paths](developer.squareup.com/docs/orders-api/manage-orders#on-dot -notation) identifying the fields to clear. To pay for an order, see [Pay for Orders](developer.squareup.com/docs/orders-api/pay-for-orders). update. the fields to POST for the request. See the corresponding object definition for field details.
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/square/api/orders_api.rb', line 265 def update_order(order_id:, body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/orders/{order_id}' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'order_id' => { 'value' => order_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 |