stripe_shared/
invoice_payment_method_options_acss_debit_mandate_options.rs1#[derive(Copy, Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct InvoicePaymentMethodOptionsAcssDebitMandateOptions {
5 pub transaction_type: Option<InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType>,
7}
8#[doc(hidden)]
9pub struct InvoicePaymentMethodOptionsAcssDebitMandateOptionsBuilder {
10 transaction_type:
11 Option<Option<InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType>>,
12}
13
14#[allow(
15 unused_variables,
16 irrefutable_let_patterns,
17 clippy::let_unit_value,
18 clippy::match_single_binding,
19 clippy::single_match
20)]
21const _: () = {
22 use miniserde::de::{Map, Visitor};
23 use miniserde::json::Value;
24 use miniserde::{make_place, Deserialize, Result};
25 use stripe_types::miniserde_helpers::FromValueOpt;
26 use stripe_types::{MapBuilder, ObjectDeser};
27
28 make_place!(Place);
29
30 impl Deserialize for InvoicePaymentMethodOptionsAcssDebitMandateOptions {
31 fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
32 Place::new(out)
33 }
34 }
35
36 struct Builder<'a> {
37 out: &'a mut Option<InvoicePaymentMethodOptionsAcssDebitMandateOptions>,
38 builder: InvoicePaymentMethodOptionsAcssDebitMandateOptionsBuilder,
39 }
40
41 impl Visitor for Place<InvoicePaymentMethodOptionsAcssDebitMandateOptions> {
42 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
43 Ok(Box::new(Builder {
44 out: &mut self.out,
45 builder: InvoicePaymentMethodOptionsAcssDebitMandateOptionsBuilder::deser_default(),
46 }))
47 }
48 }
49
50 impl MapBuilder for InvoicePaymentMethodOptionsAcssDebitMandateOptionsBuilder {
51 type Out = InvoicePaymentMethodOptionsAcssDebitMandateOptions;
52 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
53 Ok(match k {
54 "transaction_type" => Deserialize::begin(&mut self.transaction_type),
55
56 _ => <dyn Visitor>::ignore(),
57 })
58 }
59
60 fn deser_default() -> Self {
61 Self { transaction_type: Deserialize::default() }
62 }
63
64 fn take_out(&mut self) -> Option<Self::Out> {
65 let (Some(transaction_type),) = (self.transaction_type,) else {
66 return None;
67 };
68 Some(Self::Out { transaction_type })
69 }
70 }
71
72 impl Map for Builder<'_> {
73 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
74 self.builder.key(k)
75 }
76
77 fn finish(&mut self) -> Result<()> {
78 *self.out = self.builder.take_out();
79 Ok(())
80 }
81 }
82
83 impl ObjectDeser for InvoicePaymentMethodOptionsAcssDebitMandateOptions {
84 type Builder = InvoicePaymentMethodOptionsAcssDebitMandateOptionsBuilder;
85 }
86
87 impl FromValueOpt for InvoicePaymentMethodOptionsAcssDebitMandateOptions {
88 fn from_value(v: Value) -> Option<Self> {
89 let Value::Object(obj) = v else {
90 return None;
91 };
92 let mut b = InvoicePaymentMethodOptionsAcssDebitMandateOptionsBuilder::deser_default();
93 for (k, v) in obj {
94 match k.as_str() {
95 "transaction_type" => b.transaction_type = FromValueOpt::from_value(v),
96
97 _ => {}
98 }
99 }
100 b.take_out()
101 }
102 }
103};
104#[derive(Copy, Clone, Eq, PartialEq)]
106pub enum InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType {
107 Business,
108 Personal,
109}
110impl InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType {
111 pub fn as_str(self) -> &'static str {
112 use InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType::*;
113 match self {
114 Business => "business",
115 Personal => "personal",
116 }
117 }
118}
119
120impl std::str::FromStr for InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType {
121 type Err = stripe_types::StripeParseError;
122 fn from_str(s: &str) -> Result<Self, Self::Err> {
123 use InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType::*;
124 match s {
125 "business" => Ok(Business),
126 "personal" => Ok(Personal),
127 _ => Err(stripe_types::StripeParseError),
128 }
129 }
130}
131impl std::fmt::Display for InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType {
132 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
133 f.write_str(self.as_str())
134 }
135}
136
137impl std::fmt::Debug for InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType {
138 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
139 f.write_str(self.as_str())
140 }
141}
142#[cfg(feature = "serialize")]
143impl serde::Serialize for InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType {
144 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
145 where
146 S: serde::Serializer,
147 {
148 serializer.serialize_str(self.as_str())
149 }
150}
151impl miniserde::Deserialize for InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType {
152 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
153 crate::Place::new(out)
154 }
155}
156
157impl miniserde::de::Visitor
158 for crate::Place<InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType>
159{
160 fn string(&mut self, s: &str) -> miniserde::Result<()> {
161 use std::str::FromStr;
162 self.out = Some(
163 InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType::from_str(s)
164 .map_err(|_| miniserde::Error)?,
165 );
166 Ok(())
167 }
168}
169
170stripe_types::impl_from_val_with_from_str!(
171 InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType
172);
173#[cfg(feature = "deserialize")]
174impl<'de> serde::Deserialize<'de>
175 for InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType
176{
177 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
178 use std::str::FromStr;
179 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
180 Self::from_str(&s).map_err(|_| serde::de::Error::custom("Unknown value for InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType"))
181 }
182}