btcpay_client/apis/
miscelleneous_api.rs

1/*
2 * BTCPay Greenfield API
3 *
4 * A full API to use your BTCPay Server
5 *
6 * The version of the OpenAPI document: v1
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`invoice_checkout`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum InvoiceCheckoutError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`lang_codes`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum LangCodesError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`permissions_metadata`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum PermissionsMetadataError {
36    UnknownValue(serde_json::Value),
37}
38
39
40/// View the checkout page of an invoice
41pub async fn invoice_checkout(configuration: &configuration::Configuration, invoice_id: &str, lang: Option<&str>) -> Result<(), Error<InvoiceCheckoutError>> {
42    let local_var_configuration = configuration;
43
44    let local_var_client = &local_var_configuration.client;
45
46    let local_var_uri_str = format!("{}/i/{invoiceId}", local_var_configuration.base_path, invoiceId=crate::apis::urlencode(invoice_id));
47    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
48
49    if let Some(ref local_var_str) = lang {
50        local_var_req_builder = local_var_req_builder.query(&[("lang", &local_var_str.to_string())]);
51    }
52    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
53        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
54    }
55
56    let local_var_req = local_var_req_builder.build()?;
57    let local_var_resp = local_var_client.execute(local_var_req).await?;
58
59    let local_var_status = local_var_resp.status();
60    let local_var_content = local_var_resp.text().await?;
61
62    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
63        Ok(())
64    } else {
65        let local_var_entity: Option<InvoiceCheckoutError> = serde_json::from_str(&local_var_content).ok();
66        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
67        Err(Error::ResponseError(local_var_error))
68    }
69}
70
71/// The supported language codes
72pub async fn lang_codes(configuration: &configuration::Configuration, ) -> Result<Vec<crate::models::LangCodes200ResponseInner>, Error<LangCodesError>> {
73    let local_var_configuration = configuration;
74
75    let local_var_client = &local_var_configuration.client;
76
77    let local_var_uri_str = format!("{}/misc/lang", local_var_configuration.base_path);
78    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
79
80    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
81        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
82    }
83
84    let local_var_req = local_var_req_builder.build()?;
85    let local_var_resp = local_var_client.execute(local_var_req).await?;
86
87    let local_var_status = local_var_resp.status();
88    let local_var_content = local_var_resp.text().await?;
89
90    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
91        serde_json::from_str(&local_var_content).map_err(Error::from)
92    } else {
93        let local_var_entity: Option<LangCodesError> = serde_json::from_str(&local_var_content).ok();
94        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
95        Err(Error::ResponseError(local_var_error))
96    }
97}
98
99/// The metadata of available permissions
100pub async fn permissions_metadata(configuration: &configuration::Configuration, ) -> Result<Vec<crate::models::PermissionsMetadata200ResponseInner>, Error<PermissionsMetadataError>> {
101    let local_var_configuration = configuration;
102
103    let local_var_client = &local_var_configuration.client;
104
105    let local_var_uri_str = format!("{}/misc/permissions", local_var_configuration.base_path);
106    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
107
108    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
109        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
110    }
111
112    let local_var_req = local_var_req_builder.build()?;
113    let local_var_resp = local_var_client.execute(local_var_req).await?;
114
115    let local_var_status = local_var_resp.status();
116    let local_var_content = local_var_resp.text().await?;
117
118    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
119        serde_json::from_str(&local_var_content).map_err(Error::from)
120    } else {
121        let local_var_entity: Option<PermissionsMetadataError> = serde_json::from_str(&local_var_content).ok();
122        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
123        Err(Error::ResponseError(local_var_error))
124    }
125}
126