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(Clone, Eq, PartialEq)]
159#[non_exhaustive]
160pub enum UpdateBalanceSettingsPaymentsPayoutsScheduleInterval {
161    Daily,
162    Manual,
163    Monthly,
164    Weekly,
165    /// An unrecognized value from Stripe. Should not be used as a request parameter.
166    Unknown(String),
167}
168impl UpdateBalanceSettingsPaymentsPayoutsScheduleInterval {
169    pub fn as_str(&self) -> &str {
170        use UpdateBalanceSettingsPaymentsPayoutsScheduleInterval::*;
171        match self {
172            Daily => "daily",
173            Manual => "manual",
174            Monthly => "monthly",
175            Weekly => "weekly",
176            Unknown(v) => v,
177        }
178    }
179}
180
181impl std::str::FromStr for UpdateBalanceSettingsPaymentsPayoutsScheduleInterval {
182    type Err = std::convert::Infallible;
183    fn from_str(s: &str) -> Result<Self, Self::Err> {
184        use UpdateBalanceSettingsPaymentsPayoutsScheduleInterval::*;
185        match s {
186            "daily" => Ok(Daily),
187            "manual" => Ok(Manual),
188            "monthly" => Ok(Monthly),
189            "weekly" => Ok(Weekly),
190            v => {
191                tracing::warn!(
192                    "Unknown value '{}' for enum '{}'",
193                    v,
194                    "UpdateBalanceSettingsPaymentsPayoutsScheduleInterval"
195                );
196                Ok(Unknown(v.to_owned()))
197            }
198        }
199    }
200}
201impl std::fmt::Display for UpdateBalanceSettingsPaymentsPayoutsScheduleInterval {
202    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
203        f.write_str(self.as_str())
204    }
205}
206
207impl std::fmt::Debug for UpdateBalanceSettingsPaymentsPayoutsScheduleInterval {
208    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
209        f.write_str(self.as_str())
210    }
211}
212impl serde::Serialize for UpdateBalanceSettingsPaymentsPayoutsScheduleInterval {
213    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
214    where
215        S: serde::Serializer,
216    {
217        serializer.serialize_str(self.as_str())
218    }
219}
220#[cfg(feature = "deserialize")]
221impl<'de> serde::Deserialize<'de> for UpdateBalanceSettingsPaymentsPayoutsScheduleInterval {
222    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
223        use std::str::FromStr;
224        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
225        Ok(Self::from_str(&s).expect("infallible"))
226    }
227}
228/// The days of the week when available funds are paid out, specified as an array, e.g., [`monday`, `tuesday`].
229/// Required and applicable only if `interval` is `weekly`.
230#[derive(Clone, Eq, PartialEq)]
231#[non_exhaustive]
232pub enum UpdateBalanceSettingsPaymentsPayoutsScheduleWeeklyPayoutDays {
233    Friday,
234    Monday,
235    Thursday,
236    Tuesday,
237    Wednesday,
238    /// An unrecognized value from Stripe. Should not be used as a request parameter.
239    Unknown(String),
240}
241impl UpdateBalanceSettingsPaymentsPayoutsScheduleWeeklyPayoutDays {
242    pub fn as_str(&self) -> &str {
243        use UpdateBalanceSettingsPaymentsPayoutsScheduleWeeklyPayoutDays::*;
244        match self {
245            Friday => "friday",
246            Monday => "monday",
247            Thursday => "thursday",
248            Tuesday => "tuesday",
249            Wednesday => "wednesday",
250            Unknown(v) => v,
251        }
252    }
253}
254
255impl std::str::FromStr for UpdateBalanceSettingsPaymentsPayoutsScheduleWeeklyPayoutDays {
256    type Err = std::convert::Infallible;
257    fn from_str(s: &str) -> Result<Self, Self::Err> {
258        use UpdateBalanceSettingsPaymentsPayoutsScheduleWeeklyPayoutDays::*;
259        match s {
260            "friday" => Ok(Friday),
261            "monday" => Ok(Monday),
262            "thursday" => Ok(Thursday),
263            "tuesday" => Ok(Tuesday),
264            "wednesday" => Ok(Wednesday),
265            v => {
266                tracing::warn!(
267                    "Unknown value '{}' for enum '{}'",
268                    v,
269                    "UpdateBalanceSettingsPaymentsPayoutsScheduleWeeklyPayoutDays"
270                );
271                Ok(Unknown(v.to_owned()))
272            }
273        }
274    }
275}
276impl std::fmt::Display for UpdateBalanceSettingsPaymentsPayoutsScheduleWeeklyPayoutDays {
277    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
278        f.write_str(self.as_str())
279    }
280}
281
282impl std::fmt::Debug for UpdateBalanceSettingsPaymentsPayoutsScheduleWeeklyPayoutDays {
283    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
284        f.write_str(self.as_str())
285    }
286}
287impl serde::Serialize for UpdateBalanceSettingsPaymentsPayoutsScheduleWeeklyPayoutDays {
288    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
289    where
290        S: serde::Serializer,
291    {
292        serializer.serialize_str(self.as_str())
293    }
294}
295#[cfg(feature = "deserialize")]
296impl<'de> serde::Deserialize<'de> for UpdateBalanceSettingsPaymentsPayoutsScheduleWeeklyPayoutDays {
297    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
298        use std::str::FromStr;
299        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
300        Ok(Self::from_str(&s).expect("infallible"))
301    }
302}
303/// Settings related to the account's balance settlement timing.
304#[derive(Copy, Clone, Debug, serde::Serialize)]
305pub struct UpdateBalanceSettingsPaymentsSettlementTiming {
306    /// Change `delay_days` for this account, which determines the number of days charge funds are held before becoming available.
307    /// The maximum value is 31.
308    /// Passing an empty string to `delay_days_override` will return `delay_days` to the default, which is the lowest available value for the account.
309    /// [Learn more about controlling delay days](/connect/manage-payout-schedule).
310    #[serde(skip_serializing_if = "Option::is_none")]
311    pub delay_days_override: Option<u32>,
312}
313impl UpdateBalanceSettingsPaymentsSettlementTiming {
314    pub fn new() -> Self {
315        Self { delay_days_override: None }
316    }
317}
318impl Default for UpdateBalanceSettingsPaymentsSettlementTiming {
319    fn default() -> Self {
320        Self::new()
321    }
322}
323/// Updates balance settings for a given connected account.
324///  Related guide: <a href="/connect/authentication">Making API calls for connected accounts</a>
325#[derive(Clone, Debug, serde::Serialize)]
326pub struct UpdateBalanceSettings {
327    inner: UpdateBalanceSettingsBuilder,
328}
329impl UpdateBalanceSettings {
330    /// Construct a new `UpdateBalanceSettings`.
331    pub fn new() -> Self {
332        Self { inner: UpdateBalanceSettingsBuilder::new() }
333    }
334    /// Specifies which fields in the response should be expanded.
335    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
336        self.inner.expand = Some(expand.into());
337        self
338    }
339    /// Settings that apply to the [Payments Balance](https://docs.stripe.com/api/balance).
340    pub fn payments(mut self, payments: impl Into<UpdateBalanceSettingsPayments>) -> Self {
341        self.inner.payments = Some(payments.into());
342        self
343    }
344}
345impl Default for UpdateBalanceSettings {
346    fn default() -> Self {
347        Self::new()
348    }
349}
350impl UpdateBalanceSettings {
351    /// Send the request and return the deserialized response.
352    pub async fn send<C: StripeClient>(
353        &self,
354        client: &C,
355    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
356        self.customize().send(client).await
357    }
358
359    /// Send the request and return the deserialized response, blocking until completion.
360    pub fn send_blocking<C: StripeBlockingClient>(
361        &self,
362        client: &C,
363    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
364        self.customize().send_blocking(client)
365    }
366}
367
368impl StripeRequest for UpdateBalanceSettings {
369    type Output = stripe_core::BalanceSettings;
370
371    fn build(&self) -> RequestBuilder {
372        RequestBuilder::new(StripeMethod::Post, "/balance_settings").form(&self.inner)
373    }
374}