Class: SquareLegacy::OrdersApi

Inherits:
BaseApi
  • Object
show all
Defined in:
lib/square_legacy/api/orders_api.rb

Overview

OrdersApi

Instance Attribute Summary

Attributes inherited from BaseApi

#config, #http_call_back

Instance Method Summary collapse

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 SquareLegacy::BaseApi

Instance Method Details

#batch_retrieve_orders(body:) ⇒ ApiResponse

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. containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • body (BatchRetrieveOrdersRequest)

    Required parameter: An object

Returns:

  • (ApiResponse)

    the complete http response with raw body and status code.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/square_legacy/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.

Parameters:

  • body (CalculateOrderRequest)

    Required parameter: An object

Returns:

  • (ApiResponse)

    the complete http response with raw body and status code.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/square_legacy/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.

Parameters:

  • body (CloneOrderRequest)

    Required parameter: An object containing

Returns:

  • (ApiResponse)

    the complete http response with raw body and status code.



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/square_legacy/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 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. the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • body (CreateOrderRequest)

    Required parameter: An object containing

Returns:

  • (ApiResponse)

    the complete http response with raw body and status code.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/square_legacy/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 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_id when creating the payment. Any approved payments that reference the same order_id not specified in the payment_ids is canceled.
  • Be approved with [delayed capture](https://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.

Parameters:

  • order_id (String)

    Required parameter: The ID of the order being

  • body (PayOrderRequest)

    Required parameter: An object containing the

Returns:

  • (ApiResponse)

    the complete http response with raw body and status code.



231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/square_legacy/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 by ID. retrieve.

Parameters:

  • order_id (String)

    Required parameter: The ID of the order to

Returns:

  • (ApiResponse)

    the complete http response with raw body and status code.



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/square_legacy/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 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. the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • body (SearchOrdersRequest)

    Required parameter: An object containing

Returns:

  • (ApiResponse)

    the complete http response with raw body and status code.



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/square_legacy/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 by adding, replacing, or deleting fields. Orders with a COMPLETED or CANCELED state cannot be updated. An UpdateOrder request requires the following:

Parameters:

  • order_id (String)

    Required parameter: The ID of the order to

  • body (UpdateOrderRequest)

    Required parameter: An object containing

Returns:

  • (ApiResponse)

    the complete http response with raw body and status code.



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/square_legacy/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