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