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