1use std::sync::Arc;
12
13use async_trait::async_trait;
14#[cfg(feature = "mockall")]
15use mockall::automock;
16use reqwest;
17use serde::{Deserialize, Serialize, de::Error as _};
18
19use super::{Error, configuration};
20use crate::{
21 apis::{ContentType, ResponseContent},
22 models,
23};
24
25#[cfg_attr(feature = "mockall", automock)]
26#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
27#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
28pub trait ProviderBillingApi: Send + Sync {
29 async fn generate_client_invoice_report<'a>(
31 &self,
32 provider_id: uuid::Uuid,
33 invoice_id: &'a str,
34 ) -> Result<(), Error<GenerateClientInvoiceReportError>>;
35
36 async fn get_invoices<'a>(
38 &self,
39 provider_id: uuid::Uuid,
40 ) -> Result<(), Error<GetInvoicesError>>;
41
42 async fn get_subscription<'a>(
44 &self,
45 provider_id: uuid::Uuid,
46 ) -> Result<(), Error<GetSubscriptionError>>;
47
48 async fn get_tax_information<'a>(
50 &self,
51 provider_id: uuid::Uuid,
52 ) -> Result<(), Error<GetTaxInformationError>>;
53
54 async fn update_payment_method<'a>(
56 &self,
57 provider_id: uuid::Uuid,
58 update_payment_method_request_body: Option<models::UpdatePaymentMethodRequestBody>,
59 ) -> Result<(), Error<UpdatePaymentMethodError>>;
60
61 async fn update_tax_information<'a>(
63 &self,
64 provider_id: uuid::Uuid,
65 tax_information_request_body: Option<models::TaxInformationRequestBody>,
66 ) -> Result<(), Error<UpdateTaxInformationError>>;
67
68 async fn verify_bank_account<'a>(
70 &self,
71 provider_id: uuid::Uuid,
72 verify_bank_account_request_body: Option<models::VerifyBankAccountRequestBody>,
73 ) -> Result<(), Error<VerifyBankAccountError>>;
74}
75
76pub struct ProviderBillingApiClient {
77 configuration: Arc<configuration::Configuration>,
78}
79
80impl ProviderBillingApiClient {
81 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
82 Self { configuration }
83 }
84}
85
86#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
87#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
88impl ProviderBillingApi for ProviderBillingApiClient {
89 async fn generate_client_invoice_report<'a>(
90 &self,
91 provider_id: uuid::Uuid,
92 invoice_id: &'a str,
93 ) -> Result<(), Error<GenerateClientInvoiceReportError>> {
94 let local_var_configuration = &self.configuration;
95
96 let local_var_client = &local_var_configuration.client;
97
98 let local_var_uri_str = format!(
99 "{}/providers/{providerId}/billing/invoices/{invoiceId}",
100 local_var_configuration.base_path,
101 providerId = provider_id,
102 invoiceId = crate::apis::urlencode(invoice_id)
103 );
104 let mut local_var_req_builder =
105 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
106
107 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
108 local_var_req_builder = local_var_req_builder
109 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
110 }
111 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
112 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
113 };
114
115 let local_var_req = local_var_req_builder.build()?;
116 let local_var_resp = local_var_client.execute(local_var_req).await?;
117
118 let local_var_status = local_var_resp.status();
119 let local_var_content = local_var_resp.text().await?;
120
121 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
122 Ok(())
123 } else {
124 let local_var_entity: Option<GenerateClientInvoiceReportError> =
125 serde_json::from_str(&local_var_content).ok();
126 let local_var_error = ResponseContent {
127 status: local_var_status,
128 content: local_var_content,
129 entity: local_var_entity,
130 };
131 Err(Error::ResponseError(local_var_error))
132 }
133 }
134
135 async fn get_invoices<'a>(
136 &self,
137 provider_id: uuid::Uuid,
138 ) -> Result<(), Error<GetInvoicesError>> {
139 let local_var_configuration = &self.configuration;
140
141 let local_var_client = &local_var_configuration.client;
142
143 let local_var_uri_str = format!(
144 "{}/providers/{providerId}/billing/invoices",
145 local_var_configuration.base_path,
146 providerId = provider_id
147 );
148 let mut local_var_req_builder =
149 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
150
151 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
152 local_var_req_builder = local_var_req_builder
153 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
154 }
155 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
156 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
157 };
158
159 let local_var_req = local_var_req_builder.build()?;
160 let local_var_resp = local_var_client.execute(local_var_req).await?;
161
162 let local_var_status = local_var_resp.status();
163 let local_var_content = local_var_resp.text().await?;
164
165 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
166 Ok(())
167 } else {
168 let local_var_entity: Option<GetInvoicesError> =
169 serde_json::from_str(&local_var_content).ok();
170 let local_var_error = ResponseContent {
171 status: local_var_status,
172 content: local_var_content,
173 entity: local_var_entity,
174 };
175 Err(Error::ResponseError(local_var_error))
176 }
177 }
178
179 async fn get_subscription<'a>(
180 &self,
181 provider_id: uuid::Uuid,
182 ) -> Result<(), Error<GetSubscriptionError>> {
183 let local_var_configuration = &self.configuration;
184
185 let local_var_client = &local_var_configuration.client;
186
187 let local_var_uri_str = format!(
188 "{}/providers/{providerId}/billing/subscription",
189 local_var_configuration.base_path,
190 providerId = provider_id
191 );
192 let mut local_var_req_builder =
193 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
194
195 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
196 local_var_req_builder = local_var_req_builder
197 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
198 }
199 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
200 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
201 };
202
203 let local_var_req = local_var_req_builder.build()?;
204 let local_var_resp = local_var_client.execute(local_var_req).await?;
205
206 let local_var_status = local_var_resp.status();
207 let local_var_content = local_var_resp.text().await?;
208
209 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
210 Ok(())
211 } else {
212 let local_var_entity: Option<GetSubscriptionError> =
213 serde_json::from_str(&local_var_content).ok();
214 let local_var_error = ResponseContent {
215 status: local_var_status,
216 content: local_var_content,
217 entity: local_var_entity,
218 };
219 Err(Error::ResponseError(local_var_error))
220 }
221 }
222
223 async fn get_tax_information<'a>(
224 &self,
225 provider_id: uuid::Uuid,
226 ) -> Result<(), Error<GetTaxInformationError>> {
227 let local_var_configuration = &self.configuration;
228
229 let local_var_client = &local_var_configuration.client;
230
231 let local_var_uri_str = format!(
232 "{}/providers/{providerId}/billing/tax-information",
233 local_var_configuration.base_path,
234 providerId = provider_id
235 );
236 let mut local_var_req_builder =
237 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
238
239 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
240 local_var_req_builder = local_var_req_builder
241 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
242 }
243 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
244 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
245 };
246
247 let local_var_req = local_var_req_builder.build()?;
248 let local_var_resp = local_var_client.execute(local_var_req).await?;
249
250 let local_var_status = local_var_resp.status();
251 let local_var_content = local_var_resp.text().await?;
252
253 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
254 Ok(())
255 } else {
256 let local_var_entity: Option<GetTaxInformationError> =
257 serde_json::from_str(&local_var_content).ok();
258 let local_var_error = ResponseContent {
259 status: local_var_status,
260 content: local_var_content,
261 entity: local_var_entity,
262 };
263 Err(Error::ResponseError(local_var_error))
264 }
265 }
266
267 async fn update_payment_method<'a>(
268 &self,
269 provider_id: uuid::Uuid,
270 update_payment_method_request_body: Option<models::UpdatePaymentMethodRequestBody>,
271 ) -> Result<(), Error<UpdatePaymentMethodError>> {
272 let local_var_configuration = &self.configuration;
273
274 let local_var_client = &local_var_configuration.client;
275
276 let local_var_uri_str = format!(
277 "{}/providers/{providerId}/billing/payment-method",
278 local_var_configuration.base_path,
279 providerId = provider_id
280 );
281 let mut local_var_req_builder =
282 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
283
284 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
285 local_var_req_builder = local_var_req_builder
286 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
287 }
288 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
289 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
290 };
291 local_var_req_builder = local_var_req_builder.json(&update_payment_method_request_body);
292
293 let local_var_req = local_var_req_builder.build()?;
294 let local_var_resp = local_var_client.execute(local_var_req).await?;
295
296 let local_var_status = local_var_resp.status();
297 let local_var_content = local_var_resp.text().await?;
298
299 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
300 Ok(())
301 } else {
302 let local_var_entity: Option<UpdatePaymentMethodError> =
303 serde_json::from_str(&local_var_content).ok();
304 let local_var_error = ResponseContent {
305 status: local_var_status,
306 content: local_var_content,
307 entity: local_var_entity,
308 };
309 Err(Error::ResponseError(local_var_error))
310 }
311 }
312
313 async fn update_tax_information<'a>(
314 &self,
315 provider_id: uuid::Uuid,
316 tax_information_request_body: Option<models::TaxInformationRequestBody>,
317 ) -> Result<(), Error<UpdateTaxInformationError>> {
318 let local_var_configuration = &self.configuration;
319
320 let local_var_client = &local_var_configuration.client;
321
322 let local_var_uri_str = format!(
323 "{}/providers/{providerId}/billing/tax-information",
324 local_var_configuration.base_path,
325 providerId = provider_id
326 );
327 let mut local_var_req_builder =
328 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
329
330 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
331 local_var_req_builder = local_var_req_builder
332 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
333 }
334 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
335 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
336 };
337 local_var_req_builder = local_var_req_builder.json(&tax_information_request_body);
338
339 let local_var_req = local_var_req_builder.build()?;
340 let local_var_resp = local_var_client.execute(local_var_req).await?;
341
342 let local_var_status = local_var_resp.status();
343 let local_var_content = local_var_resp.text().await?;
344
345 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
346 Ok(())
347 } else {
348 let local_var_entity: Option<UpdateTaxInformationError> =
349 serde_json::from_str(&local_var_content).ok();
350 let local_var_error = ResponseContent {
351 status: local_var_status,
352 content: local_var_content,
353 entity: local_var_entity,
354 };
355 Err(Error::ResponseError(local_var_error))
356 }
357 }
358
359 async fn verify_bank_account<'a>(
360 &self,
361 provider_id: uuid::Uuid,
362 verify_bank_account_request_body: Option<models::VerifyBankAccountRequestBody>,
363 ) -> Result<(), Error<VerifyBankAccountError>> {
364 let local_var_configuration = &self.configuration;
365
366 let local_var_client = &local_var_configuration.client;
367
368 let local_var_uri_str = format!(
369 "{}/providers/{providerId}/billing/payment-method/verify-bank-account",
370 local_var_configuration.base_path,
371 providerId = provider_id
372 );
373 let mut local_var_req_builder =
374 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
375
376 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
377 local_var_req_builder = local_var_req_builder
378 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
379 }
380 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
381 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
382 };
383 local_var_req_builder = local_var_req_builder.json(&verify_bank_account_request_body);
384
385 let local_var_req = local_var_req_builder.build()?;
386 let local_var_resp = local_var_client.execute(local_var_req).await?;
387
388 let local_var_status = local_var_resp.status();
389 let local_var_content = local_var_resp.text().await?;
390
391 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
392 Ok(())
393 } else {
394 let local_var_entity: Option<VerifyBankAccountError> =
395 serde_json::from_str(&local_var_content).ok();
396 let local_var_error = ResponseContent {
397 status: local_var_status,
398 content: local_var_content,
399 entity: local_var_entity,
400 };
401 Err(Error::ResponseError(local_var_error))
402 }
403 }
404}
405
406#[derive(Debug, Clone, Serialize, Deserialize)]
408#[serde(untagged)]
409pub enum GenerateClientInvoiceReportError {
410 UnknownValue(serde_json::Value),
411}
412#[derive(Debug, Clone, Serialize, Deserialize)]
414#[serde(untagged)]
415pub enum GetInvoicesError {
416 UnknownValue(serde_json::Value),
417}
418#[derive(Debug, Clone, Serialize, Deserialize)]
420#[serde(untagged)]
421pub enum GetSubscriptionError {
422 UnknownValue(serde_json::Value),
423}
424#[derive(Debug, Clone, Serialize, Deserialize)]
426#[serde(untagged)]
427pub enum GetTaxInformationError {
428 UnknownValue(serde_json::Value),
429}
430#[derive(Debug, Clone, Serialize, Deserialize)]
432#[serde(untagged)]
433pub enum UpdatePaymentMethodError {
434 UnknownValue(serde_json::Value),
435}
436#[derive(Debug, Clone, Serialize, Deserialize)]
438#[serde(untagged)]
439pub enum UpdateTaxInformationError {
440 UnknownValue(serde_json::Value),
441}
442#[derive(Debug, Clone, Serialize, Deserialize)]
444#[serde(untagged)]
445pub enum VerifyBankAccountError {
446 UnknownValue(serde_json::Value),
447}