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:) ⇒ ApiResponse
Retrieves a set of [orders]($m/Order) by their IDs.
-
#calculate_order(body:) ⇒ ApiResponse
Enables applications to preview order pricing without creating an order.
-
#clone_order(body:) ⇒ ApiResponse
Creates a new order, in the ‘DRAFT` state, by duplicating an existing order.
-
#create_order(body:) ⇒ ApiResponse
Creates a new [order]($m/Order) that can include information about products for purchase and settings to apply to the purchase.
-
#pay_order(order_id:, body:) ⇒ ApiResponse
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:) ⇒ ApiResponse
Retrieves an [Order]($m/Order) by ID.
-
#search_orders(body:) ⇒ ApiResponse
Search all orders for one or more locations.
-
#update_order(order_id:, body:) ⇒ ApiResponse
Updates an open [order]($m/Order) by adding, replacing, or deleting fields.
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
#batch_retrieve_orders(body:) ⇒ ApiResponse
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.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/square/api/orders_api.rb', line 40 def batch_retrieve_orders(body:) new_api_call_builder .request(new_request_builder(HttpMethodEnum::POST, '/v2/orders/batch-retrieve', '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 |
#calculate_order(body:) ⇒ ApiResponse
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.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/square/api/orders_api.rb', line 62 def calculate_order(body:) new_api_call_builder .request(new_request_builder(HttpMethodEnum::POST, '/v2/orders/calculate', '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 |
#clone_order(body:) ⇒ ApiResponse
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.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/square/api/orders_api.rb', line 87 def clone_order(body:) new_api_call_builder .request(new_request_builder(HttpMethodEnum::POST, '/v2/orders/clone', '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_order(body:) ⇒ ApiResponse
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.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/square/api/orders_api.rb', line 16 def create_order(body:) new_api_call_builder .request(new_request_builder(HttpMethodEnum::POST, '/v2/orders', '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 |
#pay_order(order_id:, body:) ⇒ ApiResponse
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.
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/square/api/orders_api.rb', line 231 def pay_order(order_id:, body:) new_api_call_builder .request(new_request_builder(HttpMethodEnum::POST, '/v2/orders/{order_id}/pay', 'default') .template_param(new_parameter(order_id, key: 'order_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 |
#retrieve_order(order_id:) ⇒ ApiResponse
Retrieves an [Order]($m/Order) by ID. retrieve.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/square/api/orders_api.rb', line 146 def retrieve_order(order_id:) new_api_call_builder .request(new_request_builder(HttpMethodEnum::GET, '/v2/orders/{order_id}', 'default') .template_param(new_parameter(order_id, key: 'order_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 |
#search_orders(body:) ⇒ ApiResponse
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.
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/square/api/orders_api.rb', line 125 def search_orders(body:) new_api_call_builder .request(new_request_builder(HttpMethodEnum::POST, '/v2/orders/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_order(order_id:, body:) ⇒ ApiResponse
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/update -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/update -orders#identifying-fields-to-delete) 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.
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 186 def update_order(order_id:, body:) new_api_call_builder .request(new_request_builder(HttpMethodEnum::PUT, '/v2/orders/{order_id}', 'default') .template_param(new_parameter(order_id, key: 'order_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 |