Skip to main content

autogen_squareup/apis/
transfer_order_api.rs

1/*
2 * Square
3 *
4 * Use Square APIs to manage and run business including payment, customer, product, inventory, and employee management.
5 *
6 * The version of the OpenAPI document: 2.0
7 * Contact: developers@squareup.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`cancel_transfer_order`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CancelTransferOrderError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`create_transfer_order`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum CreateTransferOrderError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`delete_transfer_order`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum DeleteTransferOrderError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`receive_transfer_order`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum ReceiveTransferOrderError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`retrieve_transfer_order`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum RetrieveTransferOrderError {
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`search_transfer_orders`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum SearchTransferOrdersError {
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`start_transfer_order`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum StartTransferOrderError {
64    UnknownValue(serde_json::Value),
65}
66
67/// struct for typed errors of method [`update_transfer_order`]
68#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum UpdateTransferOrderError {
71    UnknownValue(serde_json::Value),
72}
73
74
75/// Cancels a transfer order in [STARTED](entity:TransferOrderStatus) or  [PARTIALLY_RECEIVED](entity:TransferOrderStatus) status. Any unreceived quantities will no longer be receivable and will be immediately returned to the source [Location](entity:Location)'s inventory.  Common reasons for cancellation: - Items no longer needed at destination - Source location needs the inventory - Order created in error  Creates a [transfer_order.updated](webhook:transfer_order.updated) webhook event.
76pub async fn cancel_transfer_order(configuration: &configuration::Configuration, transfer_order_id: &str, cancel_transfer_order_request: models::CancelTransferOrderRequest) -> Result<models::CancelTransferOrderResponse, Error<CancelTransferOrderError>> {
77    // add a prefix to parameters to efficiently prevent name collisions
78    let p_transfer_order_id = transfer_order_id;
79    let p_cancel_transfer_order_request = cancel_transfer_order_request;
80
81    let uri_str = format!("{}/v2/transfer-orders/{transfer_order_id}/cancel", configuration.base_path, transfer_order_id=crate::apis::urlencode(p_transfer_order_id));
82    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
83
84    if let Some(ref user_agent) = configuration.user_agent {
85        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
86    }
87    if let Some(ref token) = configuration.oauth_access_token {
88        req_builder = req_builder.bearer_auth(token.to_owned());
89    };
90    req_builder = req_builder.json(&p_cancel_transfer_order_request);
91
92    let req = req_builder.build()?;
93    let resp = configuration.client.execute(req).await?;
94
95    let status = resp.status();
96    let content_type = resp
97        .headers()
98        .get("content-type")
99        .and_then(|v| v.to_str().ok())
100        .unwrap_or("application/octet-stream");
101    let content_type = super::ContentType::from(content_type);
102
103    if !status.is_client_error() && !status.is_server_error() {
104        let content = resp.text().await?;
105        match content_type {
106            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
107            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CancelTransferOrderResponse`"))),
108            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::CancelTransferOrderResponse`")))),
109        }
110    } else {
111        let content = resp.text().await?;
112        let entity: Option<CancelTransferOrderError> = serde_json::from_str(&content).ok();
113        Err(Error::ResponseError(ResponseContent { status, content, entity }))
114    }
115}
116
117/// Creates a new transfer order in [DRAFT](entity:TransferOrderStatus) status. A transfer order represents the intent  to move [CatalogItemVariation](entity:CatalogItemVariation)s from one [Location](entity:Location) to another.  The source and destination locations must be different and must belong to your Square account.  In [DRAFT](entity:TransferOrderStatus) status, you can: - Add or remove items - Modify quantities - Update shipping information - Delete the entire order via [DeleteTransferOrder](api-endpoint:TransferOrders-DeleteTransferOrder)  The request requires source_location_id and destination_location_id. Inventory levels are not affected until the order is started via  [StartTransferOrder](api-endpoint:TransferOrders-StartTransferOrder).  Common integration points: - Sync with warehouse management systems - Automate regular stock transfers - Initialize transfers from inventory optimization systems  Creates a [transfer_order.created](webhook:transfer_order.created) webhook event.
118pub async fn create_transfer_order(configuration: &configuration::Configuration, create_transfer_order_request: models::CreateTransferOrderRequest) -> Result<models::CreateTransferOrderResponse, Error<CreateTransferOrderError>> {
119    // add a prefix to parameters to efficiently prevent name collisions
120    let p_create_transfer_order_request = create_transfer_order_request;
121
122    let uri_str = format!("{}/v2/transfer-orders", configuration.base_path);
123    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
124
125    if let Some(ref user_agent) = configuration.user_agent {
126        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
127    }
128    if let Some(ref token) = configuration.oauth_access_token {
129        req_builder = req_builder.bearer_auth(token.to_owned());
130    };
131    req_builder = req_builder.json(&p_create_transfer_order_request);
132
133    let req = req_builder.build()?;
134    let resp = configuration.client.execute(req).await?;
135
136    let status = resp.status();
137    let content_type = resp
138        .headers()
139        .get("content-type")
140        .and_then(|v| v.to_str().ok())
141        .unwrap_or("application/octet-stream");
142    let content_type = super::ContentType::from(content_type);
143
144    if !status.is_client_error() && !status.is_server_error() {
145        let content = resp.text().await?;
146        match content_type {
147            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
148            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateTransferOrderResponse`"))),
149            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::CreateTransferOrderResponse`")))),
150        }
151    } else {
152        let content = resp.text().await?;
153        let entity: Option<CreateTransferOrderError> = serde_json::from_str(&content).ok();
154        Err(Error::ResponseError(ResponseContent { status, content, entity }))
155    }
156}
157
158/// Deletes a transfer order in [DRAFT](entity:TransferOrderStatus) status. Only draft orders can be deleted. Once an order is started via  [StartTransferOrder](api-endpoint:TransferOrders-StartTransferOrder), it can no longer be deleted.  Creates a [transfer_order.deleted](webhook:transfer_order.deleted) webhook event.
159pub async fn delete_transfer_order(configuration: &configuration::Configuration, transfer_order_id: &str, version: Option<i64>) -> Result<models::DeleteTransferOrderResponse, Error<DeleteTransferOrderError>> {
160    // add a prefix to parameters to efficiently prevent name collisions
161    let p_transfer_order_id = transfer_order_id;
162    let p_version = version;
163
164    let uri_str = format!("{}/v2/transfer-orders/{transfer_order_id}", configuration.base_path, transfer_order_id=crate::apis::urlencode(p_transfer_order_id));
165    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
166
167    if let Some(ref param_value) = p_version {
168        req_builder = req_builder.query(&[("version", &param_value.to_string())]);
169    }
170    if let Some(ref user_agent) = configuration.user_agent {
171        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
172    }
173    if let Some(ref token) = configuration.oauth_access_token {
174        req_builder = req_builder.bearer_auth(token.to_owned());
175    };
176
177    let req = req_builder.build()?;
178    let resp = configuration.client.execute(req).await?;
179
180    let status = resp.status();
181    let content_type = resp
182        .headers()
183        .get("content-type")
184        .and_then(|v| v.to_str().ok())
185        .unwrap_or("application/octet-stream");
186    let content_type = super::ContentType::from(content_type);
187
188    if !status.is_client_error() && !status.is_server_error() {
189        let content = resp.text().await?;
190        match content_type {
191            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
192            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeleteTransferOrderResponse`"))),
193            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::DeleteTransferOrderResponse`")))),
194        }
195    } else {
196        let content = resp.text().await?;
197        let entity: Option<DeleteTransferOrderError> = serde_json::from_str(&content).ok();
198        Err(Error::ResponseError(ResponseContent { status, content, entity }))
199    }
200}
201
202/// Records receipt of [CatalogItemVariation](entity:CatalogItemVariation)s for a transfer order. This endpoint supports partial receiving - you can receive items in multiple batches.  For each line item, you can specify: - Quantity received in good condition (added to destination inventory with [InventoryState](entity:InventoryState) of IN_STOCK) - Quantity damaged during transit/handling (added to destination inventory with [InventoryState](entity:InventoryState) of WASTE) - Quantity canceled (returned to source location's inventory)  The order must be in [STARTED](entity:TransferOrderStatus) or [PARTIALLY_RECEIVED](entity:TransferOrderStatus) status. Received quantities are added to the destination [Location](entity:Location)'s inventory according to their condition. Canceled quantities are immediately returned to the source [Location](entity:Location)'s inventory.  When all items are either received, damaged, or canceled, the order moves to [COMPLETED](entity:TransferOrderStatus) status.  Creates a [transfer_order.updated](webhook:transfer_order.updated) webhook event.
203pub async fn receive_transfer_order(configuration: &configuration::Configuration, transfer_order_id: &str, receive_transfer_order_request: models::ReceiveTransferOrderRequest) -> Result<models::ReceiveTransferOrderResponse, Error<ReceiveTransferOrderError>> {
204    // add a prefix to parameters to efficiently prevent name collisions
205    let p_transfer_order_id = transfer_order_id;
206    let p_receive_transfer_order_request = receive_transfer_order_request;
207
208    let uri_str = format!("{}/v2/transfer-orders/{transfer_order_id}/receive", configuration.base_path, transfer_order_id=crate::apis::urlencode(p_transfer_order_id));
209    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
210
211    if let Some(ref user_agent) = configuration.user_agent {
212        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
213    }
214    if let Some(ref token) = configuration.oauth_access_token {
215        req_builder = req_builder.bearer_auth(token.to_owned());
216    };
217    req_builder = req_builder.json(&p_receive_transfer_order_request);
218
219    let req = req_builder.build()?;
220    let resp = configuration.client.execute(req).await?;
221
222    let status = resp.status();
223    let content_type = resp
224        .headers()
225        .get("content-type")
226        .and_then(|v| v.to_str().ok())
227        .unwrap_or("application/octet-stream");
228    let content_type = super::ContentType::from(content_type);
229
230    if !status.is_client_error() && !status.is_server_error() {
231        let content = resp.text().await?;
232        match content_type {
233            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
234            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ReceiveTransferOrderResponse`"))),
235            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ReceiveTransferOrderResponse`")))),
236        }
237    } else {
238        let content = resp.text().await?;
239        let entity: Option<ReceiveTransferOrderError> = serde_json::from_str(&content).ok();
240        Err(Error::ResponseError(ResponseContent { status, content, entity }))
241    }
242}
243
244/// Retrieves a specific [TransferOrder](entity:TransferOrder) by ID. Returns the complete order details including:  - Basic information (status, dates, notes) - Line items with ordered and received quantities - Source and destination [Location](entity:Location)s - Tracking information (if available)
245pub async fn retrieve_transfer_order(configuration: &configuration::Configuration, transfer_order_id: &str) -> Result<models::RetrieveTransferOrderResponse, Error<RetrieveTransferOrderError>> {
246    // add a prefix to parameters to efficiently prevent name collisions
247    let p_transfer_order_id = transfer_order_id;
248
249    let uri_str = format!("{}/v2/transfer-orders/{transfer_order_id}", configuration.base_path, transfer_order_id=crate::apis::urlencode(p_transfer_order_id));
250    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
251
252    if let Some(ref user_agent) = configuration.user_agent {
253        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
254    }
255    if let Some(ref token) = configuration.oauth_access_token {
256        req_builder = req_builder.bearer_auth(token.to_owned());
257    };
258
259    let req = req_builder.build()?;
260    let resp = configuration.client.execute(req).await?;
261
262    let status = resp.status();
263    let content_type = resp
264        .headers()
265        .get("content-type")
266        .and_then(|v| v.to_str().ok())
267        .unwrap_or("application/octet-stream");
268    let content_type = super::ContentType::from(content_type);
269
270    if !status.is_client_error() && !status.is_server_error() {
271        let content = resp.text().await?;
272        match content_type {
273            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
274            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RetrieveTransferOrderResponse`"))),
275            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RetrieveTransferOrderResponse`")))),
276        }
277    } else {
278        let content = resp.text().await?;
279        let entity: Option<RetrieveTransferOrderError> = serde_json::from_str(&content).ok();
280        Err(Error::ResponseError(ResponseContent { status, content, entity }))
281    }
282}
283
284/// Searches for transfer orders using filters. Returns a paginated list of matching [TransferOrder](entity:TransferOrder)s sorted by creation date.  Common search scenarios: - Find orders for a source [Location](entity:Location) - Find orders for a destination [Location](entity:Location) - Find orders in a particular [TransferOrderStatus](entity:TransferOrderStatus)
285pub async fn search_transfer_orders(configuration: &configuration::Configuration, search_transfer_orders_request: models::SearchTransferOrdersRequest) -> Result<models::SearchTransferOrdersResponse, Error<SearchTransferOrdersError>> {
286    // add a prefix to parameters to efficiently prevent name collisions
287    let p_search_transfer_orders_request = search_transfer_orders_request;
288
289    let uri_str = format!("{}/v2/transfer-orders/search", configuration.base_path);
290    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
291
292    if let Some(ref user_agent) = configuration.user_agent {
293        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
294    }
295    if let Some(ref token) = configuration.oauth_access_token {
296        req_builder = req_builder.bearer_auth(token.to_owned());
297    };
298    req_builder = req_builder.json(&p_search_transfer_orders_request);
299
300    let req = req_builder.build()?;
301    let resp = configuration.client.execute(req).await?;
302
303    let status = resp.status();
304    let content_type = resp
305        .headers()
306        .get("content-type")
307        .and_then(|v| v.to_str().ok())
308        .unwrap_or("application/octet-stream");
309    let content_type = super::ContentType::from(content_type);
310
311    if !status.is_client_error() && !status.is_server_error() {
312        let content = resp.text().await?;
313        match content_type {
314            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
315            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SearchTransferOrdersResponse`"))),
316            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::SearchTransferOrdersResponse`")))),
317        }
318    } else {
319        let content = resp.text().await?;
320        let entity: Option<SearchTransferOrdersError> = serde_json::from_str(&content).ok();
321        Err(Error::ResponseError(ResponseContent { status, content, entity }))
322    }
323}
324
325/// Changes a [DRAFT](entity:TransferOrderStatus) transfer order to [STARTED](entity:TransferOrderStatus) status. This decrements inventory at the source [Location](entity:Location) and marks it as in-transit.  The order must be in [DRAFT](entity:TransferOrderStatus) status and have all required fields populated. Once started, the order can no longer be deleted, but it can be canceled via  [CancelTransferOrder](api-endpoint:TransferOrders-CancelTransferOrder).  Creates a [transfer_order.updated](webhook:transfer_order.updated) webhook event.
326pub async fn start_transfer_order(configuration: &configuration::Configuration, transfer_order_id: &str, start_transfer_order_request: models::StartTransferOrderRequest) -> Result<models::StartTransferOrderResponse, Error<StartTransferOrderError>> {
327    // add a prefix to parameters to efficiently prevent name collisions
328    let p_transfer_order_id = transfer_order_id;
329    let p_start_transfer_order_request = start_transfer_order_request;
330
331    let uri_str = format!("{}/v2/transfer-orders/{transfer_order_id}/start", configuration.base_path, transfer_order_id=crate::apis::urlencode(p_transfer_order_id));
332    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
333
334    if let Some(ref user_agent) = configuration.user_agent {
335        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
336    }
337    if let Some(ref token) = configuration.oauth_access_token {
338        req_builder = req_builder.bearer_auth(token.to_owned());
339    };
340    req_builder = req_builder.json(&p_start_transfer_order_request);
341
342    let req = req_builder.build()?;
343    let resp = configuration.client.execute(req).await?;
344
345    let status = resp.status();
346    let content_type = resp
347        .headers()
348        .get("content-type")
349        .and_then(|v| v.to_str().ok())
350        .unwrap_or("application/octet-stream");
351    let content_type = super::ContentType::from(content_type);
352
353    if !status.is_client_error() && !status.is_server_error() {
354        let content = resp.text().await?;
355        match content_type {
356            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
357            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::StartTransferOrderResponse`"))),
358            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::StartTransferOrderResponse`")))),
359        }
360    } else {
361        let content = resp.text().await?;
362        let entity: Option<StartTransferOrderError> = serde_json::from_str(&content).ok();
363        Err(Error::ResponseError(ResponseContent { status, content, entity }))
364    }
365}
366
367/// Updates an existing transfer order. This endpoint supports sparse updates, allowing you to modify specific fields without affecting others.  Creates a [transfer_order.updated](webhook:transfer_order.updated) webhook event.
368pub async fn update_transfer_order(configuration: &configuration::Configuration, transfer_order_id: &str, update_transfer_order_request: models::UpdateTransferOrderRequest) -> Result<models::UpdateTransferOrderResponse, Error<UpdateTransferOrderError>> {
369    // add a prefix to parameters to efficiently prevent name collisions
370    let p_transfer_order_id = transfer_order_id;
371    let p_update_transfer_order_request = update_transfer_order_request;
372
373    let uri_str = format!("{}/v2/transfer-orders/{transfer_order_id}", configuration.base_path, transfer_order_id=crate::apis::urlencode(p_transfer_order_id));
374    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
375
376    if let Some(ref user_agent) = configuration.user_agent {
377        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
378    }
379    if let Some(ref token) = configuration.oauth_access_token {
380        req_builder = req_builder.bearer_auth(token.to_owned());
381    };
382    req_builder = req_builder.json(&p_update_transfer_order_request);
383
384    let req = req_builder.build()?;
385    let resp = configuration.client.execute(req).await?;
386
387    let status = resp.status();
388    let content_type = resp
389        .headers()
390        .get("content-type")
391        .and_then(|v| v.to_str().ok())
392        .unwrap_or("application/octet-stream");
393    let content_type = super::ContentType::from(content_type);
394
395    if !status.is_client_error() && !status.is_server_error() {
396        let content = resp.text().await?;
397        match content_type {
398            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
399            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UpdateTransferOrderResponse`"))),
400            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::UpdateTransferOrderResponse`")))),
401        }
402    } else {
403        let content = resp.text().await?;
404        let entity: Option<UpdateTransferOrderError> = serde_json::from_str(&content).ok();
405        Err(Error::ResponseError(ResponseContent { status, content, entity }))
406    }
407}
408