stripe_misc/exchange_rate/
requests.rs

1use stripe_client_core::{
2    RequestBuilder, StripeBlockingClient, StripeClient, StripeMethod, StripeRequest,
3};
4
5#[derive(Clone, Debug, serde::Serialize)]
6struct ListExchangeRateBuilder {
7    #[serde(skip_serializing_if = "Option::is_none")]
8    ending_before: Option<String>,
9    #[serde(skip_serializing_if = "Option::is_none")]
10    expand: Option<Vec<String>>,
11    #[serde(skip_serializing_if = "Option::is_none")]
12    limit: Option<i64>,
13    #[serde(skip_serializing_if = "Option::is_none")]
14    starting_after: Option<String>,
15}
16impl ListExchangeRateBuilder {
17    fn new() -> Self {
18        Self { ending_before: None, expand: None, limit: None, starting_after: None }
19    }
20}
21/// Returns a list of objects that contain the rates at which foreign currencies are converted to one another.
22/// Only shows the currencies for which Stripe supports.
23#[derive(Clone, Debug, serde::Serialize)]
24pub struct ListExchangeRate {
25    inner: ListExchangeRateBuilder,
26}
27impl ListExchangeRate {
28    /// Construct a new `ListExchangeRate`.
29    pub fn new() -> Self {
30        Self { inner: ListExchangeRateBuilder::new() }
31    }
32    /// A cursor for use in pagination.
33    /// `ending_before` is the currency that defines your place in the list.
34    /// For instance, if you make a list request and receive 100 objects, starting with the exchange rate for currency X your subsequent call can include `ending_before=obj_bar` in order to fetch the previous page of the list.
35    pub fn ending_before(mut self, ending_before: impl Into<String>) -> Self {
36        self.inner.ending_before = Some(ending_before.into());
37        self
38    }
39    /// Specifies which fields in the response should be expanded.
40    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
41        self.inner.expand = Some(expand.into());
42        self
43    }
44    /// A limit on the number of objects to be returned.
45    /// Limit can range between 1 and total number of supported payout currencies, and the default is the max.
46    pub fn limit(mut self, limit: impl Into<i64>) -> Self {
47        self.inner.limit = Some(limit.into());
48        self
49    }
50    /// A cursor for use in pagination.
51    /// `starting_after` is the currency that defines your place in the list.
52    /// For instance, if you make a list request and receive 100 objects, ending with the exchange rate for currency X, your subsequent call can include `starting_after=X` in order to fetch the next page of the list.
53    pub fn starting_after(mut self, starting_after: impl Into<String>) -> Self {
54        self.inner.starting_after = Some(starting_after.into());
55        self
56    }
57}
58impl Default for ListExchangeRate {
59    fn default() -> Self {
60        Self::new()
61    }
62}
63impl ListExchangeRate {
64    /// Send the request and return the deserialized response.
65    pub async fn send<C: StripeClient>(
66        &self,
67        client: &C,
68    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
69        self.customize().send(client).await
70    }
71
72    /// Send the request and return the deserialized response, blocking until completion.
73    pub fn send_blocking<C: StripeBlockingClient>(
74        &self,
75        client: &C,
76    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
77        self.customize().send_blocking(client)
78    }
79
80    pub fn paginate(
81        &self,
82    ) -> stripe_client_core::ListPaginator<stripe_types::List<stripe_misc::ExchangeRate>> {
83        stripe_client_core::ListPaginator::new_list("/exchange_rates", &self.inner)
84    }
85}
86
87impl StripeRequest for ListExchangeRate {
88    type Output = stripe_types::List<stripe_misc::ExchangeRate>;
89
90    fn build(&self) -> RequestBuilder {
91        RequestBuilder::new(StripeMethod::Get, "/exchange_rates").query(&self.inner)
92    }
93}
94#[derive(Clone, Debug, serde::Serialize)]
95struct RetrieveExchangeRateBuilder {
96    #[serde(skip_serializing_if = "Option::is_none")]
97    expand: Option<Vec<String>>,
98}
99impl RetrieveExchangeRateBuilder {
100    fn new() -> Self {
101        Self { expand: None }
102    }
103}
104/// Retrieves the exchange rates from the given currency to every supported currency.
105#[derive(Clone, Debug, serde::Serialize)]
106pub struct RetrieveExchangeRate {
107    inner: RetrieveExchangeRateBuilder,
108    rate_id: stripe_misc::ExchangeRateId,
109}
110impl RetrieveExchangeRate {
111    /// Construct a new `RetrieveExchangeRate`.
112    pub fn new(rate_id: impl Into<stripe_misc::ExchangeRateId>) -> Self {
113        Self { rate_id: rate_id.into(), inner: RetrieveExchangeRateBuilder::new() }
114    }
115    /// Specifies which fields in the response should be expanded.
116    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
117        self.inner.expand = Some(expand.into());
118        self
119    }
120}
121impl RetrieveExchangeRate {
122    /// Send the request and return the deserialized response.
123    pub async fn send<C: StripeClient>(
124        &self,
125        client: &C,
126    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
127        self.customize().send(client).await
128    }
129
130    /// Send the request and return the deserialized response, blocking until completion.
131    pub fn send_blocking<C: StripeBlockingClient>(
132        &self,
133        client: &C,
134    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
135        self.customize().send_blocking(client)
136    }
137}
138
139impl StripeRequest for RetrieveExchangeRate {
140    type Output = stripe_misc::ExchangeRate;
141
142    fn build(&self) -> RequestBuilder {
143        let rate_id = &self.rate_id;
144        RequestBuilder::new(StripeMethod::Get, format!("/exchange_rates/{rate_id}"))
145            .query(&self.inner)
146    }
147}