Class: NewStoreApi::ReservationsController
- Inherits:
-
BaseController
- Object
- BaseController
- NewStoreApi::ReservationsController
- Defined in:
- lib/new_store_api/controllers/reservations_controller.rb
Overview
ReservationsController
Constant Summary
Constants inherited from BaseController
Instance Attribute Summary
Attributes inherited from BaseController
Instance Method Summary collapse
-
#create_reservation(idempotency_key, body: nil) ⇒ Object
Creates a new reservation.
-
#list_reservations(location_id: nil, status: nil, external_id: nil, display_id: nil, customer_profile_id: nil, associate_id: nil, offset: 0, count: 10, sort: nil, expired: nil, accept: 'application/vnd.com.newstore.reservations+json; version=1') ⇒ ListReservationsResponseV1
Lists all reservations, supporting various filters.
-
#show_reservation(reservation_id, accept: 'application/vnd.com.newstore.reservations+json; version=1') ⇒ ReservationDetailsResponseV1
Retrieves a single reservation by ID.
-
#show_reservation_config ⇒ ReservationConfigResponse
Gets the reservation configuration of the retailer.
-
#update_reservation(reservation_id, body) ⇒ void
Updates the status of a 'PENDING' reservation to either 'REJECTED' or 'RESERVED'.
-
#update_reservation_config(body) ⇒ void
Updates the reservations configuration for the retailer.
-
#update_reservation_items(reservation_id, body) ⇒ void
Updates the status of a reservation's items.
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_reservation(idempotency_key, body: nil) ⇒ Object
Creates a new reservation. For each of the items in the reservation, 1
unit of the corresponding product will be moved from the 'main' stock
location to the '_customer_reservations' stock location at the specified
fulfillment location.
Reservations are created in the 'RESERVED' status by default, with an
expiry date of 24 hours from when they have been created. The default
duration of a reservation can by configured using the Update Reservation
Config endpoint.
Important: No stock is moved when a reservation expires. Stock is only
moved back into the 'main' stock location when the reservation is
converted to a sale or the item is unreserved. See Update Reservation
Items.
If you specify the reservation status to be 'PENDING', no stock movements
will occur, and the reservation will be shown as Pending in the Associate
App. If a pending reservation is accepted, its status will change to
'RESERVED' and the stock will be moved. If a pending reservation is
declined, its status will change to 'REJECTED' and no stock is moved.
You can specify an external ID for a reservation (identifier of the
reservation in an external system) by setting the Content-Type header of
your request to application/vnd.com.newstore.reservations+json; version=2 and including an external_id field in the body. If provided,
external_id must be a string between 1 and 255 characters.
should be the same between retries of the request. If a request has
previously been received with the same idempotency key, the ID of the
existing reservation will be returned instead of creating a new one. We
recommend using a UUID for this value.
description here
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/new_store_api/controllers/reservations_controller.rb', line 138 def create_reservation(idempotency_key, body: nil) @api_call .request(new_request_builder(HttpMethodEnum::POST, '/inventory/reservations', Server::API) .header_param(new_parameter(idempotency_key, key: 'Idempotency-Key')) .header_param(new_parameter('application/vnd.com.newstore.reservations+json; version=1', 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(:json_deserialize))) .execute end |
#list_reservations(location_id: nil, status: nil, external_id: nil, display_id: nil, customer_profile_id: nil, associate_id: nil, offset: 0, count: 10, sort: nil, expired: nil, accept: 'application/vnd.com.newstore.reservations+json; version=1') ⇒ ListReservationsResponseV1
Lists all reservations, supporting various filters.
location in which the reservations are being listed.
Status(es) of the reservations to list. If omitted, all reservation
statuses are listed.
allows filtering on the user facing ID, and a partial match is also
considered a match. If using V2, allows filtering on the external ID that
was provided when the reservation was created, and only an exact match is
considered a match.
reservations by 'display_id'. A partial match is also considered a match.
Only usable in V2 of the API.
the reservations by customer profile id
reservations by associate id
each page
by. Supported values are 'created_at|asc' or 'status|asc' to list in
ascending order and 'created_at|desc' or 'status|desc' to list in
descending order.
expired reservations
of the API to use. Possible values are
application/vnd.com.newstore.reservations+json; version=2 and
application/vnd.com.newstore.reservations+json; version=1
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/new_store_api/controllers/reservations_controller.rb', line 74 def list_reservations(location_id: nil, status: nil, external_id: nil, display_id: nil, customer_profile_id: nil, associate_id: nil, offset: 0, count: 10, sort: nil, expired: nil, accept: 'application/vnd.com.newstore.reservations+json; version=1') @api_call .request(new_request_builder(HttpMethodEnum::GET, '/inventory/reservations', Server::API) .query_param(new_parameter(location_id, key: 'location_id')) .query_param(new_parameter(status, key: 'status')) .query_param(new_parameter(external_id, key: 'external_id')) .query_param(new_parameter(display_id, key: 'display_id')) .query_param(new_parameter(customer_profile_id, key: 'customer_profile_id')) .query_param(new_parameter(associate_id, key: 'associate_id')) .query_param(new_parameter(offset, key: 'offset')) .query_param(new_parameter(count, key: 'count')) .query_param(new_parameter(sort, key: 'sort')) .query_param(new_parameter(expired, key: 'expired')) .header_param(new_parameter(accept, key: 'accept')) .auth(Single.new('oauth')) .array_serialization_format(ArraySerializationFormat::PLAIN)) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(ListReservationsResponseV1.method(:from_hash))) .execute end |
#show_reservation(reservation_id, accept: 'application/vnd.com.newstore.reservations+json; version=1') ⇒ ReservationDetailsResponseV1
Retrieves a single reservation by ID. The reservation status is derived from the status of its items as follows:
- Any item is RESERVED => Reservation is RESERVED
- Some items are CONVERTED to a sale or UNRESERVED => Reservation is CONVERTED
- All items are UNRESERVED => Reservation is UNRESERVED, meaning the
reservation has been cancelled
identifier.
of the API to use. Possible values are
application/vnd.com.newstore.reservations+json; version=2andapplication/vnd.com.newstore.reservations+json; version=1
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/new_store_api/controllers/reservations_controller.rb', line 169 def show_reservation(reservation_id, accept: 'application/vnd.com.newstore.reservations+json; version=1') @api_call .request(new_request_builder(HttpMethodEnum::GET, '/inventory/reservations/{reservation_id}', Server::API) .template_param(new_parameter(reservation_id, key: 'reservation_id') .should_encode(true)) .header_param(new_parameter(accept, key: 'accept')) .auth(Single.new('oauth'))) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(ReservationDetailsResponseV1.method(:from_hash))) .execute end |
#show_reservation_config ⇒ ReservationConfigResponse
Gets the reservation configuration of the retailer.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/new_store_api/controllers/reservations_controller.rb', line 11 def show_reservation_config @api_call .request(new_request_builder(HttpMethodEnum::GET, '/inventory/config/reservations', Server::API) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('oauth'))) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(ReservationConfigResponse.method(:from_hash))) .execute end |
#update_reservation(reservation_id, body) ⇒ void
This method returns an undefined value.
Updates the status of a 'PENDING' reservation to either 'REJECTED' or 'RESERVED'. If the status is changed to 'RESERVED', stock for each item in the reservation will be moved from the 'main' stock location to the '_customer_reservations' stock location and the expiry date will be reset. An email will be sent to the customer using the 'reservation_accepted_email' template if the 'send_accepted_email' config is enabled. If the status is changed to 'RESERVED', no stock will be moved, and an email will be sent to the customer using the 'reservation_rejected_email' template if the 'send_rejected_email' config is enabled. Important: This endpoint can only be used to update the status of reservations in the 'PENDING' status. All other status updates must be made at the item-level using the Update Reservation Items endpoint. identifier of the reservation here
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/new_store_api/controllers/reservations_controller.rb', line 208 def update_reservation(reservation_id, body) @api_call .request(new_request_builder(HttpMethodEnum::PATCH, '/inventory/reservations/{reservation_id}', Server::API) .template_param(new_parameter(reservation_id, key: 'reservation_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_reservation_config(body) ⇒ void
This method returns an undefined value.
Updates the reservations configuration for the retailer. description here
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/new_store_api/controllers/reservations_controller.rb', line 28 def update_reservation_config(body) @api_call .request(new_request_builder(HttpMethodEnum::PATCH, '/inventory/config/reservations', Server::API) .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_reservation_items(reservation_id, body) ⇒ void
This method returns an undefined value.
Updates the status of a reservation's items. Items start in the 'RESERVED' status, and can only be updated to 'CONVERTED' or 'UNRESERVED'. 'CONVERTED' and 'UNRESERVED' are both terminal states; You cannot change or update the status of items with these statuses. Updating the status of a RESERVED item will cause 1 unit of the corresponding product to be moved from the '_customer_reservations' stock location to the 'main' stock location at the fulfillment location associated with the reservation. When setting an item's status to 'CONVERTED', you can provide an optional 'cart_id' which indicates cart that the reserved products were added to. If this cart results in a purchase, a link to the corresponding order will be displayed alongside the item in the reservation details page in Omnichannel Manager. See this guide. Important: This endpoint cannot be used to update the status of items currently in a 'PENDING' reservation. To do this, use the Update Reservation endpoint instead. identifier of the reservation description here
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/new_store_api/controllers/reservations_controller.rb', line 249 def update_reservation_items(reservation_id, body) @api_call .request(new_request_builder(HttpMethodEnum::PATCH, '/inventory/reservations/{reservation_id}/items', Server::API) .template_param(new_parameter(reservation_id, key: 'reservation_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 |