Skip to main content

stripe_issuing/issuing_token/
requests.rs

1use stripe_client_core::{
2    RequestBuilder, StripeBlockingClient, StripeClient, StripeMethod, StripeRequest,
3};
4
5#[derive(Clone, Eq, PartialEq)]
6#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
7#[derive(serde::Serialize)]
8struct ListIssuingTokenBuilder {
9    card: String,
10    #[serde(skip_serializing_if = "Option::is_none")]
11    created: Option<stripe_types::RangeQueryTs>,
12    #[serde(skip_serializing_if = "Option::is_none")]
13    ending_before: Option<String>,
14    #[serde(skip_serializing_if = "Option::is_none")]
15    expand: Option<Vec<String>>,
16    #[serde(skip_serializing_if = "Option::is_none")]
17    limit: Option<i64>,
18    #[serde(skip_serializing_if = "Option::is_none")]
19    starting_after: Option<String>,
20    #[serde(skip_serializing_if = "Option::is_none")]
21    status: Option<stripe_shared::IssuingTokenStatus>,
22}
23#[cfg(feature = "redact-generated-debug")]
24impl std::fmt::Debug for ListIssuingTokenBuilder {
25    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
26        f.debug_struct("ListIssuingTokenBuilder").finish_non_exhaustive()
27    }
28}
29impl ListIssuingTokenBuilder {
30    fn new(card: impl Into<String>) -> Self {
31        Self {
32            card: card.into(),
33            created: None,
34            ending_before: None,
35            expand: None,
36            limit: None,
37            starting_after: None,
38            status: None,
39        }
40    }
41}
42/// Lists all Issuing `Token` objects for a given card.
43#[derive(Clone)]
44#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
45#[derive(serde::Serialize)]
46pub struct ListIssuingToken {
47    inner: ListIssuingTokenBuilder,
48}
49#[cfg(feature = "redact-generated-debug")]
50impl std::fmt::Debug for ListIssuingToken {
51    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
52        f.debug_struct("ListIssuingToken").finish_non_exhaustive()
53    }
54}
55impl ListIssuingToken {
56    /// Construct a new `ListIssuingToken`.
57    pub fn new(card: impl Into<String>) -> Self {
58        Self { inner: ListIssuingTokenBuilder::new(card.into()) }
59    }
60    /// Only return Issuing tokens that were created during the given date interval.
61    pub fn created(mut self, created: impl Into<stripe_types::RangeQueryTs>) -> Self {
62        self.inner.created = Some(created.into());
63        self
64    }
65    /// A cursor for use in pagination.
66    /// `ending_before` is an object ID that defines your place in the list.
67    /// For instance, if you make a list request and receive 100 objects, starting with `obj_bar`, your subsequent call can include `ending_before=obj_bar` in order to fetch the previous page of the list.
68    pub fn ending_before(mut self, ending_before: impl Into<String>) -> Self {
69        self.inner.ending_before = Some(ending_before.into());
70        self
71    }
72    /// Specifies which fields in the response should be expanded.
73    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
74        self.inner.expand = Some(expand.into());
75        self
76    }
77    /// A limit on the number of objects to be returned.
78    /// Limit can range between 1 and 100, and the default is 10.
79    pub fn limit(mut self, limit: impl Into<i64>) -> Self {
80        self.inner.limit = Some(limit.into());
81        self
82    }
83    /// A cursor for use in pagination.
84    /// `starting_after` is an object ID that defines your place in the list.
85    /// For instance, if you make a list request and receive 100 objects, ending with `obj_foo`, your subsequent call can include `starting_after=obj_foo` in order to fetch the next page of the list.
86    pub fn starting_after(mut self, starting_after: impl Into<String>) -> Self {
87        self.inner.starting_after = Some(starting_after.into());
88        self
89    }
90    /// Select Issuing tokens with the given status.
91    pub fn status(mut self, status: impl Into<stripe_shared::IssuingTokenStatus>) -> Self {
92        self.inner.status = Some(status.into());
93        self
94    }
95}
96impl ListIssuingToken {
97    /// Send the request and return the deserialized response.
98    pub async fn send<C: StripeClient>(
99        &self,
100        client: &C,
101    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
102        self.customize().send(client).await
103    }
104
105    /// Send the request and return the deserialized response, blocking until completion.
106    pub fn send_blocking<C: StripeBlockingClient>(
107        &self,
108        client: &C,
109    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
110        self.customize().send_blocking(client)
111    }
112
113    pub fn paginate(
114        &self,
115    ) -> stripe_client_core::ListPaginator<stripe_types::List<stripe_shared::IssuingToken>> {
116        stripe_client_core::ListPaginator::new_list("/issuing/tokens", &self.inner)
117    }
118}
119
120impl StripeRequest for ListIssuingToken {
121    type Output = stripe_types::List<stripe_shared::IssuingToken>;
122
123    fn build(&self) -> RequestBuilder {
124        RequestBuilder::new(StripeMethod::Get, "/issuing/tokens").query(&self.inner)
125    }
126}
127#[derive(Clone, Eq, PartialEq)]
128#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
129#[derive(serde::Serialize)]
130struct RetrieveIssuingTokenBuilder {
131    #[serde(skip_serializing_if = "Option::is_none")]
132    expand: Option<Vec<String>>,
133}
134#[cfg(feature = "redact-generated-debug")]
135impl std::fmt::Debug for RetrieveIssuingTokenBuilder {
136    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
137        f.debug_struct("RetrieveIssuingTokenBuilder").finish_non_exhaustive()
138    }
139}
140impl RetrieveIssuingTokenBuilder {
141    fn new() -> Self {
142        Self { expand: None }
143    }
144}
145/// Retrieves an Issuing `Token` object.
146#[derive(Clone)]
147#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
148#[derive(serde::Serialize)]
149pub struct RetrieveIssuingToken {
150    inner: RetrieveIssuingTokenBuilder,
151    token: stripe_shared::IssuingTokenId,
152}
153#[cfg(feature = "redact-generated-debug")]
154impl std::fmt::Debug for RetrieveIssuingToken {
155    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
156        f.debug_struct("RetrieveIssuingToken").finish_non_exhaustive()
157    }
158}
159impl RetrieveIssuingToken {
160    /// Construct a new `RetrieveIssuingToken`.
161    pub fn new(token: impl Into<stripe_shared::IssuingTokenId>) -> Self {
162        Self { token: token.into(), inner: RetrieveIssuingTokenBuilder::new() }
163    }
164    /// Specifies which fields in the response should be expanded.
165    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
166        self.inner.expand = Some(expand.into());
167        self
168    }
169}
170impl RetrieveIssuingToken {
171    /// Send the request and return the deserialized response.
172    pub async fn send<C: StripeClient>(
173        &self,
174        client: &C,
175    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
176        self.customize().send(client).await
177    }
178
179    /// Send the request and return the deserialized response, blocking until completion.
180    pub fn send_blocking<C: StripeBlockingClient>(
181        &self,
182        client: &C,
183    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
184        self.customize().send_blocking(client)
185    }
186}
187
188impl StripeRequest for RetrieveIssuingToken {
189    type Output = stripe_shared::IssuingToken;
190
191    fn build(&self) -> RequestBuilder {
192        let token = &self.token;
193        RequestBuilder::new(StripeMethod::Get, format!("/issuing/tokens/{token}"))
194            .query(&self.inner)
195    }
196}
197#[derive(Clone, Eq, PartialEq)]
198#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
199#[derive(serde::Serialize)]
200struct UpdateIssuingTokenBuilder {
201    #[serde(skip_serializing_if = "Option::is_none")]
202    expand: Option<Vec<String>>,
203    status: UpdateIssuingTokenStatus,
204}
205#[cfg(feature = "redact-generated-debug")]
206impl std::fmt::Debug for UpdateIssuingTokenBuilder {
207    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
208        f.debug_struct("UpdateIssuingTokenBuilder").finish_non_exhaustive()
209    }
210}
211impl UpdateIssuingTokenBuilder {
212    fn new(status: impl Into<UpdateIssuingTokenStatus>) -> Self {
213        Self { expand: None, status: status.into() }
214    }
215}
216/// Specifies which status the token should be updated to.
217#[derive(Clone, Eq, PartialEq)]
218#[non_exhaustive]
219pub enum UpdateIssuingTokenStatus {
220    Active,
221    Deleted,
222    Suspended,
223    /// An unrecognized value from Stripe. Should not be used as a request parameter.
224    Unknown(String),
225}
226impl UpdateIssuingTokenStatus {
227    pub fn as_str(&self) -> &str {
228        use UpdateIssuingTokenStatus::*;
229        match self {
230            Active => "active",
231            Deleted => "deleted",
232            Suspended => "suspended",
233            Unknown(v) => v,
234        }
235    }
236}
237
238impl std::str::FromStr for UpdateIssuingTokenStatus {
239    type Err = std::convert::Infallible;
240    fn from_str(s: &str) -> Result<Self, Self::Err> {
241        use UpdateIssuingTokenStatus::*;
242        match s {
243            "active" => Ok(Active),
244            "deleted" => Ok(Deleted),
245            "suspended" => Ok(Suspended),
246            v => {
247                tracing::warn!("Unknown value '{}' for enum '{}'", v, "UpdateIssuingTokenStatus");
248                Ok(Unknown(v.to_owned()))
249            }
250        }
251    }
252}
253impl std::fmt::Display for UpdateIssuingTokenStatus {
254    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
255        f.write_str(self.as_str())
256    }
257}
258
259#[cfg(not(feature = "redact-generated-debug"))]
260impl std::fmt::Debug for UpdateIssuingTokenStatus {
261    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
262        f.write_str(self.as_str())
263    }
264}
265#[cfg(feature = "redact-generated-debug")]
266impl std::fmt::Debug for UpdateIssuingTokenStatus {
267    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
268        f.debug_struct(stringify!(UpdateIssuingTokenStatus)).finish_non_exhaustive()
269    }
270}
271impl serde::Serialize for UpdateIssuingTokenStatus {
272    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
273    where
274        S: serde::Serializer,
275    {
276        serializer.serialize_str(self.as_str())
277    }
278}
279#[cfg(feature = "deserialize")]
280impl<'de> serde::Deserialize<'de> for UpdateIssuingTokenStatus {
281    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
282        use std::str::FromStr;
283        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
284        Ok(Self::from_str(&s).expect("infallible"))
285    }
286}
287/// Attempts to update the specified Issuing `Token` object to the status specified.
288#[derive(Clone)]
289#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
290#[derive(serde::Serialize)]
291pub struct UpdateIssuingToken {
292    inner: UpdateIssuingTokenBuilder,
293    token: stripe_shared::IssuingTokenId,
294}
295#[cfg(feature = "redact-generated-debug")]
296impl std::fmt::Debug for UpdateIssuingToken {
297    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
298        f.debug_struct("UpdateIssuingToken").finish_non_exhaustive()
299    }
300}
301impl UpdateIssuingToken {
302    /// Construct a new `UpdateIssuingToken`.
303    pub fn new(
304        token: impl Into<stripe_shared::IssuingTokenId>,
305        status: impl Into<UpdateIssuingTokenStatus>,
306    ) -> Self {
307        Self { token: token.into(), inner: UpdateIssuingTokenBuilder::new(status.into()) }
308    }
309    /// Specifies which fields in the response should be expanded.
310    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
311        self.inner.expand = Some(expand.into());
312        self
313    }
314}
315impl UpdateIssuingToken {
316    /// Send the request and return the deserialized response.
317    pub async fn send<C: StripeClient>(
318        &self,
319        client: &C,
320    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
321        self.customize().send(client).await
322    }
323
324    /// Send the request and return the deserialized response, blocking until completion.
325    pub fn send_blocking<C: StripeBlockingClient>(
326        &self,
327        client: &C,
328    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
329        self.customize().send_blocking(client)
330    }
331}
332
333impl StripeRequest for UpdateIssuingToken {
334    type Output = stripe_shared::IssuingToken;
335
336    fn build(&self) -> RequestBuilder {
337        let token = &self.token;
338        RequestBuilder::new(StripeMethod::Post, format!("/issuing/tokens/{token}"))
339            .form(&self.inner)
340    }
341}