1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum BatchRetrieveOrdersError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum CalculateOrderError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum CloneOrderError {
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum CreateOrderError {
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum PayOrderError {
50 UnknownValue(serde_json::Value),
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum RetrieveOrderError {
57 UnknownValue(serde_json::Value),
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum SearchOrdersError {
64 UnknownValue(serde_json::Value),
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum UpdateOrderError {
71 UnknownValue(serde_json::Value),
72}
73
74
75pub async fn batch_retrieve_orders(configuration: &configuration::Configuration, batch_retrieve_orders_request: models::BatchRetrieveOrdersRequest) -> Result<models::BatchRetrieveOrdersResponse, Error<BatchRetrieveOrdersError>> {
77 let p_batch_retrieve_orders_request = batch_retrieve_orders_request;
79
80 let uri_str = format!("{}/v2/orders/batch-retrieve", configuration.base_path);
81 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
82
83 if let Some(ref user_agent) = configuration.user_agent {
84 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
85 }
86 if let Some(ref token) = configuration.oauth_access_token {
87 req_builder = req_builder.bearer_auth(token.to_owned());
88 };
89 req_builder = req_builder.json(&p_batch_retrieve_orders_request);
90
91 let req = req_builder.build()?;
92 let resp = configuration.client.execute(req).await?;
93
94 let status = resp.status();
95 let content_type = resp
96 .headers()
97 .get("content-type")
98 .and_then(|v| v.to_str().ok())
99 .unwrap_or("application/octet-stream");
100 let content_type = super::ContentType::from(content_type);
101
102 if !status.is_client_error() && !status.is_server_error() {
103 let content = resp.text().await?;
104 match content_type {
105 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
106 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BatchRetrieveOrdersResponse`"))),
107 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::BatchRetrieveOrdersResponse`")))),
108 }
109 } else {
110 let content = resp.text().await?;
111 let entity: Option<BatchRetrieveOrdersError> = serde_json::from_str(&content).ok();
112 Err(Error::ResponseError(ResponseContent { status, content, entity }))
113 }
114}
115
116pub async fn calculate_order(configuration: &configuration::Configuration, calculate_order_request: models::CalculateOrderRequest) -> Result<models::CalculateOrderResponse, Error<CalculateOrderError>> {
118 let p_calculate_order_request = calculate_order_request;
120
121 let uri_str = format!("{}/v2/orders/calculate", configuration.base_path);
122 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
123
124 if let Some(ref user_agent) = configuration.user_agent {
125 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
126 }
127 if let Some(ref token) = configuration.oauth_access_token {
128 req_builder = req_builder.bearer_auth(token.to_owned());
129 };
130 req_builder = req_builder.json(&p_calculate_order_request);
131
132 let req = req_builder.build()?;
133 let resp = configuration.client.execute(req).await?;
134
135 let status = resp.status();
136 let content_type = resp
137 .headers()
138 .get("content-type")
139 .and_then(|v| v.to_str().ok())
140 .unwrap_or("application/octet-stream");
141 let content_type = super::ContentType::from(content_type);
142
143 if !status.is_client_error() && !status.is_server_error() {
144 let content = resp.text().await?;
145 match content_type {
146 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
147 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CalculateOrderResponse`"))),
148 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::CalculateOrderResponse`")))),
149 }
150 } else {
151 let content = resp.text().await?;
152 let entity: Option<CalculateOrderError> = serde_json::from_str(&content).ok();
153 Err(Error::ResponseError(ResponseContent { status, content, entity }))
154 }
155}
156
157pub async fn clone_order(configuration: &configuration::Configuration, clone_order_request: models::CloneOrderRequest) -> Result<models::CloneOrderResponse, Error<CloneOrderError>> {
159 let p_clone_order_request = clone_order_request;
161
162 let uri_str = format!("{}/v2/orders/clone", configuration.base_path);
163 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
164
165 if let Some(ref user_agent) = configuration.user_agent {
166 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
167 }
168 if let Some(ref token) = configuration.oauth_access_token {
169 req_builder = req_builder.bearer_auth(token.to_owned());
170 };
171 req_builder = req_builder.json(&p_clone_order_request);
172
173 let req = req_builder.build()?;
174 let resp = configuration.client.execute(req).await?;
175
176 let status = resp.status();
177 let content_type = resp
178 .headers()
179 .get("content-type")
180 .and_then(|v| v.to_str().ok())
181 .unwrap_or("application/octet-stream");
182 let content_type = super::ContentType::from(content_type);
183
184 if !status.is_client_error() && !status.is_server_error() {
185 let content = resp.text().await?;
186 match content_type {
187 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
188 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CloneOrderResponse`"))),
189 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::CloneOrderResponse`")))),
190 }
191 } else {
192 let content = resp.text().await?;
193 let entity: Option<CloneOrderError> = serde_json::from_str(&content).ok();
194 Err(Error::ResponseError(ResponseContent { status, content, entity }))
195 }
196}
197
198pub async fn create_order(configuration: &configuration::Configuration, create_order_request: models::CreateOrderRequest) -> Result<models::CreateOrderResponse, Error<CreateOrderError>> {
200 let p_create_order_request = create_order_request;
202
203 let uri_str = format!("{}/v2/orders", configuration.base_path);
204 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
205
206 if let Some(ref user_agent) = configuration.user_agent {
207 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
208 }
209 if let Some(ref token) = configuration.oauth_access_token {
210 req_builder = req_builder.bearer_auth(token.to_owned());
211 };
212 req_builder = req_builder.json(&p_create_order_request);
213
214 let req = req_builder.build()?;
215 let resp = configuration.client.execute(req).await?;
216
217 let status = resp.status();
218 let content_type = resp
219 .headers()
220 .get("content-type")
221 .and_then(|v| v.to_str().ok())
222 .unwrap_or("application/octet-stream");
223 let content_type = super::ContentType::from(content_type);
224
225 if !status.is_client_error() && !status.is_server_error() {
226 let content = resp.text().await?;
227 match content_type {
228 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
229 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateOrderResponse`"))),
230 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::CreateOrderResponse`")))),
231 }
232 } else {
233 let content = resp.text().await?;
234 let entity: Option<CreateOrderError> = serde_json::from_str(&content).ok();
235 Err(Error::ResponseError(ResponseContent { status, content, entity }))
236 }
237}
238
239pub async fn pay_order(configuration: &configuration::Configuration, order_id: &str, pay_order_request: models::PayOrderRequest) -> Result<models::PayOrderResponse, Error<PayOrderError>> {
241 let p_order_id = order_id;
243 let p_pay_order_request = pay_order_request;
244
245 let uri_str = format!("{}/v2/orders/{order_id}/pay", configuration.base_path, order_id=crate::apis::urlencode(p_order_id));
246 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
247
248 if let Some(ref user_agent) = configuration.user_agent {
249 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
250 }
251 if let Some(ref token) = configuration.oauth_access_token {
252 req_builder = req_builder.bearer_auth(token.to_owned());
253 };
254 req_builder = req_builder.json(&p_pay_order_request);
255
256 let req = req_builder.build()?;
257 let resp = configuration.client.execute(req).await?;
258
259 let status = resp.status();
260 let content_type = resp
261 .headers()
262 .get("content-type")
263 .and_then(|v| v.to_str().ok())
264 .unwrap_or("application/octet-stream");
265 let content_type = super::ContentType::from(content_type);
266
267 if !status.is_client_error() && !status.is_server_error() {
268 let content = resp.text().await?;
269 match content_type {
270 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
271 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PayOrderResponse`"))),
272 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::PayOrderResponse`")))),
273 }
274 } else {
275 let content = resp.text().await?;
276 let entity: Option<PayOrderError> = serde_json::from_str(&content).ok();
277 Err(Error::ResponseError(ResponseContent { status, content, entity }))
278 }
279}
280
281pub async fn retrieve_order(configuration: &configuration::Configuration, order_id: &str) -> Result<models::RetrieveOrderResponse, Error<RetrieveOrderError>> {
283 let p_order_id = order_id;
285
286 let uri_str = format!("{}/v2/orders/{order_id}", configuration.base_path, order_id=crate::apis::urlencode(p_order_id));
287 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
288
289 if let Some(ref user_agent) = configuration.user_agent {
290 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
291 }
292 if let Some(ref token) = configuration.oauth_access_token {
293 req_builder = req_builder.bearer_auth(token.to_owned());
294 };
295
296 let req = req_builder.build()?;
297 let resp = configuration.client.execute(req).await?;
298
299 let status = resp.status();
300 let content_type = resp
301 .headers()
302 .get("content-type")
303 .and_then(|v| v.to_str().ok())
304 .unwrap_or("application/octet-stream");
305 let content_type = super::ContentType::from(content_type);
306
307 if !status.is_client_error() && !status.is_server_error() {
308 let content = resp.text().await?;
309 match content_type {
310 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
311 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RetrieveOrderResponse`"))),
312 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::RetrieveOrderResponse`")))),
313 }
314 } else {
315 let content = resp.text().await?;
316 let entity: Option<RetrieveOrderError> = serde_json::from_str(&content).ok();
317 Err(Error::ResponseError(ResponseContent { status, content, entity }))
318 }
319}
320
321pub async fn search_orders(configuration: &configuration::Configuration, search_orders_request: models::SearchOrdersRequest) -> Result<models::SearchOrdersResponse, Error<SearchOrdersError>> {
323 let p_search_orders_request = search_orders_request;
325
326 let uri_str = format!("{}/v2/orders/search", configuration.base_path);
327 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
328
329 if let Some(ref user_agent) = configuration.user_agent {
330 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
331 }
332 if let Some(ref token) = configuration.oauth_access_token {
333 req_builder = req_builder.bearer_auth(token.to_owned());
334 };
335 req_builder = req_builder.json(&p_search_orders_request);
336
337 let req = req_builder.build()?;
338 let resp = configuration.client.execute(req).await?;
339
340 let status = resp.status();
341 let content_type = resp
342 .headers()
343 .get("content-type")
344 .and_then(|v| v.to_str().ok())
345 .unwrap_or("application/octet-stream");
346 let content_type = super::ContentType::from(content_type);
347
348 if !status.is_client_error() && !status.is_server_error() {
349 let content = resp.text().await?;
350 match content_type {
351 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
352 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SearchOrdersResponse`"))),
353 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::SearchOrdersResponse`")))),
354 }
355 } else {
356 let content = resp.text().await?;
357 let entity: Option<SearchOrdersError> = serde_json::from_str(&content).ok();
358 Err(Error::ResponseError(ResponseContent { status, content, entity }))
359 }
360}
361
362pub async fn update_order(configuration: &configuration::Configuration, order_id: &str, update_order_request: models::UpdateOrderRequest) -> Result<models::UpdateOrderResponse, Error<UpdateOrderError>> {
364 let p_order_id = order_id;
366 let p_update_order_request = update_order_request;
367
368 let uri_str = format!("{}/v2/orders/{order_id}", configuration.base_path, order_id=crate::apis::urlencode(p_order_id));
369 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
370
371 if let Some(ref user_agent) = configuration.user_agent {
372 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
373 }
374 if let Some(ref token) = configuration.oauth_access_token {
375 req_builder = req_builder.bearer_auth(token.to_owned());
376 };
377 req_builder = req_builder.json(&p_update_order_request);
378
379 let req = req_builder.build()?;
380 let resp = configuration.client.execute(req).await?;
381
382 let status = resp.status();
383 let content_type = resp
384 .headers()
385 .get("content-type")
386 .and_then(|v| v.to_str().ok())
387 .unwrap_or("application/octet-stream");
388 let content_type = super::ContentType::from(content_type);
389
390 if !status.is_client_error() && !status.is_server_error() {
391 let content = resp.text().await?;
392 match content_type {
393 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
394 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UpdateOrderResponse`"))),
395 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::UpdateOrderResponse`")))),
396 }
397 } else {
398 let content = resp.text().await?;
399 let entity: Option<UpdateOrderError> = serde_json::from_str(&content).ok();
400 Err(Error::ResponseError(ResponseContent { status, content, entity }))
401 }
402}
403