Class: Square::Orders::Client
- Inherits:
-
Object
- Object
- Square::Orders::Client
- Defined in:
- lib/square/orders/client.rb
Instance Method Summary collapse
-
#batch_get(request_options: {}, **params) ⇒ Square::Types::BatchGetOrdersResponse
Retrieves a set of [orders](entity:Order) by their IDs.
-
#calculate(request_options: {}, **params) ⇒ Square::Types::CalculateOrderResponse
Enables applications to preview order pricing without creating an order.
-
#clone(request_options: {}, **params) ⇒ Square::Types::CloneOrderResponse
Creates a new order, in the ‘DRAFT` state, by duplicating an existing order.
-
#create(request_options: {}, **params) ⇒ Square::Types::CreateOrderResponse
Creates a new [order](entity:Order) that can include information about products for purchase and settings to apply to the purchase.
- #custom_attribute_definitions ⇒ Square::CustomAttributeDefinitions::Client
- #custom_attributes ⇒ Square::CustomAttributes::Client
-
#get(request_options: {}, **params) ⇒ Square::Types::GetOrderResponse
Retrieves an [Order](entity:Order) by ID.
- #initialize(client:) ⇒ Square::Orders::Client constructor
-
#pay(request_options: {}, **params) ⇒ Square::Types::PayOrderResponse
Pay for an [order](entity:Order) using one or more approved [payments](entity:Payment) or settle an order with a total of ‘0`.
-
#search(request_options: {}, **params) ⇒ Square::Types::SearchOrdersResponse
Search all orders for one or more locations.
-
#update(request_options: {}, **params) ⇒ Square::Types::UpdateOrderResponse
Updates an open [order](entity:Order) by adding, replacing, or deleting fields.
Constructor Details
#initialize(client:) ⇒ Square::Orders::Client
7 8 9 |
# File 'lib/square/orders/client.rb', line 7 def initialize(client:) @client = client end |
Instance Method Details
#batch_get(request_options: {}, **params) ⇒ Square::Types::BatchGetOrdersResponse
Retrieves a set of [orders](entity:Order) by their IDs.
If a given order ID does not exist, the ID is ignored instead of generating an error.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/square/orders/client.rb', line 40 def batch_get(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "POST", path: "v2/orders/batch-retrieve", body: params ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::BatchGetOrdersResponse.load(_response.body) end raise _response.body end |
#calculate(request_options: {}, **params) ⇒ Square::Types::CalculateOrderResponse
Enables applications to preview order pricing without creating an order.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/square/orders/client.rb', line 58 def calculate(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "POST", path: "v2/orders/calculate", body: params ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::CalculateOrderResponse.load(_response.body) end raise _response.body end |
#clone(request_options: {}, **params) ⇒ Square::Types::CloneOrderResponse
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.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/square/orders/client.rb', line 77 def clone(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "POST", path: "v2/orders/clone", body: params ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::CloneOrderResponse.load(_response.body) end raise _response.body end |
#create(request_options: {}, **params) ⇒ Square::Types::CreateOrderResponse
Creates a new [order](entity: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](api-endpoint:Orders-UpdateOrder) endpoint.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/square/orders/client.rb', line 20 def create(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "POST", path: "v2/orders", body: Square::Types::CreateOrderRequest.new(params).to_h ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::CreateOrderResponse.load(_response.body) end raise _response.body end |
#custom_attribute_definitions ⇒ Square::CustomAttributeDefinitions::Client
207 208 209 |
# File 'lib/square/orders/client.rb', line 207 def custom_attribute_definitions @custom_attribute_definitions ||= Square::Orders::CustomAttributeDefinitions::Client.new(client: @client) end |
#custom_attributes ⇒ Square::CustomAttributes::Client
212 213 214 |
# File 'lib/square/orders/client.rb', line 212 def custom_attributes @custom_attributes ||= Square::Orders::CustomAttributes::Client.new(client: @client) end |
#get(request_options: {}, **params) ⇒ Square::Types::GetOrderResponse
Retrieves an [Order](entity:Order) by ID.
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/square/orders/client.rb', line 129 def get(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "GET", path: "v2/orders/#{params[:order_id]}" ) _response = @client.send(_request) return Square::Types::GetOrderResponse.load(_response.body) if _response.code >= "200" && _response.code < "300" raise _response.body end |
#pay(request_options: {}, **params) ⇒ Square::Types::PayOrderResponse
Pay for an [order](entity:Order) using one or more approved [payments](entity: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](api-endpoint: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/card-payments/delayed-capture).
Using a delayed capture payment with ‘PayOrder` completes the approved payment.
191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/square/orders/client.rb', line 191 def pay(request_options: {}, **params) _path_param_names = ["order_id"] _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "POST", path: "v2/orders/#{params[:order_id]}/pay", body: params.except(*_path_param_names) ) _response = @client.send(_request) return Square::Types::PayOrderResponse.load(_response.body) if _response.code >= "200" && _response.code < "300" raise _response.body end |
#search(request_options: {}, **params) ⇒ Square::Types::SearchOrdersResponse
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](entity: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](entity: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.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/square/orders/client.rb', line 111 def search(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "POST", path: "v2/orders/search", body: params ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::SearchOrdersResponse.load(_response.body) end raise _response.body end |
#update(request_options: {}, **params) ⇒ Square::Types::UpdateOrderResponse
Updates an open [order](entity: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).
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/square/orders/client.rb', line 158 def update(request_options: {}, **params) _path_param_names = ["order_id"] _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "PUT", path: "v2/orders/#{params[:order_id]}", body: params.except(*_path_param_names) ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::UpdateOrderResponse.load(_response.body) end raise _response.body end |