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 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
DRAFTstate, by duplicating an existing order. -
#create(request_options: {}, **params) ⇒ Square::Types::CreateOrderResponse
Creates a new 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 by ID.
- #initialize(client:) ⇒ void constructor
- #pay(request_options: {}, **params) ⇒ Square::Types::PayOrderResponse
-
#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 by adding, replacing, or deleting fields.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/square/orders/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#batch_get(request_options: {}, **params) ⇒ Square::Types::BatchGetOrdersResponse
Retrieves a set of orders by their IDs.
If a given order ID does not exist, the ID is ignored instead of generating an error.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/square/orders/client.rb', line 66 def batch_get(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/orders/batch-retrieve", body: Square::Orders::Types::BatchGetOrdersRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::BatchGetOrdersResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#calculate(request_options: {}, **params) ⇒ Square::Types::CalculateOrderResponse
Enables applications to preview order pricing without creating an order.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/square/orders/client.rb', line 100 def calculate(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/orders/calculate", body: Square::Orders::Types::CalculateOrderRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::CalculateOrderResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end 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.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/square/orders/client.rb', line 135 def clone(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/orders/clone", body: Square::Orders::Types::CloneOrderRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::CloneOrderResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#create(request_options: {}, **params) ⇒ Square::Types::CreateOrderResponse
Creates a new 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.
You can modify open orders using the UpdateOrder endpoint.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/square/orders/client.rb', line 30 def create(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/orders", body: Square::Types::CreateOrderRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::CreateOrderResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#custom_attribute_definitions ⇒ Square::CustomAttributeDefinitions::Client
352 353 354 |
# File 'lib/square/orders/client.rb', line 352 def custom_attribute_definitions @custom_attribute_definitions ||= Square::Orders::CustomAttributeDefinitions::Client.new(client: @client) end |
#custom_attributes ⇒ Square::CustomAttributes::Client
357 358 359 |
# File 'lib/square/orders/client.rb', line 357 def custom_attributes @custom_attributes ||= Square::Orders::CustomAttributes::Client.new(client: @client) end |
#get(request_options: {}, **params) ⇒ Square::Types::GetOrderResponse
Retrieves an Order by ID.
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/square/orders/client.rb', line 220 def get(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/orders/#{params[:order_id]}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::GetOrderResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#pay(request_options: {}, **params) ⇒ Square::Types::PayOrderResponse
Pay for an order using one or more approved payments
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_idwhen creating the payment. Any approved payments that reference the sameorder_idnot specified in thepayment_idsis canceled. - Be approved with delayed
capture.
Using a delayed capture payment with
PayOrdercompletes the approved payment.
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 |
# File 'lib/square/orders/client.rb', line 324 def pay(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request_data = Square::Orders::Types::PayOrderRequest.new(params).to_h non_body_param_names = ["order_id"] body = request_data.except(*non_body_param_names) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/orders/#{params[:order_id]}/pay", body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::PayOrderResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end 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 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 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.
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/square/orders/client.rb', line 185 def search(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/orders/search", body: Square::Orders::Types::SearchOrdersRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::SearchOrdersResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#update(request_options: {}, **params) ⇒ Square::Types::UpdateOrderResponse
Updates an open 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_idin the endpoint path, identifying the order to update. - The latest
versionof the order to update. - The sparse order containing only the fields to update and the version to which the update is being applied.
- If deleting fields, the dot notation paths identifying the fields to clear.
To pay for an order, see Pay for Orders.
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 |
# File 'lib/square/orders/client.rb', line 270 def update(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request_data = Square::Orders::Types::UpdateOrderRequest.new(params).to_h non_body_param_names = ["order_id"] body = request_data.except(*non_body_param_names) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "PUT", path: "v2/orders/#{params[:order_id]}", body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::UpdateOrderResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |