Skip to main content

stripe_connect/capability/
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 ListAccountCapabilityBuilder {
9    #[serde(skip_serializing_if = "Option::is_none")]
10    expand: Option<Vec<String>>,
11}
12#[cfg(feature = "redact-generated-debug")]
13impl std::fmt::Debug for ListAccountCapabilityBuilder {
14    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
15        f.debug_struct("ListAccountCapabilityBuilder").finish_non_exhaustive()
16    }
17}
18impl ListAccountCapabilityBuilder {
19    fn new() -> Self {
20        Self { expand: None }
21    }
22}
23/// Returns a list of capabilities associated with the account.
24/// The capabilities are returned sorted by creation date, with the most recent capability appearing first.
25#[derive(Clone)]
26#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
27#[derive(serde::Serialize)]
28pub struct ListAccountCapability {
29    inner: ListAccountCapabilityBuilder,
30    account: stripe_shared::AccountId,
31}
32#[cfg(feature = "redact-generated-debug")]
33impl std::fmt::Debug for ListAccountCapability {
34    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
35        f.debug_struct("ListAccountCapability").finish_non_exhaustive()
36    }
37}
38impl ListAccountCapability {
39    /// Construct a new `ListAccountCapability`.
40    pub fn new(account: impl Into<stripe_shared::AccountId>) -> Self {
41        Self { account: account.into(), inner: ListAccountCapabilityBuilder::new() }
42    }
43    /// Specifies which fields in the response should be expanded.
44    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
45        self.inner.expand = Some(expand.into());
46        self
47    }
48}
49impl ListAccountCapability {
50    /// Send the request and return the deserialized response.
51    pub async fn send<C: StripeClient>(
52        &self,
53        client: &C,
54    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
55        self.customize().send(client).await
56    }
57
58    /// Send the request and return the deserialized response, blocking until completion.
59    pub fn send_blocking<C: StripeBlockingClient>(
60        &self,
61        client: &C,
62    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
63        self.customize().send_blocking(client)
64    }
65
66    pub fn paginate(
67        &self,
68    ) -> stripe_client_core::ListPaginator<stripe_types::List<stripe_shared::Capability>> {
69        let account = &self.account;
70
71        stripe_client_core::ListPaginator::new_list(
72            format!("/accounts/{account}/capabilities"),
73            &self.inner,
74        )
75    }
76}
77
78impl StripeRequest for ListAccountCapability {
79    type Output = stripe_types::List<stripe_shared::Capability>;
80
81    fn build(&self) -> RequestBuilder {
82        let account = &self.account;
83        RequestBuilder::new(StripeMethod::Get, format!("/accounts/{account}/capabilities"))
84            .query(&self.inner)
85    }
86}
87#[derive(Clone, Eq, PartialEq)]
88#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
89#[derive(serde::Serialize)]
90struct RetrieveCapabilityBuilder {
91    #[serde(skip_serializing_if = "Option::is_none")]
92    expand: Option<Vec<String>>,
93}
94#[cfg(feature = "redact-generated-debug")]
95impl std::fmt::Debug for RetrieveCapabilityBuilder {
96    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
97        f.debug_struct("RetrieveCapabilityBuilder").finish_non_exhaustive()
98    }
99}
100impl RetrieveCapabilityBuilder {
101    fn new() -> Self {
102        Self { expand: None }
103    }
104}
105/// Retrieves information about the specified Account Capability.
106#[derive(Clone)]
107#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
108#[derive(serde::Serialize)]
109pub struct RetrieveCapability {
110    inner: RetrieveCapabilityBuilder,
111    account: stripe_shared::AccountId,
112    capability: String,
113}
114#[cfg(feature = "redact-generated-debug")]
115impl std::fmt::Debug for RetrieveCapability {
116    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
117        f.debug_struct("RetrieveCapability").finish_non_exhaustive()
118    }
119}
120impl RetrieveCapability {
121    /// Construct a new `RetrieveCapability`.
122    pub fn new(
123        account: impl Into<stripe_shared::AccountId>,
124        capability: impl Into<String>,
125    ) -> Self {
126        Self {
127            account: account.into(),
128            capability: capability.into(),
129            inner: RetrieveCapabilityBuilder::new(),
130        }
131    }
132    /// Specifies which fields in the response should be expanded.
133    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
134        self.inner.expand = Some(expand.into());
135        self
136    }
137}
138impl RetrieveCapability {
139    /// Send the request and return the deserialized response.
140    pub async fn send<C: StripeClient>(
141        &self,
142        client: &C,
143    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
144        self.customize().send(client).await
145    }
146
147    /// Send the request and return the deserialized response, blocking until completion.
148    pub fn send_blocking<C: StripeBlockingClient>(
149        &self,
150        client: &C,
151    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
152        self.customize().send_blocking(client)
153    }
154}
155
156impl StripeRequest for RetrieveCapability {
157    type Output = stripe_shared::Capability;
158
159    fn build(&self) -> RequestBuilder {
160        let account = &self.account;
161        let capability = &self.capability;
162        RequestBuilder::new(
163            StripeMethod::Get,
164            format!("/accounts/{account}/capabilities/{capability}"),
165        )
166        .query(&self.inner)
167    }
168}
169#[derive(Clone, Eq, PartialEq)]
170#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
171#[derive(serde::Serialize)]
172struct UpdateCapabilityBuilder {
173    #[serde(skip_serializing_if = "Option::is_none")]
174    expand: Option<Vec<String>>,
175    #[serde(skip_serializing_if = "Option::is_none")]
176    requested: Option<bool>,
177}
178#[cfg(feature = "redact-generated-debug")]
179impl std::fmt::Debug for UpdateCapabilityBuilder {
180    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
181        f.debug_struct("UpdateCapabilityBuilder").finish_non_exhaustive()
182    }
183}
184impl UpdateCapabilityBuilder {
185    fn new() -> Self {
186        Self { expand: None, requested: None }
187    }
188}
189/// Updates an existing Account Capability.
190/// Request or remove a capability by updating its `requested` parameter.
191#[derive(Clone)]
192#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
193#[derive(serde::Serialize)]
194pub struct UpdateCapability {
195    inner: UpdateCapabilityBuilder,
196    account: stripe_shared::AccountId,
197    capability: String,
198}
199#[cfg(feature = "redact-generated-debug")]
200impl std::fmt::Debug for UpdateCapability {
201    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
202        f.debug_struct("UpdateCapability").finish_non_exhaustive()
203    }
204}
205impl UpdateCapability {
206    /// Construct a new `UpdateCapability`.
207    pub fn new(
208        account: impl Into<stripe_shared::AccountId>,
209        capability: impl Into<String>,
210    ) -> Self {
211        Self {
212            account: account.into(),
213            capability: capability.into(),
214            inner: UpdateCapabilityBuilder::new(),
215        }
216    }
217    /// Specifies which fields in the response should be expanded.
218    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
219        self.inner.expand = Some(expand.into());
220        self
221    }
222    /// To request a new capability for an account, pass true.
223    /// There can be a delay before the requested capability becomes active.
224    /// If the capability has any activation requirements, the response includes them in the `requirements` arrays.
225    ///
226    /// If a capability isn't permanent, you can remove it from the account by passing false.
227    /// Some capabilities are permanent after they've been requested.
228    /// Attempting to remove a permanent capability returns an error.
229    pub fn requested(mut self, requested: impl Into<bool>) -> Self {
230        self.inner.requested = Some(requested.into());
231        self
232    }
233}
234impl UpdateCapability {
235    /// Send the request and return the deserialized response.
236    pub async fn send<C: StripeClient>(
237        &self,
238        client: &C,
239    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
240        self.customize().send(client).await
241    }
242
243    /// Send the request and return the deserialized response, blocking until completion.
244    pub fn send_blocking<C: StripeBlockingClient>(
245        &self,
246        client: &C,
247    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
248        self.customize().send_blocking(client)
249    }
250}
251
252impl StripeRequest for UpdateCapability {
253    type Output = stripe_shared::Capability;
254
255    fn build(&self) -> RequestBuilder {
256        let account = &self.account;
257        let capability = &self.capability;
258        RequestBuilder::new(
259            StripeMethod::Post,
260            format!("/accounts/{account}/capabilities/{capability}"),
261        )
262        .form(&self.inner)
263    }
264}