stripe_shared/
invoice_payment.rs

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