stripe_core/cash_balance/
requests.rs

1use stripe_client_core::{
2    RequestBuilder, StripeBlockingClient, StripeClient, StripeMethod, StripeRequest,
3};
4
5#[derive(Clone, Debug, serde::Serialize)]
6struct RetrieveCashBalanceBuilder {
7    #[serde(skip_serializing_if = "Option::is_none")]
8    expand: Option<Vec<String>>,
9}
10impl RetrieveCashBalanceBuilder {
11    fn new() -> Self {
12        Self { expand: None }
13    }
14}
15/// Retrieves a customer’s cash balance.
16#[derive(Clone, Debug, serde::Serialize)]
17pub struct RetrieveCashBalance {
18    inner: RetrieveCashBalanceBuilder,
19    customer: stripe_shared::CustomerId,
20}
21impl RetrieveCashBalance {
22    /// Construct a new `RetrieveCashBalance`.
23    pub fn new(customer: impl Into<stripe_shared::CustomerId>) -> Self {
24        Self { customer: customer.into(), inner: RetrieveCashBalanceBuilder::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 RetrieveCashBalance {
33    /// Send the request and return the deserialized response.
34    pub async fn send<C: StripeClient>(
35        &self,
36        client: &C,
37    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
38        self.customize().send(client).await
39    }
40
41    /// Send the request and return the deserialized response, blocking until completion.
42    pub fn send_blocking<C: StripeBlockingClient>(
43        &self,
44        client: &C,
45    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
46        self.customize().send_blocking(client)
47    }
48}
49
50impl StripeRequest for RetrieveCashBalance {
51    type Output = stripe_shared::CashBalance;
52
53    fn build(&self) -> RequestBuilder {
54        let customer = &self.customer;
55        RequestBuilder::new(StripeMethod::Get, format!("/customers/{customer}/cash_balance"))
56            .query(&self.inner)
57    }
58}
59#[derive(Clone, Debug, serde::Serialize)]
60struct UpdateCashBalanceBuilder {
61    #[serde(skip_serializing_if = "Option::is_none")]
62    expand: Option<Vec<String>>,
63    #[serde(skip_serializing_if = "Option::is_none")]
64    settings: Option<UpdateCashBalanceSettings>,
65}
66impl UpdateCashBalanceBuilder {
67    fn new() -> Self {
68        Self { expand: None, settings: None }
69    }
70}
71/// A hash of settings for this cash balance.
72#[derive(Copy, Clone, Debug, serde::Serialize)]
73pub struct UpdateCashBalanceSettings {
74    /// Controls how funds transferred by the customer are applied to payment intents and invoices.
75    /// Valid options are `automatic`, `manual`, or `merchant_default`.
76    /// For more information about these reconciliation modes, see [Reconciliation](https://stripe.com/docs/payments/customer-balance/reconciliation).
77    #[serde(skip_serializing_if = "Option::is_none")]
78    pub reconciliation_mode: Option<UpdateCashBalanceSettingsReconciliationMode>,
79}
80impl UpdateCashBalanceSettings {
81    pub fn new() -> Self {
82        Self { reconciliation_mode: None }
83    }
84}
85impl Default for UpdateCashBalanceSettings {
86    fn default() -> Self {
87        Self::new()
88    }
89}
90/// Controls how funds transferred by the customer are applied to payment intents and invoices.
91/// Valid options are `automatic`, `manual`, or `merchant_default`.
92/// For more information about these reconciliation modes, see [Reconciliation](https://stripe.com/docs/payments/customer-balance/reconciliation).
93#[derive(Copy, Clone, Eq, PartialEq)]
94pub enum UpdateCashBalanceSettingsReconciliationMode {
95    Automatic,
96    Manual,
97    MerchantDefault,
98}
99impl UpdateCashBalanceSettingsReconciliationMode {
100    pub fn as_str(self) -> &'static str {
101        use UpdateCashBalanceSettingsReconciliationMode::*;
102        match self {
103            Automatic => "automatic",
104            Manual => "manual",
105            MerchantDefault => "merchant_default",
106        }
107    }
108}
109
110impl std::str::FromStr for UpdateCashBalanceSettingsReconciliationMode {
111    type Err = stripe_types::StripeParseError;
112    fn from_str(s: &str) -> Result<Self, Self::Err> {
113        use UpdateCashBalanceSettingsReconciliationMode::*;
114        match s {
115            "automatic" => Ok(Automatic),
116            "manual" => Ok(Manual),
117            "merchant_default" => Ok(MerchantDefault),
118            _ => Err(stripe_types::StripeParseError),
119        }
120    }
121}
122impl std::fmt::Display for UpdateCashBalanceSettingsReconciliationMode {
123    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
124        f.write_str(self.as_str())
125    }
126}
127
128impl std::fmt::Debug for UpdateCashBalanceSettingsReconciliationMode {
129    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
130        f.write_str(self.as_str())
131    }
132}
133impl serde::Serialize for UpdateCashBalanceSettingsReconciliationMode {
134    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
135    where
136        S: serde::Serializer,
137    {
138        serializer.serialize_str(self.as_str())
139    }
140}
141#[cfg(feature = "deserialize")]
142impl<'de> serde::Deserialize<'de> for UpdateCashBalanceSettingsReconciliationMode {
143    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
144        use std::str::FromStr;
145        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
146        Self::from_str(&s).map_err(|_| {
147            serde::de::Error::custom(
148                "Unknown value for UpdateCashBalanceSettingsReconciliationMode",
149            )
150        })
151    }
152}
153/// Changes the settings on a customer’s cash balance.
154#[derive(Clone, Debug, serde::Serialize)]
155pub struct UpdateCashBalance {
156    inner: UpdateCashBalanceBuilder,
157    customer: stripe_shared::CustomerId,
158}
159impl UpdateCashBalance {
160    /// Construct a new `UpdateCashBalance`.
161    pub fn new(customer: impl Into<stripe_shared::CustomerId>) -> Self {
162        Self { customer: customer.into(), inner: UpdateCashBalanceBuilder::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    /// A hash of settings for this cash balance.
170    pub fn settings(mut self, settings: impl Into<UpdateCashBalanceSettings>) -> Self {
171        self.inner.settings = Some(settings.into());
172        self
173    }
174}
175impl UpdateCashBalance {
176    /// Send the request and return the deserialized response.
177    pub async fn send<C: StripeClient>(
178        &self,
179        client: &C,
180    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
181        self.customize().send(client).await
182    }
183
184    /// Send the request and return the deserialized response, blocking until completion.
185    pub fn send_blocking<C: StripeBlockingClient>(
186        &self,
187        client: &C,
188    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
189        self.customize().send_blocking(client)
190    }
191}
192
193impl StripeRequest for UpdateCashBalance {
194    type Output = stripe_shared::CashBalance;
195
196    fn build(&self) -> RequestBuilder {
197        let customer = &self.customer;
198        RequestBuilder::new(StripeMethod::Post, format!("/customers/{customer}/cash_balance"))
199            .form(&self.inner)
200    }
201}