Skip to main content

autogen_squareup/apis/
terminal_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_terminal_action`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CancelTerminalActionError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`cancel_terminal_checkout`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum CancelTerminalCheckoutError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`cancel_terminal_refund`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum CancelTerminalRefundError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`create_terminal_action`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum CreateTerminalActionError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`create_terminal_checkout`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum CreateTerminalCheckoutError {
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`create_terminal_refund`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum CreateTerminalRefundError {
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`dismiss_terminal_action`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum DismissTerminalActionError {
64    UnknownValue(serde_json::Value),
65}
66
67/// struct for typed errors of method [`dismiss_terminal_checkout`]
68#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum DismissTerminalCheckoutError {
71    UnknownValue(serde_json::Value),
72}
73
74/// struct for typed errors of method [`dismiss_terminal_refund`]
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum DismissTerminalRefundError {
78    UnknownValue(serde_json::Value),
79}
80
81/// struct for typed errors of method [`get_terminal_action`]
82#[derive(Debug, Clone, Serialize, Deserialize)]
83#[serde(untagged)]
84pub enum GetTerminalActionError {
85    UnknownValue(serde_json::Value),
86}
87
88/// struct for typed errors of method [`get_terminal_checkout`]
89#[derive(Debug, Clone, Serialize, Deserialize)]
90#[serde(untagged)]
91pub enum GetTerminalCheckoutError {
92    UnknownValue(serde_json::Value),
93}
94
95/// struct for typed errors of method [`get_terminal_refund`]
96#[derive(Debug, Clone, Serialize, Deserialize)]
97#[serde(untagged)]
98pub enum GetTerminalRefundError {
99    UnknownValue(serde_json::Value),
100}
101
102/// struct for typed errors of method [`search_terminal_actions`]
103#[derive(Debug, Clone, Serialize, Deserialize)]
104#[serde(untagged)]
105pub enum SearchTerminalActionsError {
106    UnknownValue(serde_json::Value),
107}
108
109/// struct for typed errors of method [`search_terminal_checkouts`]
110#[derive(Debug, Clone, Serialize, Deserialize)]
111#[serde(untagged)]
112pub enum SearchTerminalCheckoutsError {
113    UnknownValue(serde_json::Value),
114}
115
116/// struct for typed errors of method [`search_terminal_refunds`]
117#[derive(Debug, Clone, Serialize, Deserialize)]
118#[serde(untagged)]
119pub enum SearchTerminalRefundsError {
120    UnknownValue(serde_json::Value),
121}
122
123
124/// Cancels a Terminal action request if the status of the request permits it.
125pub async fn cancel_terminal_action(configuration: &configuration::Configuration, action_id: &str) -> Result<models::CancelTerminalActionResponse, Error<CancelTerminalActionError>> {
126    // add a prefix to parameters to efficiently prevent name collisions
127    let p_action_id = action_id;
128
129    let uri_str = format!("{}/v2/terminals/actions/{action_id}/cancel", configuration.base_path, action_id=crate::apis::urlencode(p_action_id));
130    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
131
132    if let Some(ref user_agent) = configuration.user_agent {
133        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
134    }
135    if let Some(ref token) = configuration.oauth_access_token {
136        req_builder = req_builder.bearer_auth(token.to_owned());
137    };
138
139    let req = req_builder.build()?;
140    let resp = configuration.client.execute(req).await?;
141
142    let status = resp.status();
143    let content_type = resp
144        .headers()
145        .get("content-type")
146        .and_then(|v| v.to_str().ok())
147        .unwrap_or("application/octet-stream");
148    let content_type = super::ContentType::from(content_type);
149
150    if !status.is_client_error() && !status.is_server_error() {
151        let content = resp.text().await?;
152        match content_type {
153            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
154            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CancelTerminalActionResponse`"))),
155            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::CancelTerminalActionResponse`")))),
156        }
157    } else {
158        let content = resp.text().await?;
159        let entity: Option<CancelTerminalActionError> = serde_json::from_str(&content).ok();
160        Err(Error::ResponseError(ResponseContent { status, content, entity }))
161    }
162}
163
164/// Cancels a Terminal checkout request if the status of the request permits it.
165pub async fn cancel_terminal_checkout(configuration: &configuration::Configuration, checkout_id: &str) -> Result<models::CancelTerminalCheckoutResponse, Error<CancelTerminalCheckoutError>> {
166    // add a prefix to parameters to efficiently prevent name collisions
167    let p_checkout_id = checkout_id;
168
169    let uri_str = format!("{}/v2/terminals/checkouts/{checkout_id}/cancel", configuration.base_path, checkout_id=crate::apis::urlencode(p_checkout_id));
170    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
171
172    if let Some(ref user_agent) = configuration.user_agent {
173        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
174    }
175    if let Some(ref token) = configuration.oauth_access_token {
176        req_builder = req_builder.bearer_auth(token.to_owned());
177    };
178
179    let req = req_builder.build()?;
180    let resp = configuration.client.execute(req).await?;
181
182    let status = resp.status();
183    let content_type = resp
184        .headers()
185        .get("content-type")
186        .and_then(|v| v.to_str().ok())
187        .unwrap_or("application/octet-stream");
188    let content_type = super::ContentType::from(content_type);
189
190    if !status.is_client_error() && !status.is_server_error() {
191        let content = resp.text().await?;
192        match content_type {
193            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
194            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CancelTerminalCheckoutResponse`"))),
195            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::CancelTerminalCheckoutResponse`")))),
196        }
197    } else {
198        let content = resp.text().await?;
199        let entity: Option<CancelTerminalCheckoutError> = serde_json::from_str(&content).ok();
200        Err(Error::ResponseError(ResponseContent { status, content, entity }))
201    }
202}
203
204/// Cancels an Interac Terminal refund request by refund request ID if the status of the request permits it.
205pub async fn cancel_terminal_refund(configuration: &configuration::Configuration, terminal_refund_id: &str) -> Result<models::CancelTerminalRefundResponse, Error<CancelTerminalRefundError>> {
206    // add a prefix to parameters to efficiently prevent name collisions
207    let p_terminal_refund_id = terminal_refund_id;
208
209    let uri_str = format!("{}/v2/terminals/refunds/{terminal_refund_id}/cancel", configuration.base_path, terminal_refund_id=crate::apis::urlencode(p_terminal_refund_id));
210    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
211
212    if let Some(ref user_agent) = configuration.user_agent {
213        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
214    }
215    if let Some(ref token) = configuration.oauth_access_token {
216        req_builder = req_builder.bearer_auth(token.to_owned());
217    };
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::CancelTerminalRefundResponse`"))),
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::CancelTerminalRefundResponse`")))),
236        }
237    } else {
238        let content = resp.text().await?;
239        let entity: Option<CancelTerminalRefundError> = serde_json::from_str(&content).ok();
240        Err(Error::ResponseError(ResponseContent { status, content, entity }))
241    }
242}
243
244/// Creates a Terminal action request and sends it to the specified device.
245pub async fn create_terminal_action(configuration: &configuration::Configuration, create_terminal_action_request: models::CreateTerminalActionRequest) -> Result<models::CreateTerminalActionResponse, Error<CreateTerminalActionError>> {
246    // add a prefix to parameters to efficiently prevent name collisions
247    let p_create_terminal_action_request = create_terminal_action_request;
248
249    let uri_str = format!("{}/v2/terminals/actions", configuration.base_path);
250    let mut req_builder = configuration.client.request(reqwest::Method::POST, &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    req_builder = req_builder.json(&p_create_terminal_action_request);
259
260    let req = req_builder.build()?;
261    let resp = configuration.client.execute(req).await?;
262
263    let status = resp.status();
264    let content_type = resp
265        .headers()
266        .get("content-type")
267        .and_then(|v| v.to_str().ok())
268        .unwrap_or("application/octet-stream");
269    let content_type = super::ContentType::from(content_type);
270
271    if !status.is_client_error() && !status.is_server_error() {
272        let content = resp.text().await?;
273        match content_type {
274            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
275            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateTerminalActionResponse`"))),
276            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::CreateTerminalActionResponse`")))),
277        }
278    } else {
279        let content = resp.text().await?;
280        let entity: Option<CreateTerminalActionError> = serde_json::from_str(&content).ok();
281        Err(Error::ResponseError(ResponseContent { status, content, entity }))
282    }
283}
284
285/// Creates a Terminal checkout request and sends it to the specified device to take a payment for the requested amount.
286pub async fn create_terminal_checkout(configuration: &configuration::Configuration, create_terminal_checkout_request: models::CreateTerminalCheckoutRequest) -> Result<models::CreateTerminalCheckoutResponse, Error<CreateTerminalCheckoutError>> {
287    // add a prefix to parameters to efficiently prevent name collisions
288    let p_create_terminal_checkout_request = create_terminal_checkout_request;
289
290    let uri_str = format!("{}/v2/terminals/checkouts", configuration.base_path);
291    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
292
293    if let Some(ref user_agent) = configuration.user_agent {
294        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
295    }
296    if let Some(ref token) = configuration.oauth_access_token {
297        req_builder = req_builder.bearer_auth(token.to_owned());
298    };
299    req_builder = req_builder.json(&p_create_terminal_checkout_request);
300
301    let req = req_builder.build()?;
302    let resp = configuration.client.execute(req).await?;
303
304    let status = resp.status();
305    let content_type = resp
306        .headers()
307        .get("content-type")
308        .and_then(|v| v.to_str().ok())
309        .unwrap_or("application/octet-stream");
310    let content_type = super::ContentType::from(content_type);
311
312    if !status.is_client_error() && !status.is_server_error() {
313        let content = resp.text().await?;
314        match content_type {
315            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
316            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateTerminalCheckoutResponse`"))),
317            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::CreateTerminalCheckoutResponse`")))),
318        }
319    } else {
320        let content = resp.text().await?;
321        let entity: Option<CreateTerminalCheckoutError> = serde_json::from_str(&content).ok();
322        Err(Error::ResponseError(ResponseContent { status, content, entity }))
323    }
324}
325
326/// Creates a request to refund an Interac payment completed on a Square Terminal. Refunds for Interac payments on a Square Terminal are supported only for Interac debit cards in Canada. Other refunds for Terminal payments should use the Refunds API. For more information, see [Refunds API](api:Refunds).
327pub async fn create_terminal_refund(configuration: &configuration::Configuration, create_terminal_refund_request: models::CreateTerminalRefundRequest) -> Result<models::CreateTerminalRefundResponse, Error<CreateTerminalRefundError>> {
328    // add a prefix to parameters to efficiently prevent name collisions
329    let p_create_terminal_refund_request = create_terminal_refund_request;
330
331    let uri_str = format!("{}/v2/terminals/refunds", configuration.base_path);
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_create_terminal_refund_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::CreateTerminalRefundResponse`"))),
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::CreateTerminalRefundResponse`")))),
359        }
360    } else {
361        let content = resp.text().await?;
362        let entity: Option<CreateTerminalRefundError> = serde_json::from_str(&content).ok();
363        Err(Error::ResponseError(ResponseContent { status, content, entity }))
364    }
365}
366
367/// Dismisses a Terminal action request if the status and type of the request permits it.  See [Link and Dismiss Actions](https://developer.squareup.com/docs/terminal-api/advanced-features/custom-workflows/link-and-dismiss-actions) for more details.
368pub async fn dismiss_terminal_action(configuration: &configuration::Configuration, action_id: &str) -> Result<models::DismissTerminalActionResponse, Error<DismissTerminalActionError>> {
369    // add a prefix to parameters to efficiently prevent name collisions
370    let p_action_id = action_id;
371
372    let uri_str = format!("{}/v2/terminals/actions/{action_id}/dismiss", configuration.base_path, action_id=crate::apis::urlencode(p_action_id));
373    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
374
375    if let Some(ref user_agent) = configuration.user_agent {
376        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
377    }
378    if let Some(ref token) = configuration.oauth_access_token {
379        req_builder = req_builder.bearer_auth(token.to_owned());
380    };
381
382    let req = req_builder.build()?;
383    let resp = configuration.client.execute(req).await?;
384
385    let status = resp.status();
386    let content_type = resp
387        .headers()
388        .get("content-type")
389        .and_then(|v| v.to_str().ok())
390        .unwrap_or("application/octet-stream");
391    let content_type = super::ContentType::from(content_type);
392
393    if !status.is_client_error() && !status.is_server_error() {
394        let content = resp.text().await?;
395        match content_type {
396            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
397            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DismissTerminalActionResponse`"))),
398            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::DismissTerminalActionResponse`")))),
399        }
400    } else {
401        let content = resp.text().await?;
402        let entity: Option<DismissTerminalActionError> = serde_json::from_str(&content).ok();
403        Err(Error::ResponseError(ResponseContent { status, content, entity }))
404    }
405}
406
407/// Dismisses a Terminal checkout request if the status and type of the request permits it.
408pub async fn dismiss_terminal_checkout(configuration: &configuration::Configuration, checkout_id: &str) -> Result<models::DismissTerminalCheckoutResponse, Error<DismissTerminalCheckoutError>> {
409    // add a prefix to parameters to efficiently prevent name collisions
410    let p_checkout_id = checkout_id;
411
412    let uri_str = format!("{}/v2/terminals/checkouts/{checkout_id}/dismiss", configuration.base_path, checkout_id=crate::apis::urlencode(p_checkout_id));
413    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
414
415    if let Some(ref user_agent) = configuration.user_agent {
416        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
417    }
418    if let Some(ref token) = configuration.oauth_access_token {
419        req_builder = req_builder.bearer_auth(token.to_owned());
420    };
421
422    let req = req_builder.build()?;
423    let resp = configuration.client.execute(req).await?;
424
425    let status = resp.status();
426    let content_type = resp
427        .headers()
428        .get("content-type")
429        .and_then(|v| v.to_str().ok())
430        .unwrap_or("application/octet-stream");
431    let content_type = super::ContentType::from(content_type);
432
433    if !status.is_client_error() && !status.is_server_error() {
434        let content = resp.text().await?;
435        match content_type {
436            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
437            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DismissTerminalCheckoutResponse`"))),
438            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::DismissTerminalCheckoutResponse`")))),
439        }
440    } else {
441        let content = resp.text().await?;
442        let entity: Option<DismissTerminalCheckoutError> = serde_json::from_str(&content).ok();
443        Err(Error::ResponseError(ResponseContent { status, content, entity }))
444    }
445}
446
447/// Dismisses a Terminal refund request if the status and type of the request permits it.
448pub async fn dismiss_terminal_refund(configuration: &configuration::Configuration, terminal_refund_id: &str) -> Result<models::DismissTerminalRefundResponse, Error<DismissTerminalRefundError>> {
449    // add a prefix to parameters to efficiently prevent name collisions
450    let p_terminal_refund_id = terminal_refund_id;
451
452    let uri_str = format!("{}/v2/terminals/refunds/{terminal_refund_id}/dismiss", configuration.base_path, terminal_refund_id=crate::apis::urlencode(p_terminal_refund_id));
453    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
454
455    if let Some(ref user_agent) = configuration.user_agent {
456        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
457    }
458    if let Some(ref token) = configuration.oauth_access_token {
459        req_builder = req_builder.bearer_auth(token.to_owned());
460    };
461
462    let req = req_builder.build()?;
463    let resp = configuration.client.execute(req).await?;
464
465    let status = resp.status();
466    let content_type = resp
467        .headers()
468        .get("content-type")
469        .and_then(|v| v.to_str().ok())
470        .unwrap_or("application/octet-stream");
471    let content_type = super::ContentType::from(content_type);
472
473    if !status.is_client_error() && !status.is_server_error() {
474        let content = resp.text().await?;
475        match content_type {
476            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
477            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DismissTerminalRefundResponse`"))),
478            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::DismissTerminalRefundResponse`")))),
479        }
480    } else {
481        let content = resp.text().await?;
482        let entity: Option<DismissTerminalRefundError> = serde_json::from_str(&content).ok();
483        Err(Error::ResponseError(ResponseContent { status, content, entity }))
484    }
485}
486
487/// Retrieves a Terminal action request by `action_id`. Terminal action requests are available for 30 days.
488pub async fn get_terminal_action(configuration: &configuration::Configuration, action_id: &str) -> Result<models::GetTerminalActionResponse, Error<GetTerminalActionError>> {
489    // add a prefix to parameters to efficiently prevent name collisions
490    let p_action_id = action_id;
491
492    let uri_str = format!("{}/v2/terminals/actions/{action_id}", configuration.base_path, action_id=crate::apis::urlencode(p_action_id));
493    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
494
495    if let Some(ref user_agent) = configuration.user_agent {
496        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
497    }
498    if let Some(ref token) = configuration.oauth_access_token {
499        req_builder = req_builder.bearer_auth(token.to_owned());
500    };
501
502    let req = req_builder.build()?;
503    let resp = configuration.client.execute(req).await?;
504
505    let status = resp.status();
506    let content_type = resp
507        .headers()
508        .get("content-type")
509        .and_then(|v| v.to_str().ok())
510        .unwrap_or("application/octet-stream");
511    let content_type = super::ContentType::from(content_type);
512
513    if !status.is_client_error() && !status.is_server_error() {
514        let content = resp.text().await?;
515        match content_type {
516            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
517            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetTerminalActionResponse`"))),
518            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::GetTerminalActionResponse`")))),
519        }
520    } else {
521        let content = resp.text().await?;
522        let entity: Option<GetTerminalActionError> = serde_json::from_str(&content).ok();
523        Err(Error::ResponseError(ResponseContent { status, content, entity }))
524    }
525}
526
527/// Retrieves a Terminal checkout request by `checkout_id`. Terminal checkout requests are available for 30 days.
528pub async fn get_terminal_checkout(configuration: &configuration::Configuration, checkout_id: &str) -> Result<models::GetTerminalCheckoutResponse, Error<GetTerminalCheckoutError>> {
529    // add a prefix to parameters to efficiently prevent name collisions
530    let p_checkout_id = checkout_id;
531
532    let uri_str = format!("{}/v2/terminals/checkouts/{checkout_id}", configuration.base_path, checkout_id=crate::apis::urlencode(p_checkout_id));
533    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
534
535    if let Some(ref user_agent) = configuration.user_agent {
536        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
537    }
538    if let Some(ref token) = configuration.oauth_access_token {
539        req_builder = req_builder.bearer_auth(token.to_owned());
540    };
541
542    let req = req_builder.build()?;
543    let resp = configuration.client.execute(req).await?;
544
545    let status = resp.status();
546    let content_type = resp
547        .headers()
548        .get("content-type")
549        .and_then(|v| v.to_str().ok())
550        .unwrap_or("application/octet-stream");
551    let content_type = super::ContentType::from(content_type);
552
553    if !status.is_client_error() && !status.is_server_error() {
554        let content = resp.text().await?;
555        match content_type {
556            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
557            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetTerminalCheckoutResponse`"))),
558            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::GetTerminalCheckoutResponse`")))),
559        }
560    } else {
561        let content = resp.text().await?;
562        let entity: Option<GetTerminalCheckoutError> = serde_json::from_str(&content).ok();
563        Err(Error::ResponseError(ResponseContent { status, content, entity }))
564    }
565}
566
567/// Retrieves an Interac Terminal refund object by ID. Terminal refund objects are available for 30 days.
568pub async fn get_terminal_refund(configuration: &configuration::Configuration, terminal_refund_id: &str) -> Result<models::GetTerminalRefundResponse, Error<GetTerminalRefundError>> {
569    // add a prefix to parameters to efficiently prevent name collisions
570    let p_terminal_refund_id = terminal_refund_id;
571
572    let uri_str = format!("{}/v2/terminals/refunds/{terminal_refund_id}", configuration.base_path, terminal_refund_id=crate::apis::urlencode(p_terminal_refund_id));
573    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
574
575    if let Some(ref user_agent) = configuration.user_agent {
576        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
577    }
578    if let Some(ref token) = configuration.oauth_access_token {
579        req_builder = req_builder.bearer_auth(token.to_owned());
580    };
581
582    let req = req_builder.build()?;
583    let resp = configuration.client.execute(req).await?;
584
585    let status = resp.status();
586    let content_type = resp
587        .headers()
588        .get("content-type")
589        .and_then(|v| v.to_str().ok())
590        .unwrap_or("application/octet-stream");
591    let content_type = super::ContentType::from(content_type);
592
593    if !status.is_client_error() && !status.is_server_error() {
594        let content = resp.text().await?;
595        match content_type {
596            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
597            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetTerminalRefundResponse`"))),
598            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::GetTerminalRefundResponse`")))),
599        }
600    } else {
601        let content = resp.text().await?;
602        let entity: Option<GetTerminalRefundError> = serde_json::from_str(&content).ok();
603        Err(Error::ResponseError(ResponseContent { status, content, entity }))
604    }
605}
606
607/// Retrieves a filtered list of Terminal action requests created by the account making the request. Terminal action requests are available for 30 days.
608pub async fn search_terminal_actions(configuration: &configuration::Configuration, search_terminal_actions_request: models::SearchTerminalActionsRequest) -> Result<models::SearchTerminalActionsResponse, Error<SearchTerminalActionsError>> {
609    // add a prefix to parameters to efficiently prevent name collisions
610    let p_search_terminal_actions_request = search_terminal_actions_request;
611
612    let uri_str = format!("{}/v2/terminals/actions/search", configuration.base_path);
613    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
614
615    if let Some(ref user_agent) = configuration.user_agent {
616        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
617    }
618    if let Some(ref token) = configuration.oauth_access_token {
619        req_builder = req_builder.bearer_auth(token.to_owned());
620    };
621    req_builder = req_builder.json(&p_search_terminal_actions_request);
622
623    let req = req_builder.build()?;
624    let resp = configuration.client.execute(req).await?;
625
626    let status = resp.status();
627    let content_type = resp
628        .headers()
629        .get("content-type")
630        .and_then(|v| v.to_str().ok())
631        .unwrap_or("application/octet-stream");
632    let content_type = super::ContentType::from(content_type);
633
634    if !status.is_client_error() && !status.is_server_error() {
635        let content = resp.text().await?;
636        match content_type {
637            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
638            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SearchTerminalActionsResponse`"))),
639            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::SearchTerminalActionsResponse`")))),
640        }
641    } else {
642        let content = resp.text().await?;
643        let entity: Option<SearchTerminalActionsError> = serde_json::from_str(&content).ok();
644        Err(Error::ResponseError(ResponseContent { status, content, entity }))
645    }
646}
647
648/// Returns a filtered list of Terminal checkout requests created by the application making the request. Only Terminal checkout requests created for the merchant scoped to the OAuth token are returned. Terminal checkout requests are available for 30 days.
649pub async fn search_terminal_checkouts(configuration: &configuration::Configuration, search_terminal_checkouts_request: models::SearchTerminalCheckoutsRequest) -> Result<models::SearchTerminalCheckoutsResponse, Error<SearchTerminalCheckoutsError>> {
650    // add a prefix to parameters to efficiently prevent name collisions
651    let p_search_terminal_checkouts_request = search_terminal_checkouts_request;
652
653    let uri_str = format!("{}/v2/terminals/checkouts/search", configuration.base_path);
654    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
655
656    if let Some(ref user_agent) = configuration.user_agent {
657        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
658    }
659    if let Some(ref token) = configuration.oauth_access_token {
660        req_builder = req_builder.bearer_auth(token.to_owned());
661    };
662    req_builder = req_builder.json(&p_search_terminal_checkouts_request);
663
664    let req = req_builder.build()?;
665    let resp = configuration.client.execute(req).await?;
666
667    let status = resp.status();
668    let content_type = resp
669        .headers()
670        .get("content-type")
671        .and_then(|v| v.to_str().ok())
672        .unwrap_or("application/octet-stream");
673    let content_type = super::ContentType::from(content_type);
674
675    if !status.is_client_error() && !status.is_server_error() {
676        let content = resp.text().await?;
677        match content_type {
678            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
679            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SearchTerminalCheckoutsResponse`"))),
680            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::SearchTerminalCheckoutsResponse`")))),
681        }
682    } else {
683        let content = resp.text().await?;
684        let entity: Option<SearchTerminalCheckoutsError> = serde_json::from_str(&content).ok();
685        Err(Error::ResponseError(ResponseContent { status, content, entity }))
686    }
687}
688
689/// Retrieves a filtered list of Interac Terminal refund requests created by the seller making the request. Terminal refund requests are available for 30 days.
690pub async fn search_terminal_refunds(configuration: &configuration::Configuration, search_terminal_refunds_request: models::SearchTerminalRefundsRequest) -> Result<models::SearchTerminalRefundsResponse, Error<SearchTerminalRefundsError>> {
691    // add a prefix to parameters to efficiently prevent name collisions
692    let p_search_terminal_refunds_request = search_terminal_refunds_request;
693
694    let uri_str = format!("{}/v2/terminals/refunds/search", configuration.base_path);
695    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
696
697    if let Some(ref user_agent) = configuration.user_agent {
698        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
699    }
700    if let Some(ref token) = configuration.oauth_access_token {
701        req_builder = req_builder.bearer_auth(token.to_owned());
702    };
703    req_builder = req_builder.json(&p_search_terminal_refunds_request);
704
705    let req = req_builder.build()?;
706    let resp = configuration.client.execute(req).await?;
707
708    let status = resp.status();
709    let content_type = resp
710        .headers()
711        .get("content-type")
712        .and_then(|v| v.to_str().ok())
713        .unwrap_or("application/octet-stream");
714    let content_type = super::ContentType::from(content_type);
715
716    if !status.is_client_error() && !status.is_server_error() {
717        let content = resp.text().await?;
718        match content_type {
719            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
720            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SearchTerminalRefundsResponse`"))),
721            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::SearchTerminalRefundsResponse`")))),
722        }
723    } else {
724        let content = resp.text().await?;
725        let entity: Option<SearchTerminalRefundsError> = serde_json::from_str(&content).ok();
726        Err(Error::ResponseError(ResponseContent { status, content, entity }))
727    }
728}
729