1use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AddRecurringSubscriptionError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum AddSubscriptionInstallmentError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum CancelRecurringSubscriptionError {
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum DeleteSubscriptionError {
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum FindSubscriptionByDealError {
50 UnknownValue(serde_json::Value),
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum GetSubscriptionError {
57 UnknownValue(serde_json::Value),
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum GetSubscriptionPaymentsError {
64 UnknownValue(serde_json::Value),
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum UpdateRecurringSubscriptionError {
71 UnknownValue(serde_json::Value),
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum UpdateSubscriptionInstallmentError {
78 UnknownValue(serde_json::Value),
79}
80
81
82pub async fn add_recurring_subscription(configuration: &configuration::Configuration, add_recurring_subscription_request: Option<crate::models::AddRecurringSubscriptionRequest>) -> Result<crate::models::SubscriptionsIdResponse200, Error<AddRecurringSubscriptionError>> {
84 let local_var_configuration = configuration;
85
86 let local_var_client = &local_var_configuration.client;
87
88 let local_var_uri_str = format!("{}/subscriptions/recurring", local_var_configuration.base_path);
89 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
90
91 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
92 let local_var_key = local_var_apikey.key.clone();
93 let local_var_value = match local_var_apikey.prefix {
94 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
95 None => local_var_key,
96 };
97 local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
98 }
99 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
100 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
101 }
102 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
103 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
104 };
105 local_var_req_builder = local_var_req_builder.json(&add_recurring_subscription_request);
106
107 let local_var_req = local_var_req_builder.build()?;
108 let local_var_resp = local_var_client.execute(local_var_req).await?;
109
110 let local_var_status = local_var_resp.status();
111 let local_var_content = local_var_resp.text().await?;
112
113 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
114 serde_json::from_str(&local_var_content).map_err(Error::from)
115 } else {
116 let local_var_entity: Option<AddRecurringSubscriptionError> = serde_json::from_str(&local_var_content).ok();
117 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
118 Err(Error::ResponseError(local_var_error))
119 }
120}
121
122pub async fn add_subscription_installment(configuration: &configuration::Configuration, add_subscription_installment_request: Option<crate::models::AddSubscriptionInstallmentRequest>) -> Result<crate::models::SubscriptionsIdResponse200, Error<AddSubscriptionInstallmentError>> {
124 let local_var_configuration = configuration;
125
126 let local_var_client = &local_var_configuration.client;
127
128 let local_var_uri_str = format!("{}/subscriptions/installment", local_var_configuration.base_path);
129 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
130
131 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
132 let local_var_key = local_var_apikey.key.clone();
133 let local_var_value = match local_var_apikey.prefix {
134 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
135 None => local_var_key,
136 };
137 local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
138 }
139 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
140 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
141 }
142 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
143 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
144 };
145 local_var_req_builder = local_var_req_builder.json(&add_subscription_installment_request);
146
147 let local_var_req = local_var_req_builder.build()?;
148 let local_var_resp = local_var_client.execute(local_var_req).await?;
149
150 let local_var_status = local_var_resp.status();
151 let local_var_content = local_var_resp.text().await?;
152
153 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
154 serde_json::from_str(&local_var_content).map_err(Error::from)
155 } else {
156 let local_var_entity: Option<AddSubscriptionInstallmentError> = serde_json::from_str(&local_var_content).ok();
157 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
158 Err(Error::ResponseError(local_var_error))
159 }
160}
161
162pub async fn cancel_recurring_subscription(configuration: &configuration::Configuration, id: i32, cancel_recurring_subscription_request: Option<crate::models::CancelRecurringSubscriptionRequest>) -> Result<crate::models::SubscriptionsIdResponse200, Error<CancelRecurringSubscriptionError>> {
164 let local_var_configuration = configuration;
165
166 let local_var_client = &local_var_configuration.client;
167
168 let local_var_uri_str = format!("{}/subscriptions/recurring/{id}/cancel", local_var_configuration.base_path, id=id);
169 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
170
171 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
172 let local_var_key = local_var_apikey.key.clone();
173 let local_var_value = match local_var_apikey.prefix {
174 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
175 None => local_var_key,
176 };
177 local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
178 }
179 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
180 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
181 }
182 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
183 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
184 };
185 local_var_req_builder = local_var_req_builder.json(&cancel_recurring_subscription_request);
186
187 let local_var_req = local_var_req_builder.build()?;
188 let local_var_resp = local_var_client.execute(local_var_req).await?;
189
190 let local_var_status = local_var_resp.status();
191 let local_var_content = local_var_resp.text().await?;
192
193 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
194 serde_json::from_str(&local_var_content).map_err(Error::from)
195 } else {
196 let local_var_entity: Option<CancelRecurringSubscriptionError> = serde_json::from_str(&local_var_content).ok();
197 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
198 Err(Error::ResponseError(local_var_error))
199 }
200}
201
202pub async fn delete_subscription(configuration: &configuration::Configuration, id: i32) -> Result<crate::models::SubscriptionsIdResponse200, Error<DeleteSubscriptionError>> {
204 let local_var_configuration = configuration;
205
206 let local_var_client = &local_var_configuration.client;
207
208 let local_var_uri_str = format!("{}/subscriptions/{id}", local_var_configuration.base_path, id=id);
209 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
210
211 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
212 let local_var_key = local_var_apikey.key.clone();
213 let local_var_value = match local_var_apikey.prefix {
214 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
215 None => local_var_key,
216 };
217 local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
218 }
219 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
220 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
221 }
222 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
223 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
224 };
225
226 let local_var_req = local_var_req_builder.build()?;
227 let local_var_resp = local_var_client.execute(local_var_req).await?;
228
229 let local_var_status = local_var_resp.status();
230 let local_var_content = local_var_resp.text().await?;
231
232 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
233 serde_json::from_str(&local_var_content).map_err(Error::from)
234 } else {
235 let local_var_entity: Option<DeleteSubscriptionError> = serde_json::from_str(&local_var_content).ok();
236 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
237 Err(Error::ResponseError(local_var_error))
238 }
239}
240
241pub async fn find_subscription_by_deal(configuration: &configuration::Configuration, deal_id: i32) -> Result<crate::models::SubscriptionsIdResponse200, Error<FindSubscriptionByDealError>> {
243 let local_var_configuration = configuration;
244
245 let local_var_client = &local_var_configuration.client;
246
247 let local_var_uri_str = format!("{}/subscriptions/find/{dealId}", local_var_configuration.base_path, dealId=deal_id);
248 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
249
250 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
251 let local_var_key = local_var_apikey.key.clone();
252 let local_var_value = match local_var_apikey.prefix {
253 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
254 None => local_var_key,
255 };
256 local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
257 }
258 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
259 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
260 }
261 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
262 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
263 };
264
265 let local_var_req = local_var_req_builder.build()?;
266 let local_var_resp = local_var_client.execute(local_var_req).await?;
267
268 let local_var_status = local_var_resp.status();
269 let local_var_content = local_var_resp.text().await?;
270
271 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
272 serde_json::from_str(&local_var_content).map_err(Error::from)
273 } else {
274 let local_var_entity: Option<FindSubscriptionByDealError> = serde_json::from_str(&local_var_content).ok();
275 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
276 Err(Error::ResponseError(local_var_error))
277 }
278}
279
280pub async fn get_subscription(configuration: &configuration::Configuration, id: i32) -> Result<crate::models::SubscriptionsIdResponse200, Error<GetSubscriptionError>> {
282 let local_var_configuration = configuration;
283
284 let local_var_client = &local_var_configuration.client;
285
286 let local_var_uri_str = format!("{}/subscriptions/{id}", local_var_configuration.base_path, id=id);
287 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
288
289 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
290 let local_var_key = local_var_apikey.key.clone();
291 let local_var_value = match local_var_apikey.prefix {
292 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
293 None => local_var_key,
294 };
295 local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
296 }
297 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
298 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
299 }
300 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
301 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
302 };
303
304 let local_var_req = local_var_req_builder.build()?;
305 let local_var_resp = local_var_client.execute(local_var_req).await?;
306
307 let local_var_status = local_var_resp.status();
308 let local_var_content = local_var_resp.text().await?;
309
310 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
311 serde_json::from_str(&local_var_content).map_err(Error::from)
312 } else {
313 let local_var_entity: Option<GetSubscriptionError> = serde_json::from_str(&local_var_content).ok();
314 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
315 Err(Error::ResponseError(local_var_error))
316 }
317}
318
319pub async fn get_subscription_payments(configuration: &configuration::Configuration, id: i32) -> Result<crate::models::PaymentResponse200, Error<GetSubscriptionPaymentsError>> {
321 let local_var_configuration = configuration;
322
323 let local_var_client = &local_var_configuration.client;
324
325 let local_var_uri_str = format!("{}/subscriptions/{id}/payments", local_var_configuration.base_path, id=id);
326 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
327
328 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
329 let local_var_key = local_var_apikey.key.clone();
330 let local_var_value = match local_var_apikey.prefix {
331 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
332 None => local_var_key,
333 };
334 local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
335 }
336 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
337 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
338 }
339 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
340 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
341 };
342
343 let local_var_req = local_var_req_builder.build()?;
344 let local_var_resp = local_var_client.execute(local_var_req).await?;
345
346 let local_var_status = local_var_resp.status();
347 let local_var_content = local_var_resp.text().await?;
348
349 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
350 serde_json::from_str(&local_var_content).map_err(Error::from)
351 } else {
352 let local_var_entity: Option<GetSubscriptionPaymentsError> = serde_json::from_str(&local_var_content).ok();
353 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
354 Err(Error::ResponseError(local_var_error))
355 }
356}
357
358pub async fn update_recurring_subscription(configuration: &configuration::Configuration, id: i32, update_recurring_subscription_request: Option<crate::models::UpdateRecurringSubscriptionRequest>) -> Result<crate::models::SubscriptionsIdResponse200, Error<UpdateRecurringSubscriptionError>> {
360 let local_var_configuration = configuration;
361
362 let local_var_client = &local_var_configuration.client;
363
364 let local_var_uri_str = format!("{}/subscriptions/recurring/{id}", local_var_configuration.base_path, id=id);
365 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
366
367 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
368 let local_var_key = local_var_apikey.key.clone();
369 let local_var_value = match local_var_apikey.prefix {
370 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
371 None => local_var_key,
372 };
373 local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
374 }
375 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
376 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
377 }
378 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
379 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
380 };
381 local_var_req_builder = local_var_req_builder.json(&update_recurring_subscription_request);
382
383 let local_var_req = local_var_req_builder.build()?;
384 let local_var_resp = local_var_client.execute(local_var_req).await?;
385
386 let local_var_status = local_var_resp.status();
387 let local_var_content = local_var_resp.text().await?;
388
389 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
390 serde_json::from_str(&local_var_content).map_err(Error::from)
391 } else {
392 let local_var_entity: Option<UpdateRecurringSubscriptionError> = serde_json::from_str(&local_var_content).ok();
393 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
394 Err(Error::ResponseError(local_var_error))
395 }
396}
397
398pub async fn update_subscription_installment(configuration: &configuration::Configuration, id: i32, update_subscription_installment_request: Option<crate::models::UpdateSubscriptionInstallmentRequest>) -> Result<crate::models::SubscriptionsIdResponse200, Error<UpdateSubscriptionInstallmentError>> {
400 let local_var_configuration = configuration;
401
402 let local_var_client = &local_var_configuration.client;
403
404 let local_var_uri_str = format!("{}/subscriptions/installment/{id}", local_var_configuration.base_path, id=id);
405 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
406
407 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
408 let local_var_key = local_var_apikey.key.clone();
409 let local_var_value = match local_var_apikey.prefix {
410 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
411 None => local_var_key,
412 };
413 local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
414 }
415 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
416 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
417 }
418 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
419 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
420 };
421 local_var_req_builder = local_var_req_builder.json(&update_subscription_installment_request);
422
423 let local_var_req = local_var_req_builder.build()?;
424 let local_var_resp = local_var_client.execute(local_var_req).await?;
425
426 let local_var_status = local_var_resp.status();
427 let local_var_content = local_var_resp.text().await?;
428
429 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
430 serde_json::from_str(&local_var_content).map_err(Error::from)
431 } else {
432 let local_var_entity: Option<UpdateSubscriptionInstallmentError> = serde_json::from_str(&local_var_content).ok();
433 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
434 Err(Error::ResponseError(local_var_error))
435 }
436}
437