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(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://docs.stripe.com/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://docs.stripe.com/payments/customer-balance/reconciliation).
93#[derive(Clone, Eq, PartialEq)]
94#[non_exhaustive]
95pub enum UpdateCashBalanceSettingsReconciliationMode {
96    Automatic,
97    Manual,
98    MerchantDefault,
99    /// An unrecognized value from Stripe. Should not be used as a request parameter.
100    Unknown(String),
101}
102impl UpdateCashBalanceSettingsReconciliationMode {
103    pub fn as_str(&self) -> &str {
104        use UpdateCashBalanceSettingsReconciliationMode::*;
105        match self {
106            Automatic => "automatic",
107            Manual => "manual",
108            MerchantDefault => "merchant_default",
109            Unknown(v) => v,
110        }
111    }
112}
113
114impl std::str::FromStr for UpdateCashBalanceSettingsReconciliationMode {
115    type Err = std::convert::Infallible;
116    fn from_str(s: &str) -> Result<Self, Self::Err> {
117        use UpdateCashBalanceSettingsReconciliationMode::*;
118        match s {
119            "automatic" => Ok(Automatic),
120            "manual" => Ok(Manual),
121            "merchant_default" => Ok(MerchantDefault),
122            v => {
123                tracing::warn!(
124                    "Unknown value '{}' for enum '{}'",
125                    v,
126                    "UpdateCashBalanceSettingsReconciliationMode"
127                );
128                Ok(Unknown(v.to_owned()))
129            }
130        }
131    }
132}
133impl std::fmt::Display for UpdateCashBalanceSettingsReconciliationMode {
134    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
135        f.write_str(self.as_str())
136    }
137}
138
139impl std::fmt::Debug for UpdateCashBalanceSettingsReconciliationMode {
140    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
141        f.write_str(self.as_str())
142    }
143}
144impl serde::Serialize for UpdateCashBalanceSettingsReconciliationMode {
145    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
146    where
147        S: serde::Serializer,
148    {
149        serializer.serialize_str(self.as_str())
150    }
151}
152#[cfg(feature = "deserialize")]
153impl<'de> serde::Deserialize<'de> for UpdateCashBalanceSettingsReconciliationMode {
154    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
155        use std::str::FromStr;
156        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
157        Ok(Self::from_str(&s).expect("infallible"))
158    }
159}
160/// Changes the settings on a customer’s cash balance.
161#[derive(Clone, Debug, serde::Serialize)]
162pub struct UpdateCashBalance {
163    inner: UpdateCashBalanceBuilder,
164    customer: stripe_shared::CustomerId,
165}
166impl UpdateCashBalance {
167    /// Construct a new `UpdateCashBalance`.
168    pub fn new(customer: impl Into<stripe_shared::CustomerId>) -> Self {
169        Self { customer: customer.into(), inner: UpdateCashBalanceBuilder::new() }
170    }
171    /// Specifies which fields in the response should be expanded.
172    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
173        self.inner.expand = Some(expand.into());
174        self
175    }
176    /// A hash of settings for this cash balance.
177    pub fn settings(mut self, settings: impl Into<UpdateCashBalanceSettings>) -> Self {
178        self.inner.settings = Some(settings.into());
179        self
180    }
181}
182impl UpdateCashBalance {
183    /// Send the request and return the deserialized response.
184    pub async fn send<C: StripeClient>(
185        &self,
186        client: &C,
187    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
188        self.customize().send(client).await
189    }
190
191    /// Send the request and return the deserialized response, blocking until completion.
192    pub fn send_blocking<C: StripeBlockingClient>(
193        &self,
194        client: &C,
195    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
196        self.customize().send_blocking(client)
197    }
198}
199
200impl StripeRequest for UpdateCashBalance {
201    type Output = stripe_shared::CashBalance;
202
203    fn build(&self) -> RequestBuilder {
204        let customer = &self.customer;
205        RequestBuilder::new(StripeMethod::Post, format!("/customers/{customer}/cash_balance"))
206            .form(&self.inner)
207    }
208}