trieve_client/apis/
stripe_api.rs

1/*
2 * Trieve API
3 *
4 * Trieve OpenAPI Specification. This document describes all of the operations available through the Trieve API.
5 *
6 * The version of the OpenAPI document: 0.11.7
7 * Contact: developers@trieve.ai
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`cancel_subscription`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CancelSubscriptionError {
22    Status400(models::ErrorResponseBody),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`create_setup_checkout_session`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum CreateSetupCheckoutSessionError {
30    Status400(models::ErrorResponseBody),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`direct_to_payment_link`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum DirectToPaymentLinkError {
38    Status400(models::ErrorResponseBody),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`get_all_invoices`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum GetAllInvoicesError {
46    Status400(models::ErrorResponseBody),
47    UnknownValue(serde_json::Value),
48}
49
50/// struct for typed errors of method [`get_all_plans`]
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum GetAllPlansError {
54    Status400(models::ErrorResponseBody),
55    UnknownValue(serde_json::Value),
56}
57
58/// struct for typed errors of method [`update_subscription_plan`]
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum UpdateSubscriptionPlanError {
62    Status400(models::ErrorResponseBody),
63    UnknownValue(serde_json::Value),
64}
65
66
67/// Cancel a subscription by its id
68pub async fn cancel_subscription(configuration: &configuration::Configuration, tr_organization: &str, subscription_id: &str) -> Result<(), Error<CancelSubscriptionError>> {
69    let local_var_configuration = configuration;
70
71    let local_var_client = &local_var_configuration.client;
72
73    let local_var_uri_str = format!("{}/api/stripe/subscription/{subscription_id}", local_var_configuration.base_path, subscription_id=crate::apis::urlencode(subscription_id));
74    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
75
76    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
77        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
78    }
79    local_var_req_builder = local_var_req_builder.header("TR-Organization", tr_organization.to_string());
80    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
81        let local_var_key = local_var_apikey.key.clone();
82        let local_var_value = match local_var_apikey.prefix {
83            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
84            None => local_var_key,
85        };
86        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
87    };
88
89    let local_var_req = local_var_req_builder.build()?;
90    let local_var_resp = local_var_client.execute(local_var_req).await?;
91
92    let local_var_status = local_var_resp.status();
93    let local_var_content = local_var_resp.text().await?;
94
95    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
96        Ok(())
97    } else {
98        let local_var_entity: Option<CancelSubscriptionError> = serde_json::from_str(&local_var_content).ok();
99        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
100        Err(Error::ResponseError(local_var_error))
101    }
102}
103
104/// Create a checkout session (setup)
105pub async fn create_setup_checkout_session(configuration: &configuration::Configuration, organization_id: &str) -> Result<models::CreateSetupCheckoutSessionResPayload, Error<CreateSetupCheckoutSessionError>> {
106    let local_var_configuration = configuration;
107
108    let local_var_client = &local_var_configuration.client;
109
110    let local_var_uri_str = format!("{}/api/stripe/checkout/setup/{organization_id}", local_var_configuration.base_path, organization_id=crate::apis::urlencode(organization_id));
111    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
112
113    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
114        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
115    }
116
117    let local_var_req = local_var_req_builder.build()?;
118    let local_var_resp = local_var_client.execute(local_var_req).await?;
119
120    let local_var_status = local_var_resp.status();
121    let local_var_content = local_var_resp.text().await?;
122
123    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
124        serde_json::from_str(&local_var_content).map_err(Error::from)
125    } else {
126        let local_var_entity: Option<CreateSetupCheckoutSessionError> = serde_json::from_str(&local_var_content).ok();
127        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
128        Err(Error::ResponseError(local_var_error))
129    }
130}
131
132/// Get a 303 SeeOther redirect link to the stripe checkout page for the plan and organization
133pub async fn direct_to_payment_link(configuration: &configuration::Configuration, plan_id: &str, organization_id: &str) -> Result<(), Error<DirectToPaymentLinkError>> {
134    let local_var_configuration = configuration;
135
136    let local_var_client = &local_var_configuration.client;
137
138    let local_var_uri_str = format!("{}/api/stripe/payment_link/{plan_id}/{organization_id}", local_var_configuration.base_path, plan_id=crate::apis::urlencode(plan_id), organization_id=crate::apis::urlencode(organization_id));
139    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
140
141    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
142        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
143    }
144
145    let local_var_req = local_var_req_builder.build()?;
146    let local_var_resp = local_var_client.execute(local_var_req).await?;
147
148    let local_var_status = local_var_resp.status();
149    let local_var_content = local_var_resp.text().await?;
150
151    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
152        Ok(())
153    } else {
154        let local_var_entity: Option<DirectToPaymentLinkError> = serde_json::from_str(&local_var_content).ok();
155        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
156        Err(Error::ResponseError(local_var_error))
157    }
158}
159
160/// Get a list of all invoices
161pub async fn get_all_invoices(configuration: &configuration::Configuration, organization_id: &str) -> Result<Vec<models::StripeInvoice>, Error<GetAllInvoicesError>> {
162    let local_var_configuration = configuration;
163
164    let local_var_client = &local_var_configuration.client;
165
166    let local_var_uri_str = format!("{}/api/stripe/invoices/{organization_id}", local_var_configuration.base_path, organization_id=crate::apis::urlencode(organization_id));
167    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
168
169    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
170        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
171    }
172
173    let local_var_req = local_var_req_builder.build()?;
174    let local_var_resp = local_var_client.execute(local_var_req).await?;
175
176    let local_var_status = local_var_resp.status();
177    let local_var_content = local_var_resp.text().await?;
178
179    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
180        serde_json::from_str(&local_var_content).map_err(Error::from)
181    } else {
182        let local_var_entity: Option<GetAllInvoicesError> = serde_json::from_str(&local_var_content).ok();
183        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
184        Err(Error::ResponseError(local_var_error))
185    }
186}
187
188/// Get a list of all plans
189pub async fn get_all_plans(configuration: &configuration::Configuration, ) -> Result<Vec<models::StripePlan>, Error<GetAllPlansError>> {
190    let local_var_configuration = configuration;
191
192    let local_var_client = &local_var_configuration.client;
193
194    let local_var_uri_str = format!("{}/api/stripe/plans", local_var_configuration.base_path);
195    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
196
197    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
198        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
199    }
200
201    let local_var_req = local_var_req_builder.build()?;
202    let local_var_resp = local_var_client.execute(local_var_req).await?;
203
204    let local_var_status = local_var_resp.status();
205    let local_var_content = local_var_resp.text().await?;
206
207    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
208        serde_json::from_str(&local_var_content).map_err(Error::from)
209    } else {
210        let local_var_entity: Option<GetAllPlansError> = serde_json::from_str(&local_var_content).ok();
211        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
212        Err(Error::ResponseError(local_var_error))
213    }
214}
215
216/// Update a subscription to a new plan
217pub async fn update_subscription_plan(configuration: &configuration::Configuration, tr_organization: &str, subscription_id: &str, plan_id: &str) -> Result<(), Error<UpdateSubscriptionPlanError>> {
218    let local_var_configuration = configuration;
219
220    let local_var_client = &local_var_configuration.client;
221
222    let local_var_uri_str = format!("{}/api/stripe/subscription_plan/{subscription_id}/{plan_id}", local_var_configuration.base_path, subscription_id=crate::apis::urlencode(subscription_id), plan_id=crate::apis::urlencode(plan_id));
223    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
224
225    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
226        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
227    }
228    local_var_req_builder = local_var_req_builder.header("TR-Organization", tr_organization.to_string());
229    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
230        let local_var_key = local_var_apikey.key.clone();
231        let local_var_value = match local_var_apikey.prefix {
232            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
233            None => local_var_key,
234        };
235        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
236    };
237
238    let local_var_req = local_var_req_builder.build()?;
239    let local_var_resp = local_var_client.execute(local_var_req).await?;
240
241    let local_var_status = local_var_resp.status();
242    let local_var_content = local_var_resp.text().await?;
243
244    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
245        Ok(())
246    } else {
247        let local_var_entity: Option<UpdateSubscriptionPlanError> = serde_json::from_str(&local_var_content).ok();
248        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
249        Err(Error::ResponseError(local_var_error))
250    }
251}
252