Class: NewStoreApi::SalesOrdersController

Inherits:
BaseController show all
Defined in:
lib/new_store_api/controllers/sales_orders_controller.rb

Overview

SalesOrdersController

Constant Summary

Constants inherited from BaseController

BaseController::GLOBAL_ERRORS

Instance Attribute Summary

Attributes inherited from BaseController

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseController

#initialize, #new_parameter, #new_request_builder, #new_response_handler, user_agent

Constructor Details

This class inherits a constructor from NewStoreApi::BaseController

Instance Method Details

#create_bulk_cancel_orders(body) ⇒ SchemaForBulkCancelOrdersResponse

Use this resource to cancel multiple orders in bulk. This endpoint is designed for internal use by NewStore support team / agents. Important Notes:

  • This endpoint temporarily enables DC (Distribution Center) cancellations if not already enabled
  • The original cancellation configuration is automatically restored after processing
  • Orders are assumed to be with ID type 'internal'
  • The response includes both succeeded and failed cancellations with detailed error information
  • Order can only be cancelled if it is in a state that allows cancellation (e.g. not closed, not in fulfillment) Use Cases:
  • Bulk cancellation of orders for customer service scenarios in response to an incident that caused multiple orders to be created with wrong information type description here

Parameters:

Returns:



327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# File 'lib/new_store_api/controllers/sales_orders_controller.rb', line 327

def create_bulk_cancel_orders(body)
  @api_call
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/v0/orders/bulk-cancel',
                                 Server::API)
               .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('oauth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(SchemaForBulkCancelOrdersResponse.method(:from_hash)))
    .execute
end

#create_cancellation(id, id_type, body: nil) ⇒ void

This method returns an undefined value.

Initiates the cancellation of the specified order. When using this method to cancel an order, you must specify a reason for cancellation, such as Item was damaged during shipping. You can also include a note to provide a longer explanation for the cancellation of the order. be used for cancellation. Example "external". description here

Parameters:

  • id (String)

    Required parameter: ID of the order.

  • id_type (String)

    Required parameter: Type of order id which should

  • body (SalesOrderCancellationRequest) (defaults to: nil)

    Optional parameter: TODO: type



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/new_store_api/controllers/sales_orders_controller.rb', line 172

def create_cancellation(id,
                        id_type,
                        body: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/v0/orders/{id}/cancel',
                                 Server::API)
               .template_param(new_parameter(id, key: 'id')
                                .should_encode(true))
               .query_param(new_parameter(id_type, key: 'id_type'))
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('oauth')))
    .response(new_response_handler
                .is_response_void(true))
    .execute
end

#create_conflict_resolution(body: nil) ⇒ OrderConflictResolutionResponse

Process conflicted order and items. For each item, an action can be defined. Actions can be:

  • reroute
  • cancel
  • swap
  • manual_routing Depending on the action, different fields on items are required. They are defined in the schema type description here

Parameters:

Returns:



354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
# File 'lib/new_store_api/controllers/sales_orders_controller.rb', line 354

