stripe_shared/
payment_method_details_card_installments_plan.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentMethodDetailsCardInstallmentsPlan {
5    /// For `fixed_count` installment plans, this is the number of installment payments your customer will make to their credit card.
6    pub count: Option<u64>,
7    /// For `fixed_count` installment plans, this is the interval between installment payments your customer will make to their credit card.
8    /// One of `month`.
9    pub interval: Option<PaymentMethodDetailsCardInstallmentsPlanInterval>,
10    /// Type of installment plan, one of `fixed_count`, `bonus`, or `revolving`.
11    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
12    pub type_: PaymentMethodDetailsCardInstallmentsPlanType,
13}
14#[doc(hidden)]
15pub struct PaymentMethodDetailsCardInstallmentsPlanBuilder {
16    count: Option<Option<u64>>,
17    interval: Option<Option<PaymentMethodDetailsCardInstallmentsPlanInterval>>,
18    type_: Option<PaymentMethodDetailsCardInstallmentsPlanType>,
19}
20
21#[allow(
22    unused_variables,
23    irrefutable_let_patterns,
24    clippy::let_unit_value,
25    clippy::match_single_binding,
26    clippy::single_match
27)]
28const _: () = {
29    use miniserde::de::{Map, Visitor};
30    use miniserde::json::Value;
31    use miniserde::{Deserialize, Result, make_place};
32    use stripe_types::miniserde_helpers::FromValueOpt;
33    use stripe_types::{MapBuilder, ObjectDeser};
34
35    make_place!(Place);
36
37    impl Deserialize for PaymentMethodDetailsCardInstallmentsPlan {
38        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
39            Place::new(out)
40        }
41    }
42
43    struct Builder<'a> {
44        out: &'a mut Option<PaymentMethodDetailsCardInstallmentsPlan>,
45        builder: PaymentMethodDetailsCardInstallmentsPlanBuilder,
46    }
47
48    impl Visitor for Place<PaymentMethodDetailsCardInstallmentsPlan> {
49        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
50            Ok(Box::new(Builder {
51                out: &mut self.out,
52                builder: PaymentMethodDetailsCardInstallmentsPlanBuilder::deser_default(),
53            }))
54        }
55    }
56
57    impl MapBuilder for PaymentMethodDetailsCardInstallmentsPlanBuilder {
58        type Out = PaymentMethodDetailsCardInstallmentsPlan;
59        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
60            Ok(match k {
61                "count" => Deserialize::begin(&mut self.count),
62                "interval" => Deserialize::begin(&mut self.interval),
63                "type" => Deserialize::begin(&mut self.type_),
64                _ => <dyn Visitor>::ignore(),
65            })
66        }
67
68        fn deser_default() -> Self {
69            Self {
70                count: Deserialize::default(),
71                interval: Deserialize::default(),
72                type_: Deserialize::default(),
73            }
74        }
75
76        fn take_out(&mut self) -> Option<Self::Out> {
77            let (Some(count), Some(interval), Some(type_)) =
78                (self.count, self.interval.take(), self.type_.take())
79            else {
80                return None;
81            };
82            Some(Self::Out { count, interval, type_ })
83        }
84    }
85
86    impl Map for Builder<'_> {
87        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
88            self.builder.key(k)
89        }
90
91        fn finish(&mut self) -> Result<()> {
92            *self.out = self.builder.take_out();
93            Ok(())
94        }
95    }
96
97    impl ObjectDeser for PaymentMethodDetailsCardInstallmentsPlan {
98        type Builder = PaymentMethodDetailsCardInstallmentsPlanBuilder;
99    }
100
101    impl FromValueOpt for PaymentMethodDetailsCardInstallmentsPlan {
102        fn from_value(v: Value) -> Option<Self> {
103            let Value::Object(obj) = v else {
104                return None;
105            };
106            let mut b = PaymentMethodDetailsCardInstallmentsPlanBuilder::deser_default();
107            for (k, v) in obj {
108                match k.as_str() {
109                    "count" => b.count = FromValueOpt::from_value(v),
110                    "interval" => b.interval = FromValueOpt::from_value(v),
111                    "type" => b.type_ = FromValueOpt::from_value(v),
112                    _ => {}
113                }
114            }
115            b.take_out()
116        }
117    }
118};
119/// For `fixed_count` installment plans, this is the interval between installment payments your customer will make to their credit card.
120/// One of `month`.
121#[derive(Clone, Eq, PartialEq)]
122#[non_exhaustive]
123pub enum PaymentMethodDetailsCardInstallmentsPlanInterval {
124    Month,
125    /// An unrecognized value from Stripe. Should not be used as a request parameter.
126    Unknown(String),
127}
128impl PaymentMethodDetailsCardInstallmentsPlanInterval {
129    pub fn as_str(&self) -> &str {
130        use PaymentMethodDetailsCardInstallmentsPlanInterval::*;
131        match self {
132            Month => "month",
133            Unknown(v) => v,
134        }
135    }
136}
137
138impl std::str::FromStr for PaymentMethodDetailsCardInstallmentsPlanInterval {
139    type Err = std::convert::Infallible;
140    fn from_str(s: &str) -> Result<Self, Self::Err> {
141        use PaymentMethodDetailsCardInstallmentsPlanInterval::*;
142        match s {
143            "month" => Ok(Month),
144            v => {
145                tracing::warn!(
146                    "Unknown value '{}' for enum '{}'",
147                    v,
148                    "PaymentMethodDetailsCardInstallmentsPlanInterval"
149                );
150                Ok(Unknown(v.to_owned()))
151            }
152        }
153    }
154}
155impl std::fmt::Display for PaymentMethodDetailsCardInstallmentsPlanInterval {
156    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
157        f.write_str(self.as_str())
158    }
159}
160
161impl std::fmt::Debug for PaymentMethodDetailsCardInstallmentsPlanInterval {
162    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
163        f.write_str(self.as_str())
164    }
165}
166#[cfg(feature = "serialize")]
167impl serde::Serialize for PaymentMethodDetailsCardInstallmentsPlanInterval {
168    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
169    where
170        S: serde::Serializer,
171    {
172        serializer.serialize_str(self.as_str())
173    }
174}
175impl miniserde::Deserialize for PaymentMethodDetailsCardInstallmentsPlanInterval {
176    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
177        crate::Place::new(out)
178    }
179}
180
181impl miniserde::de::Visitor for crate::Place<PaymentMethodDetailsCardInstallmentsPlanInterval> {
182    fn string(&mut self, s: &str) -> miniserde::Result<()> {
183        use std::str::FromStr;
184        self.out = Some(
185            PaymentMethodDetailsCardInstallmentsPlanInterval::from_str(s).expect("infallible"),
186        );
187        Ok(())
188    }
189}
190
191stripe_types::impl_from_val_with_from_str!(PaymentMethodDetailsCardInstallmentsPlanInterval);
192#[cfg(feature = "deserialize")]
193impl<'de> serde::Deserialize<'de> for PaymentMethodDetailsCardInstallmentsPlanInterval {
194    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
195        use std::str::FromStr;
196        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
197        Ok(Self::from_str(&s).expect("infallible"))
198    }
199}
200/// Type of installment plan, one of `fixed_count`, `bonus`, or `revolving`.
201#[derive(Clone, Eq, PartialEq)]
202#[non_exhaustive]
203pub enum PaymentMethodDetailsCardInstallmentsPlanType {
204    Bonus,
205    FixedCount,
206    Revolving,
207    /// An unrecognized value from Stripe. Should not be used as a request parameter.
208    Unknown(String),
209}
210impl PaymentMethodDetailsCardInstallmentsPlanType {
211    pub fn as_str(&self) -> &str {
212        use PaymentMethodDetailsCardInstallmentsPlanType::*;
213        match self {
214            Bonus => "bonus",
215            FixedCount => "fixed_count",
216            Revolving => "revolving",
217            Unknown(v) => v,
218        }
219    }
220}
221
222impl std::str::FromStr for PaymentMethodDetailsCardInstallmentsPlanType {
223    type Err = std::convert::Infallible;
224    fn from_str(s: &str) -> Result<Self, Self::Err> {
225        use PaymentMethodDetailsCardInstallmentsPlanType::*;
226        match s {
227            "bonus" => Ok(Bonus),
228            "fixed_count" => Ok(FixedCount),
229            "revolving" => Ok(Revolving),
230            v => {
231                tracing::warn!(
232                    "Unknown value '{}' for enum '{}'",
233                    v,
234                    "PaymentMethodDetailsCardInstallmentsPlanType"
235                );
236                Ok(Unknown(v.to_owned()))
237            }
238        }
239    }
240}
241impl std::fmt::Display for PaymentMethodDetailsCardInstallmentsPlanType {
242    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
243        f.write_str(self.as_str())
244    }
245}
246
247impl std::fmt::Debug for PaymentMethodDetailsCardInstallmentsPlanType {
248    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
249        f.write_str(self.as_str())
250    }
251}
252#[cfg(feature = "serialize")]
253impl serde::Serialize for PaymentMethodDetailsCardInstallmentsPlanType {
254    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
255    where
256        S: serde::Serializer,
257    {
258        serializer.serialize_str(self.as_str())
259    }
260}
261impl miniserde::Deserialize for PaymentMethodDetailsCardInstallmentsPlanType {
262    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
263        crate::Place::new(out)
264    }
265}
266
267impl miniserde::de::Visitor for crate::Place<PaymentMethodDetailsCardInstallmentsPlanType> {
268    fn string(&mut self, s: &str) -> miniserde::Result<()> {
269        use std::str::FromStr;
270        self.out =
271            Some(PaymentMethodDetailsCardInstallmentsPlanType::from_str(s).expect("infallible"));
272        Ok(())
273    }
274}
275
276stripe_types::impl_from_val_with_from_str!(PaymentMethodDetailsCardInstallmentsPlanType);
277#[cfg(feature = "deserialize")]
278impl<'de> serde::Deserialize<'de> for PaymentMethodDetailsCardInstallmentsPlanType {
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        Ok(Self::from_str(&s).expect("infallible"))
283    }
284}