stripe_core/balance_settings/
requests.rs

1use stripe_client_core::{
2    RequestBuilder, StripeBlockingClient, StripeClient, StripeMethod, StripeRequest,
3};
4
5#[derive(Clone, Debug, serde::Serialize)]
6struct RetrieveForMyAccountBalanceSettingsBuilder {
7    #[serde(skip_serializing_if = "Option::is_none")]
8    expand: Option<Vec<String>>,
9}
10impl RetrieveForMyAccountBalanceSettingsBuilder {
11    fn new() -> Self {
12        Self { expand: None }
13    }
14}
15/// Retrieves balance settings for a given connected account.
16///  Related guide: <a href="/connect/authentication">Making API calls for connected accounts</a>
17#[derive(Clone, Debug, serde::Serialize)]
18pub struct RetrieveForMyAccountBalanceSettings {
19    inner: RetrieveForMyAccountBalanceSettingsBuilder,
20}
21impl RetrieveForMyAccountBalanceSettings {
22    /// Construct a new `RetrieveForMyAccountBalanceSettings`.
23    pub fn new() -> Self {
24        Self { inner: RetrieveForMyAccountBalanceSettingsBuilder::new() }
25    }
26    /// Specifies which fields in the response should be expanded.
27    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
28        self.inner.expand = Some(expand.into());
29        self
30    }
31}
32impl Default for RetrieveForMyAccountBalanceSettings {
33    fn default() -> Self {
34        Self::new()
35    }
36}
37impl RetrieveForMyAccountBalanceSettings {
38    /// Send the request and return the deserialized response.
39    pub async fn send<C: StripeClient>(
40        &self,
41        client: &C,
42    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
43        self.customize().send(client).await
44    }
45
46    /// Send the request and return the deserialized response, blocking until completion.
47    pub fn send_blocking<C: StripeBlockingClient>(
48        &self,
49        client: &C,
50    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
51        self.customize().send_blocking(client)
52    }
53}
54
55impl StripeRequest for RetrieveForMyAccountBalanceSettings {
56    type Output = stripe_core::BalanceSettings;
57
58    fn build(&self) -> RequestBuilder {
59        RequestBuilder::new(StripeMethod::Get, "/balance_settings").query(&self.inner)
60    }
61}
62#[derive(Clone, Debug, serde::Serialize)]
63struct UpdateBalanceSettingsBuilder {
64    #[serde(skip_serializing_if = "Option::is_none")]
65    expand: Option<Vec<String>>,
66    #[serde(skip_serializing_if = "Option::is_none")]
67    payments: Option<UpdateBalanceSettingsPayments>,
68}
69impl UpdateBalanceSettingsBuilder {
70    fn new() -> Self {
71        Self { expand: None, payments: None }
72    }
73}
74/// Settings that apply to the [Payments Balance](https://docs.stripe.com/api/balance).
75#[derive(Clone, Debug, serde::Serialize)]
76pub struct UpdateBalanceSettingsPayments {
77    /// A Boolean indicating whether Stripe should try to reclaim negative balances from an attached bank account.
78    /// For details, see [Understanding Connect Account Balances](/connect/account-balances).
79    #[serde(skip_serializing_if = "Option::is_none")]
80    pub debit_negative_balances: Option<bool>,
81    /// Settings specific to the account's payouts.
82    #[serde(skip_serializing_if = "Option::is_none")]
83    pub payouts: Option<UpdateBalanceSettingsPaymentsPayouts>,
84    /// Settings related to the account's balance settlement timing.
85    #[serde(skip_serializing_if = "Option::is_none")]
86    pub settlement_timing: Option<UpdateBalanceSettingsPaymentsSettlementTiming>,
87}
88impl UpdateBalanceSettingsPayments {
89    pub fn new() -> Self {
90        Self { debit_negative_balances: None, payouts: None, settlement_timing: None }
91    }
92}
93impl Default for UpdateBalanceSettingsPayments {
94    fn default() -> Self {
95        Self::new()
96    }
97}
98/// Settings specific to the account's payouts.
99#[derive(Clone, Debug, serde::Serialize)]
100pub struct UpdateBalanceSettingsPaymentsPayouts {
101    /// The minimum balance amount to retain per currency after automatic payouts.
102    /// Only funds that exceed these amounts are paid out.
103    /// Learn more about the [minimum balances for automatic payouts](/payouts/minimum-balances-for-automatic-payouts).
104    #[serde(skip_serializing_if = "Option::is_none")]
105    pub minimum_balance_by_currency: Option<std::collections::HashMap<String, i64>>,
106    /// Details on when funds from charges are available, and when they are paid out to an external account.
107    /// For details, see our [Setting Bank and Debit Card Payouts](/connect/bank-transfers#payout-information) documentation.
108    #[serde(skip_serializing_if = "Option::is_none")]
109    pub schedule: Option<UpdateBalanceSettingsPaymentsPayoutsSchedule>,
110    /// The text that appears on the bank account statement for payouts.
111    /// If not set, this defaults to the platform's bank descriptor as set in the Dashboard.
112    #[serde(skip_serializing_if = "Option::is_none")]
113    pub statement_descriptor: Option<String>,
114}
115impl UpdateBalanceSettingsPaymentsPayouts {
116    pub fn new() -> Self {
117        Self { minimum_balance_by_currency: None, schedule: None, statement_descriptor: None }
118    }
119}
120impl Default for UpdateBalanceSettingsPaymentsPayouts {
121    fn default() -> Self {
122        Self::new()
123    }
124}
125/// Details on when funds from charges are available, and when they are paid out to an external account.
126/// For details, see our [Setting Bank and Debit Card Payouts](/connect/bank-transfers#payout-information) documentation.
127#[derive(Clone, Debug, serde::Serialize)]
128pub struct UpdateBalanceSettingsPaymentsPayoutsSchedule {
129    /// How frequently available funds are paid out.
130    /// One of: `daily`, `manual`, `weekly`, or `monthly`.
131    /// Default is `daily`.
132    #[serde(skip_serializing_if = "Option::is_none")]
133    pub interval: Option<UpdateBalanceSettingsPaymentsPayoutsScheduleInterval>,
134    /// The days of the month when available funds are paid out, specified as an array of numbers between 1--31.
135    /// Payouts nominally scheduled between the 29th and 31st of the month are instead sent on the last day of a shorter month.
136    /// Required and applicable only if `interval` is `monthly`.
137    #[serde(skip_serializing_if = "Option::is_none")]
138    pub monthly_payout_days: Option<Vec<u32>>,
139    /// The days of the week when available funds are paid out, specified as an array, e.g., [`monday`, `tuesday`].
140    /// Required and applicable only if `interval` is `weekly`.
141    #[serde(skip_serializing_if = "Option::is_none")]
142    pub weekly_payout_days:
143        Option<Vec<UpdateBalanceSettingsPaymentsPayoutsScheduleWeeklyPayoutDays>>,
144}
145impl UpdateBalanceSettingsPaymentsPayoutsSchedule {
146    pub fn new() -> Self {
147        Self { interval: None, monthly_payout_days: None, weekly_payout_days: None }
148    }
149}
150impl Default for UpdateBalanceSettingsPaymentsPayoutsSchedule {
151    fn default() -> Self {
152        Self::new()
153    }
154}
155/// How frequently available funds are paid out.
156/// One of: `daily`, `manual`, `weekly`, or `monthly`.
157/// Default is `daily`.
158#[derive(Copy, Clone, Eq, PartialEq)]
159pub enum UpdateBalanceSettingsPaymentsPayoutsScheduleInterval {
160    Daily,
161    Manual,
162    Monthly,
163    Weekly,
164}
165impl UpdateBalanceSettingsPaymentsPayoutsScheduleInterval {
166    pub fn as_str(self) -> &'static str {
167        use UpdateBalanceSettingsPaymentsPayoutsScheduleInterval::*;
168        match self {
169            Daily => "daily",
170            Manual => "manual",
171            Monthly => "monthly",
172            Weekly => "weekly",
173        }
174    }
175}
176
177impl std::str::FromStr for UpdateBalanceSettingsPaymentsPayoutsScheduleInterval {
178    type Err = stripe_types::StripeParseError;
179    fn from_str(s: &str) -> Result<Self, Self::Err> {
180        use UpdateBalanceSettingsPaymentsPayoutsScheduleInterval::*;
181        match s {
182            "daily" => Ok(Daily),
183            "manual" => Ok(Manual),
184            "monthly" => Ok(Monthly),
185            "weekly" => Ok(Weekly),
186            _ => Err(stripe_types::StripeParseError),
187        }
188    }
189}
190impl std::fmt::Display for UpdateBalanceSettingsPaymentsPayoutsScheduleInterval {
191    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
192        f.write_str(self.as_str())
193    }
194}
195
196impl std::fmt::Debug for UpdateBalanceSettingsPaymentsPayoutsScheduleInterval {
197    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
198        f.write_str(self.as_str())
199    }
200}
201impl serde::Serialize for UpdateBalanceSettingsPaymentsPayoutsScheduleInterval {
202    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
203    where
204        S: serde::Serializer,
205    {
206        serializer.serialize_str(self.as_str())
207    }
208}
209#[cfg(feature = "deserialize")]
210impl<'de> serde::Deserialize<'de> for UpdateBalanceSettingsPaymentsPayoutsScheduleInterval {
211    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
212        use std::str::FromStr;
213        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
214        Self::from_str(&s).map_err(|_| {
215            serde::de::Error::custom(
216                "Unknown value for UpdateBalanceSettingsPaymentsPayoutsScheduleInterval",
217            )
218        })
219    }
220}
221/// The days of the week when available funds are paid out, specified as an array, e.g., [`monday`, `tuesday`].
222/// Required and applicable only if `interval` is `weekly`.
223#[derive(Copy, Clone, Eq, PartialEq)]
224pub enum UpdateBalanceSettingsPaymentsPayoutsScheduleWeeklyPayoutDays {
225    Friday,
226    Monday,
227    Thursday,
228    Tuesday,
229    Wednesday,
230}
231impl UpdateBalanceSettingsPaymentsPayoutsScheduleWeeklyPayoutDays {
232    pub fn as_str(self) -> &'static str {
233        use UpdateBalanceSettingsPaymentsPayoutsScheduleWeeklyPayoutDays::*;
234        match self {
235            Friday => "friday",
236            Monday => "monday",
237            Thursday => "thursday",
238            Tuesday => "tuesday",
239            Wednesday => "wednesday",
240        }
241    }
242}
243
244impl std::str::FromStr for UpdateBalanceSettingsPaymentsPayoutsScheduleWeeklyPayoutDays {
245    type Err = stripe_types::StripeParseError;
246    fn from_str(s: &str) -> Result<Self, Self::Err> {
247        use UpdateBalanceSettingsPaymentsPayoutsScheduleWeeklyPayoutDays::*;
248        match s {
249            "friday" => Ok(Friday),
250            "monday" => Ok(Monday),
251            "thursday" => Ok(Thursday),
252            "tuesday" => Ok(Tuesday),
253            "wednesday" => Ok(Wednesday),
254            _ => Err(stripe_types::StripeParseError),
255        }
256    }
257}
258impl std::fmt::Display for UpdateBalanceSettingsPaymentsPayoutsScheduleWeeklyPayoutDays {
259    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
260        f.write_str(self.as_str())
261    }
262}
263
264impl std::fmt::Debug for UpdateBalanceSettingsPaymentsPayoutsScheduleWeeklyPayoutDays {
265    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
266        f.write_str(self.as_str())
267    }
268}
269impl serde::Serialize for UpdateBalanceSettingsPaymentsPayoutsScheduleWeeklyPayoutDays {
270    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
271    where
272        S: serde::Serializer,
273    {
274        serializer.serialize_str(self.as_str())
275    }
276}
277#[cfg(feature = "deserialize")]
278impl<'de> serde::Deserialize<'de> for UpdateBalanceSettingsPaymentsPayoutsScheduleWeeklyPayoutDays {
279    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
280        use std::str::FromStr;
281        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
282        Self::from_str(&s).map_err(|_| {
283            serde::de::Error::custom(
284                "Unknown value for UpdateBalanceSettingsPaymentsPayoutsScheduleWeeklyPayoutDays",
285            )
286        })
287    }
288}
289/// Settings related to the account's balance settlement timing.
290#[derive(Copy, Clone, Debug, serde::Serialize)]
291pub struct UpdateBalanceSettingsPaymentsSettlementTiming {
292    /// Change `delay_days` for this account, which determines the number of days charge funds are held before becoming available.
293    /// The maximum value is 31.
294    /// Passing an empty string to `delay_days_override` will return `delay_days` to the default, which is the lowest available value for the account.
295    /// [Learn more about controlling delay days](/connect/manage-payout-schedule).
296    #[serde(skip_serializing_if = "Option::is_none")]
297    pub delay_days_override: Option<u32>,
298}
299impl UpdateBalanceSettingsPaymentsSettlementTiming {
300    pub fn new() -> Self {
301        Self { delay_days_override: None }
302    }
303}
304impl Default for UpdateBalanceSettingsPaymentsSettlementTiming {
305    fn default() -> Self {
306        Self::new()
307    }
308}
309/// Updates balance settings for a given connected account.
310///  Related guide: <a href="/connect/authentication">Making API calls for connected accounts</a>
311#[derive(Clone, Debug, serde::Serialize)]
312pub struct UpdateBalanceSettings {
313    inner: UpdateBalanceSettingsBuilder,
314}
315impl UpdateBalanceSettings {
316    /// Construct a new `UpdateBalanceSettings`.
317    pub fn new() -> Self {
318        Self { inner: UpdateBalanceSettingsBuilder::new() }
319    }
320    /// Specifies which fields in the response should be expanded.
321    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
322        self.inner.expand = Some(expand.into());
323        self
324    }
325    /// Settings that apply to the [Payments Balance](https://docs.stripe.com/api/balance).
326    pub fn payments(mut self, payments: impl Into<UpdateBalanceSettingsPayments>) -> Self {
327        self.inner.payments = Some(payments.into());
328        self
329    }
330}
331impl Default for UpdateBalanceSettings {
332    fn default() -> Self {
333        Self::new()
334    }
335}
336impl UpdateBalanceSettings {
337    /// Send the request and return the deserialized response.
338    pub async fn send<C: StripeClient>(
339        &self,
340        client: &C,
341    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
342        self.customize().send(client).await
343    }
344
345    /// Send the request and return the deserialized response, blocking until completion.
346    pub fn send_blocking<C: StripeBlockingClient>(
347        &self,
348        client: &C,
349    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
350        self.customize().send_blocking(client)
351    }
352}
353
354impl StripeRequest for UpdateBalanceSettings {
355    type Output = stripe_core::BalanceSettings;
356
357    fn build(&self) -> RequestBuilder {
358        RequestBuilder::new(StripeMethod::Post, "/balance_settings").form(&self.inner)
359    }
360}