bitwarden_api_api/apis/
misc_api.rs1use reqwest;
12use serde::{de::Error as _, Deserialize, Serialize};
13
14use super::{configuration, ContentType, Error};
15use crate::{apis::ResponseContent, models};
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum BitpayInvoicePostError {
21 UnknownValue(serde_json::Value),
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum SetupPaymentPostError {
28 UnknownValue(serde_json::Value),
29}
30
31pub async fn bitpay_invoice_post(
32 configuration: &configuration::Configuration,
33 bit_pay_invoice_request_model: Option<models::BitPayInvoiceRequestModel>,
34) -> Result<String, Error<BitpayInvoicePostError>> {
35 let p_bit_pay_invoice_request_model = bit_pay_invoice_request_model;
37
38 let uri_str = format!("{}/bitpay-invoice", configuration.base_path);
39 let mut req_builder = configuration
40 .client
41 .request(reqwest::Method::POST, &uri_str);
42
43 if let Some(ref user_agent) = configuration.user_agent {
44 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
45 }
46 if let Some(ref token) = configuration.oauth_access_token {
47 req_builder = req_builder.bearer_auth(token.to_owned());
48 };
49 req_builder = req_builder.json(&p_bit_pay_invoice_request_model);
50
51 let req = req_builder.build()?;
52 let resp = configuration.client.execute(req).await?;
53
54 let status = resp.status();
55 let content_type = resp
56 .headers()
57 .get("content-type")
58 .and_then(|v| v.to_str().ok())
59 .unwrap_or("application/octet-stream");
60 let content_type = super::ContentType::from(content_type);
61
62 if !status.is_client_error() && !status.is_server_error() {
63 let content = resp.text().await?;
64 match content_type {
65 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
66 ContentType::Text => return Ok(content),
67 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `String`")))),
68 }
69 } else {
70 let content = resp.text().await?;
71 let entity: Option<BitpayInvoicePostError> = serde_json::from_str(&content).ok();
72 Err(Error::ResponseError(ResponseContent {
73 status,
74 content,
75 entity,
76 }))
77 }
78}
79
80pub async fn setup_payment_post(
81 configuration: &configuration::Configuration,
82) -> Result<String, Error<SetupPaymentPostError>> {
83 let uri_str = format!("{}/setup-payment", configuration.base_path);
84 let mut req_builder = configuration
85 .client
86 .request(reqwest::Method::POST, &uri_str);
87
88 if let Some(ref user_agent) = configuration.user_agent {
89 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
90 }
91 if let Some(ref token) = configuration.oauth_access_token {
92 req_builder = req_builder.bearer_auth(token.to_owned());
93 };
94
95 let req = req_builder.build()?;
96 let resp = configuration.client.execute(req).await?;
97
98 let status = resp.status();
99 let content_type = resp
100 .headers()
101 .get("content-type")
102 .and_then(|v| v.to_str().ok())
103 .unwrap_or("application/octet-stream");
104 let content_type = super::ContentType::from(content_type);
105
106 if !status.is_client_error() && !status.is_server_error() {
107 let content = resp.text().await?;
108 match content_type {
109 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
110 ContentType::Text => return Ok(content),
111 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `String`")))),
112 }
113 } else {
114 let content = resp.text().await?;
115 let entity: Option<SetupPaymentPostError> = serde_json::from_str(&content).ok();
116 Err(Error::ResponseError(ResponseContent {
117 status,
118 content,
119 entity,
120 }))
121 }
122}