stripe_shared/
invoice_payment.rs

1/// The invoice payment object
2#[derive(Clone, Debug)]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct InvoicePayment {
5    /// Amount that was actually paid for this invoice, in cents (or local equivalent).
6    /// This field is null until the payment is `paid`.
7    /// This amount can be less than the `amount_requested` if the PaymentIntent’s `amount_received` is not sufficient to pay all of the invoices that it is attached to.
8    pub amount_paid: Option<i64>,
9    /// Amount intended to be paid toward this invoice, in cents (or local equivalent)
10    pub amount_requested: i64,
11    /// Time at which the object was created. Measured in seconds since the Unix epoch.
12    pub created: stripe_types::Timestamp,
13    /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
14    /// Must be a [supported currency](https://stripe.com/docs/currencies).
15    pub currency: stripe_types::Currency,
16    /// Unique identifier for the object.
17    pub id: stripe_shared::InvoicePaymentId,
18    /// The invoice that was paid.
19    pub invoice: stripe_types::Expandable<stripe_shared::Invoice>,
20    /// Stripe automatically creates a default InvoicePayment when the invoice is finalized, and keeps it synchronized with the invoice’s `amount_remaining`.
21    /// The PaymentIntent associated with the default payment can’t be edited or canceled directly.
22    pub is_default: bool,
23    /// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
24    pub livemode: bool,
25    pub payment: stripe_shared::InvoicesPaymentsInvoicePaymentAssociatedPayment,
26    /// The status of the payment, one of `open`, `paid`, or `canceled`.
27    pub status: String,
28    pub status_transitions: stripe_shared::InvoicesPaymentsInvoicePaymentStatusTransitions,
29}
30#[doc(hidden)]
31pub struct InvoicePaymentBuilder {
32    amount_paid: Option<Option<i64>>,
33    amount_requested: Option<i64>,
34    created: Option<stripe_types::Timestamp>,
35    currency: Option<stripe_types::Currency>,
36    id: Option<stripe_shared::InvoicePaymentId>,
37    invoice: Option<stripe_types::Expandable<stripe_shared::Invoice>>,
38    is_default: Option<bool>,
39    livemode: Option<bool>,
40    payment: Option<stripe_shared::InvoicesPaymentsInvoicePaymentAssociatedPayment>,
41    status: Option<String>,
42    status_transitions: Option<stripe_shared::InvoicesPaymentsInvoicePaymentStatusTransitions>,
43}
44
45#[allow(
46    unused_variables,
47    irrefutable_let_patterns,
48    clippy::let_unit_value,
49    clippy::match_single_binding,
50    clippy::single_match
51)]
52const _: () = {
53    use miniserde::de::{Map, Visitor};
54    use miniserde::json::Value;
55    use miniserde::{make_place, Deserialize, Result};
56    use stripe_types::miniserde_helpers::FromValueOpt;
57    use stripe_types::{MapBuilder, ObjectDeser};
58
59    make_place!(Place);
60
61    impl Deserialize for InvoicePayment {
62        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
63            Place::new(out)
64        }
65    }
66
67    struct Builder<'a> {
68        out: &'a mut Option<InvoicePayment>,
69        builder: InvoicePaymentBuilder,
70    }
71
72    impl Visitor for Place<InvoicePayment> {
73        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
74            Ok(Box::new(Builder {
75                out: &mut self.out,
76                builder: InvoicePaymentBuilder::deser_default(),
77            }))
78        }
79    }
80
81    impl MapBuilder for InvoicePaymentBuilder {
82        type Out = InvoicePayment;
83        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
84            Ok(match k {
85                "amount_paid" => Deserialize::begin(&mut self.amount_paid),
86                "amount_requested" => Deserialize::begin(&mut self.amount_requested),
87                "created" => Deserialize::begin(&mut self.created),
88                "currency" => Deserialize::begin(&mut self.currency),
89                "id" => Deserialize::begin(&mut self.id),
90                "invoice" => Deserialize::begin(&mut self.invoice),
91                "is_default" => Deserialize::begin(&mut self.is_default),
92                "livemode" => Deserialize::begin(&mut self.livemode),
93                "payment" => Deserialize::begin(&mut self.payment),
94                "status" => Deserialize::begin(&mut self.status),
95                "status_transitions" => Deserialize::begin(&mut self.status_transitions),
96
97                _ => <dyn Visitor>::ignore(),
98            })
99        }
100
101        fn deser_default() -> Self {
102            Self {
103                amount_paid: Deserialize::default(),
104                amount_requested: Deserialize::default(),
105                created: Deserialize::default(),
106                currency: Deserialize::default(),
107                id: Deserialize::default(),
108                invoice: Deserialize::default(),
109                is_default: Deserialize::default(),
110                livemode: Deserialize::default(),
111                payment: Deserialize::default(),
112                status: Deserialize::default(),
113                status_transitions: Deserialize::default(),
114            }
115        }
116
117        fn take_out(&mut self) -> Option<Self::Out> {
118            let (
119                Some(amount_paid),
120                Some(amount_requested),
121                Some(created),
122                Some(currency),
123                Some(id),
124                Some(invoice),
125                Some(is_default),
126                Some(livemode),
127                Some(payment),
128                Some(status),
129                Some(status_transitions),
130            ) = (
131                self.amount_paid,
132                self.amount_requested,
133                self.created,
134                self.currency,
135                self.id.take(),
136                self.invoice.take(),
137                self.is_default,
138                self.livemode,
139                self.payment.take(),
140                self.status.take(),
141                self.status_transitions,
142            )
143            else {
144                return None;
145            };
146            Some(Self::Out {
147                amount_paid,
148                amount_requested,
149                created,
150                currency,
151                id,
152                invoice,
153                is_default,
154                livemode,
155                payment,
156                status,
157                status_transitions,
158            })
159        }
160    }
161
162    impl<'a> Map for Builder<'a> {
163        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
164            self.builder.key(k)
165        }
166
167        fn finish(&mut self) -> Result<()> {
168            *self.out = self.builder.take_out();
169            Ok(())
170        }
171    }
172
173    impl ObjectDeser for InvoicePayment {
174        type Builder = InvoicePaymentBuilder;
175    }
176
177    impl FromValueOpt for InvoicePayment {
178        fn from_value(v: Value) -> Option<Self> {
179            let Value::Object(obj) = v else {
180                return None;
181            };
182            let mut b = InvoicePaymentBuilder::deser_default();
183            for (k, v) in obj {
184                match k.as_str() {
185                    "amount_paid" => b.amount_paid = FromValueOpt::from_value(v),
186                    "amount_requested" => b.amount_requested = FromValueOpt::from_value(v),
187                    "created" => b.created = FromValueOpt::from_value(v),
188                    "currency" => b.currency = FromValueOpt::from_value(v),
189                    "id" => b.id = FromValueOpt::from_value(v),
190                    "invoice" => b.invoice = FromValueOpt::from_value(v),
191                    "is_default" => b.is_default = FromValueOpt::from_value(v),
192                    "livemode" => b.livemode = FromValueOpt::from_value(v),
193                    "payment" => b.payment = FromValueOpt::from_value(v),
194                    "status" => b.status = FromValueOpt::from_value(v),
195                    "status_transitions" => b.status_transitions = FromValueOpt::from_value(v),
196
197                    _ => {}
198                }
199            }
200            b.take_out()
201        }
202    }
203};
204#[cfg(feature = "serialize")]
205impl serde::Serialize for InvoicePayment {
206    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
207        use serde::ser::SerializeStruct;
208        let mut s = s.serialize_struct("InvoicePayment", 12)?;
209        s.serialize_field("amount_paid", &self.amount_paid)?;
210        s.serialize_field("amount_requested", &self.amount_requested)?;
211        s.serialize_field("created", &self.created)?;
212        s.serialize_field("currency", &self.currency)?;
213        s.serialize_field("id", &self.id)?;
214        s.serialize_field("invoice", &self.invoice)?;
215        s.serialize_field("is_default", &self.is_default)?;
216        s.serialize_field("livemode", &self.livemode)?;
217        s.serialize_field("payment", &self.payment)?;
218        s.serialize_field("status", &self.status)?;
219        s.serialize_field("status_transitions", &self.status_transitions)?;
220
221        s.serialize_field("object", "invoice_payment")?;
222        s.end()
223    }
224}
225impl stripe_types::Object for InvoicePayment {
226    type Id = stripe_shared::InvoicePaymentId;
227    fn id(&self) -> &Self::Id {
228        &self.id
229    }
230
231    fn into_id(self) -> Self::Id {
232        self.id
233    }
234}
235stripe_types::def_id!(InvoicePaymentId);