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::{make_place, Deserialize, Result};
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
105                _ => <dyn Visitor>::ignore(),
106            })
107        }
108
109        fn deser_default() -> Self {
110            Self {
111                amount_paid: Deserialize::default(),
112                amount_requested: Deserialize::default(),
113                created: Deserialize::default(),
114                currency: Deserialize::default(),
115                id: Deserialize::default(),
116                invoice: Deserialize::default(),
117                is_default: Deserialize::default(),
118                livemode: Deserialize::default(),
119                payment: Deserialize::default(),
120                status: Deserialize::default(),
121                status_transitions: Deserialize::default(),
122            }
123        }
124
125        fn take_out(&mut self) -> Option<Self::Out> {
126            let (
127                Some(amount_paid),
128                Some(amount_requested),
129                Some(created),
130                Some(currency),
131                Some(id),
132                Some(invoice),
133                Some(is_default),
134                Some(livemode),
135                Some(payment),
136                Some(status),
137                Some(status_transitions),
138            ) = (
139                self.amount_paid,
140                self.amount_requested,
141                self.created,
142                self.currency.take(),
143                self.id.take(),
144                self.invoice.take(),
145                self.is_default,
146                self.livemode,
147                self.payment.take(),
148                self.status.take(),
149                self.status_transitions,
150            )
151            else {
152                return None;
153            };
154            Some(Self::Out {
155                amount_paid,
156                amount_requested,
157                created,
158                currency,
159                id,
160                invoice,
161                is_default,
162                livemode,
163                payment,
164                status,
165                status_transitions,
166            })
167        }
168    }
169
170    impl Map for Builder<'_> {
171        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
172            self.builder.key(k)
173        }
174
175        fn finish(&mut self) -> Result<()> {
176            *self.out = self.builder.take_out();
177            Ok(())
178        }
179    }
180
181    impl ObjectDeser for InvoicePayment {
182        type Builder = InvoicePaymentBuilder;
183    }
184
185    impl FromValueOpt for InvoicePayment {
186        fn from_value(v: Value) -> Option<Self> {
187            let Value::Object(obj) = v else {
188                return None;
189            };
190            let mut b = InvoicePaymentBuilder::deser_default();
191            for (k, v) in obj {
192                match k.as_str() {
193                    "amount_paid" => b.amount_paid = FromValueOpt::from_value(v),
194                    "amount_requested" => b.amount_requested = FromValueOpt::from_value(v),
195                    "created" => b.created = FromValueOpt::from_value(v),
196                    "currency" => b.currency = FromValueOpt::from_value(v),
197                    "id" => b.id = FromValueOpt::from_value(v),
198                    "invoice" => b.invoice = FromValueOpt::from_value(v),
199                    "is_default" => b.is_default = FromValueOpt::from_value(v),
200                    "livemode" => b.livemode = FromValueOpt::from_value(v),
201                    "payment" => b.payment = FromValueOpt::from_value(v),
202                    "status" => b.status = FromValueOpt::from_value(v),
203                    "status_transitions" => b.status_transitions = FromValueOpt::from_value(v),
204
205                    _ => {}
206                }
207            }
208            b.take_out()
209        }
210    }
211};
212#[cfg(feature = "serialize")]
213impl serde::Serialize for InvoicePayment {
214    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
215        use serde::ser::SerializeStruct;
216        let mut s = s.serialize_struct("InvoicePayment", 12)?;
217        s.serialize_field("amount_paid", &self.amount_paid)?;
218        s.serialize_field("amount_requested", &self.amount_requested)?;
219        s.serialize_field("created", &self.created)?;
220        s.serialize_field("currency", &self.currency)?;
221        s.serialize_field("id", &self.id)?;
222        s.serialize_field("invoice", &self.invoice)?;
223        s.serialize_field("is_default", &self.is_default)?;
224        s.serialize_field("livemode", &self.livemode)?;
225        s.serialize_field("payment", &self.payment)?;
226        s.serialize_field("status", &self.status)?;
227        s.serialize_field("status_transitions", &self.status_transitions)?;
228
229        s.serialize_field("object", "invoice_payment")?;
230        s.end()
231    }
232}
233impl stripe_types::Object for InvoicePayment {
234    type Id = stripe_shared::InvoicePaymentId;
235    fn id(&self) -> &Self::Id {
236        &self.id
237    }
238
239    fn into_id(self) -> Self::Id {
240        self.id
241    }
242}
243stripe_types::def_id!(InvoicePaymentId);