Class: NewStoreApi::OrderInjectionController

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

Overview

OrderInjectionController

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_injected_order(body) ⇒ InjectedOrderResponse

ℹ️ Rate Limit: This endpoint is rate limited to 20 requests per second.
Creates an order in NewStore by importing an order placed via an external system. This is also referred as *injecting an order*. Each request creates a single order in NewStore. The request payload depends on the order you are creating. For example: - A pre-routed order relies on a `routing strategy` defined with the [fulfillment configuration](/newstore-cloud/newstore.html#fulfillment-configuration). - An in-store pickup order relies on the `in-store configuration` defined with the [in-store pickup config resource](/newstore-cloud/store_operations/in_store_pickup.html). This method is idempotent, with regards to the `external_id` property. You can use the method multiple times to create the same order in the platform. The order itself is created only once, with the same response payload returned every time. There can be transient errors (`500`) when creating an order, such as a timeout when communicating with the shipping provider. To fix these errors, retry the method again with the same payload. **Important**: - Ensure that the request payload is same when creating an order with several tries. A retry with the same `external_id` but a different payload will fail. - Ensure that there is a small delay between each retry. - Only the `200` response implies that the order has been created correctly. Therefore, ensure that your integration has a retry logic set up. For more information, see the request examples and [Importing orders](https://docs.newstore.com/docs/importing-orders). **Add-ons** An item can be declared as an add-on of another item by setting `shipments[].items[].addon_parent_external_item_id` to the `external_item_id` of the parent item. The add-on is created as a separate line item linked to that parent and carries its own price. The parent must be a non-add-on item in the **same shipment**; add-ons cannot be nested (the parent must not itself be an add-on) and an item cannot reference itself. A reference that breaks these rules is rejected with `400` (error code `addon_invalid_parent_item`). An add-on's own and its parent's `external_item_id` must be unique across the whole order; a duplicate makes the linkage ambiguous and is rejected with `400` (error code `addon_duplicate_external_item_id`). **Configuration** There are two configuration settings that impact injection flow: `big_sales_order` and `skip_soft_routing_on_injection`. For more information, see the page with all [order_injection configuration](https://docs.newstore.net/api/configuration/order-managemen t/order_injection_admin/#tag/Injection-configuration/operation/updateConfi g). **Notes:** - Ensure that you specify the correct number of decimal places for monetary values of prices, according to the specified currency. For example, if the currency is specified as ``USD`` and the price has more than 2 decimal places, it is considered as invalid by the platform. For more information, see [pricing dependencies on currency](https://docs.newstore.com/v1/docs/set-up-payments#managing-produ ct-pricing-dependencies-on-currency). - To send payment-related metadata with the order, use the [Create financial instrument](https://docs.newstore.net/api/webhooks/fat_psp_hook/#operation /createFinancialInstrument) method in the Payment Provider webhooks. - The validity of a shipping offer token can vary based on the shipping provider and shipping offer. For `in-store pickup` orders, a shipping offer token does not expire. - If you set `shipments[].shipment_option.routing_strategy` as "external" and the routing failed to communicate with shipping provider, the order will be cancelled. Check shipping provider integration, if you have customer integration, otherwise contact team delivery for support. - If the customer's phone number does not have a country calling code, the platform will attempt to use the billing address country code to derive the calling code while formatting the phone number to the E.164 standard. If the phone number cannot be formatted, it will be placed in the extended attribute `injected-invalid-phone-number` on customer profile. It can be updated later, if needed. description here

Parameters:

Returns:



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/new_store_api/controllers/order_injection_controller.rb', line 109

def create_injected_order(body)
  @api_call
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/v0/d/fulfill_order',
                                 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(InjectedOrderResponse.method(:from_hash)))
    .execute
end