def create_conflict_resolution(body: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/v0/orders/conflicts',
                                 Server::API)
               .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('oauth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(OrderConflictResolutionResponse.method(:from_hash)))
    .execute
end

#create_grace_period(id, id_type) ⇒ ExtendOrderSGracePeriodTimer

Use this method to extend the grace period timer for the specified order by 15 minutes, if the grace period of the order has not yet expired. should be used to extend the order grace period. Example "external" for human-readable identifiers, and "internal" for system-generated UUIDs (by NewStore).

Parameters:

  • id (String)

    Required parameter: ID of the order.

  • id_type (String)

    Required parameter: Type of the order id which

Returns:



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/new_store_api/controllers/sales_orders_controller.rb', line 121

def create_grace_period(id,
                        id_type)
  @api_call
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/v0/orders/{id}/_extend_grace_period',
                                 Server::API)
               .template_param(new_parameter(id, key: 'id')
                                .should_encode(true))
               .query_param(new_parameter(id_type, key: 'id_type'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('oauth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(ExtendOrderSGracePeriodTimer.method(:from_hash)))
    .execute
end

#create_line_item_cancellation(id, item_uuid, id_type) ⇒ void

This method returns an undefined value.

Use this resource to cancel line items. Note:

  1. This API currently only supports pre-ordered line items and will throw an error for other line items.
  2. The line item can only be cancelled for non-terminal item statuses. be used for cancellation of line items. Example "external" for human-readable identifiers, and "internal" for system-generated UUIDs (by NewStore).

Parameters:

  • id (String)

    Required parameter: UUID of the order.

  • item_uuid (String)

    Required parameter: UUID of the order item.

  • id_type (String)

    Required parameter: Type of order id which should



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/new_store_api/controllers/sales_orders_controller.rb', line 203

def create_line_item_cancellation(id,
                                  item_uuid,
                                  id_type)
  @api_call
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/v0/orders/{id}/items/{item_uuid}/cancel',
                                 Server::API)
               .template_param(new_parameter(id, key: 'id')
                                .should_encode(true))
               .template_param(new_parameter(item_uuid, key: 'item_uuid')
                                .should_encode(true))
               .query_param(new_parameter(id_type, key: 'id_type'))
               .auth(Single.new('oauth')))
    .response(new_response_handler
                .is_response_void(true))
    .execute
end

#create_price_information_for_items(id, body) ⇒ SalesOrderPricesResponse

Use this method to retrieve price information for products or shipping options, defined in items in the request payload. The price information includes the gross price of the item, the net price, and the tax levied on the item. If the prices you requested are for products, the response payload also contains the status of the product. For example, cancelled or pending, or in_fulfillment, and so on. Important: You can only request for the pricing information of a maximum of 500 items, exceeding which the method returns a 400 error. description here

Parameters:

  • id (String)

    Required parameter: The identifier of the order.

  • body (SalesOrderPricesRequest)

    Required parameter: TODO: type

Returns:



237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/new_store_api/controllers/sales_orders_controller.rb', line 237

def create_price_information_for_items(id,
                                       body)
  @api_call
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/v0/orders/{id}/prices',
                                 Server::API)
               .template_param(new_parameter(id, key: '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('oauth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(SalesOrderPricesResponse.method(:from_hash)))
    .execute
end

#show_cancellation_status(id, id_type) ⇒ SalesOrderCancellationResponse

API to get cancellation status by order ID be fetched. Example "external".

Parameters:

  • id (String)

    Required parameter: ID of the order.

  • id_type (String)

    Required parameter: ID type on which order should

Returns:



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/new_store_api/controllers/sales_orders_controller.rb', line 143

def show_cancellation_status(id,
                             id_type)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/v0/orders/{id}/cancel',
                                 Server::API)
               .template_param(new_parameter(id, key: 'id')
                                .should_encode(true))
               .query_param(new_parameter(id_type, key: 'id_type'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('oauth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(SalesOrderCancellationResponse.method(:from_hash)))
    .execute
end

#show_order_history_for_customer(customer_id, offset: 0, count: 10) ⇒ SalesOrderListResponse

ℹ️ Rate Limit: This endpoint is rate limited to 30 requests per second.
the customer resulting order list. Will only be accepted when using the ``Accept`` header with ``application/x.newstore.orders+json;version=2``. Will only be accepted when using the ``Accept`` header with ``application/x.newstore.orders+json;version=2``.

Parameters:

  • customer_id (String)

    Required parameter: NewStore's unique UUID for

  • offset (Integer) (defaults to: 0)

    Optional parameter: The offset to be used for the

  • count (Integer) (defaults to: 10)

    Optional parameter: The number of requested orders.

Returns:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/new_store_api/controllers/sales_orders_controller.rb', line 24

def show_order_history_for_customer(customer_id,
                                    offset: 0,
                                    count: 10)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/v0/orders',
                                 Server::API)
               .query_param(new_parameter(customer_id, key: 'customer_id'))
               .query_param(new_parameter(offset, key: 'offset'))
               .query_param(new_parameter(count, key: 'count'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('oauth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(SalesOrderListResponse.method(:from_hash)))
    .execute
end

#show_sales_order_by_id_and_id_type(id, id_type, accept: nil) ⇒ SalesOrderDetailResponse

ℹ️ Rate Limit: This endpoint is rate limited to 100 requests per second.
Retrieves the specified order by order ID and ID type for the order. This method allows you to retrieve information about orders that were placed in the platform, as well as outside of the NewStore platform. **Note**: In case of ``internal`` id type the API will only return orders that exists in the NewStore database and will **NOT** call the external OMS webhook. Furthermore, the `payment_history` field will be empty in this case. In case of ``external`` id type this API will check if the external OMS webhook is configured. In this case the API will fetch the order data from the configured webhook. If no external OMS is configured then the order will be fetched from the NewStore database. be fetched. Example "external" in case of human-readable identifier of the order, else "internal" in case of system-generated UUID (by NewStore). ``application/json`` and ``application/x.newstore.orders+json;version=2``. When ``application/x.newstore.orders+json;version=2`` is provided, the ``placed_at`` timestamp is returned with UTC+0.

Parameters:

  • id (String)

    Required parameter: ID of the order.

  • id_type (String)

    Required parameter: ID type on which order should

  • accept (String) (defaults to: nil)

    Optional parameter: Accepted values are

Returns:



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/new_store_api/controllers/sales_orders_controller.rb', line 69

def show_sales_order_by_id_and_id_type(id,
                                       id_type,
                                       accept: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/v0/orders/{id}',
                                 Server::API)
               .template_param(new_parameter(id, key: 'id')
                                .should_encode(true))
               .query_param(new_parameter(id_type, key: 'id_type'))
               .header_param(new_parameter(accept, key: 'Accept'))
               .auth(Single.new('oauth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(SalesOrderDetailResponse.method(:from_hash)))
    .execute
end

#update_order_service_level(body, id) ⇒ Object

Sets a new service level for conflict items in the specified order. description here

Parameters:

  • body (UpdateServiceLevelRequest)

    Required parameter: TODO: type

  • id (String)

    Required parameter: TODO: type description here

Returns:

  • (Object)

    Response from the API call.



290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/new_store_api/controllers/sales_orders_controller.rb', line 290

def update_order_service_level(body,
                               id)
  @api_call
    .request(new_request_builder(HttpMethodEnum::PATCH,
                                 '/v0/orders/{id}/service_level',
                                 Server::API)
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .template_param(new_parameter(id, key: 'id')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('oauth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:json_deserialize)))
    .execute
end

#update_sales_order(id, body) ⇒ void

This method returns an undefined value.

Updates specific fields of an order. Supported updates:

  • Order Status here

Parameters:

  • id (String)

    Required parameter: ID of the order.

  • body (V0OrdersRequest)

    Required parameter: TODO: type description



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/new_store_api/controllers/sales_orders_controller.rb', line 94

def update_sales_order(id,
                       body)
  @api_call
    .request(new_request_builder(HttpMethodEnum::PATCH,
                                 '/v0/orders/{id}',
                                 Server::API)
               .template_param(new_parameter(id, key: 'id')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('oauth')))
    .response(new_response_handler
                .is_response_void(true))
    .execute
end

#update_sales_order_serial_numbers(id, body) ⇒ void

This method returns an undefined value.

Use this method to add serial numbers to specified items of the order. Serial numbers will be overwritten in case some or all of the items have already serial numbers attached. The maximum number of items in this request cannot exceed 500, otherwise this method will return a 400 error. order, for example, b604ffda-7e31-4338-beab-7f939a8c2322. type description here

Parameters:



266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/new_store_api/controllers/sales_orders_controller.rb', line 266

def update_sales_order_serial_numbers(id,
                                      body)
  @api_call
    .request(new_request_builder(HttpMethodEnum::PATCH,
                                 '/v0/orders/{id}/serial_numbers',
                                 Server::API)
               .template_param(new_parameter(id, key: 'id')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('oauth')))
    .response(new_response_handler
                .is_response_void(true))
    .execute
end