stripe_shared/
invoice_payment.rs

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