stripe_shared/
payment_record.rs

1/// A Payment Record is a resource that allows you to represent payments that occur on- or off-Stripe.
2/// For example, you can create a Payment Record to model a payment made on a different payment processor,.
3/// in order to mark an Invoice as paid and a Subscription as active. Payment Records consist of one or
4/// more Payment Attempt Records, which represent individual attempts made on a payment network.
5#[derive(Clone, Debug)]
6#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
7pub struct PaymentRecord {
8    pub amount: stripe_shared::PaymentsPrimitivesPaymentRecordsResourceAmount,
9    pub amount_authorized: stripe_shared::PaymentsPrimitivesPaymentRecordsResourceAmount,
10    pub amount_canceled: stripe_shared::PaymentsPrimitivesPaymentRecordsResourceAmount,
11    pub amount_failed: stripe_shared::PaymentsPrimitivesPaymentRecordsResourceAmount,
12    pub amount_guaranteed: stripe_shared::PaymentsPrimitivesPaymentRecordsResourceAmount,
13    pub amount_refunded: stripe_shared::PaymentsPrimitivesPaymentRecordsResourceAmount,
14    pub amount_requested: stripe_shared::PaymentsPrimitivesPaymentRecordsResourceAmount,
15    /// ID of the Connect application that created the PaymentRecord.
16    pub application: Option<String>,
17    /// Time at which the object was created. Measured in seconds since the Unix epoch.
18    pub created: stripe_types::Timestamp,
19    /// Customer information for this payment.
20    pub customer_details:
21        Option<stripe_shared::PaymentsPrimitivesPaymentRecordsResourceCustomerDetails>,
22    /// Indicates whether the customer was present in your checkout flow during this payment.
23    pub customer_presence: Option<stripe_shared::PaymentRecordCustomerPresence>,
24    /// An arbitrary string attached to the object. Often useful for displaying to users.
25    pub description: Option<String>,
26    /// Unique identifier for the object.
27    pub id: stripe_shared::PaymentRecordId,
28    /// ID of the latest Payment Attempt Record attached to this Payment Record.
29    pub latest_payment_attempt_record: Option<String>,
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    /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
33    /// This can be useful for storing additional information about the object in a structured format.
34    pub metadata: std::collections::HashMap<String, String>,
35    /// Information about the Payment Method debited for this payment.
36    pub payment_method_details:
37        Option<stripe_shared::PaymentsPrimitivesPaymentRecordsResourcePaymentMethodDetails>,
38    pub processor_details: stripe_shared::PaymentsPrimitivesPaymentRecordsResourceProcessorDetails,
39    /// Shipping information for this payment.
40    pub shipping_details:
41        Option<stripe_shared::PaymentsPrimitivesPaymentRecordsResourceShippingDetails>,
42}
43#[doc(hidden)]
44pub struct PaymentRecordBuilder {
45    amount: Option<stripe_shared::PaymentsPrimitivesPaymentRecordsResourceAmount>,
46    amount_authorized: Option<stripe_shared::PaymentsPrimitivesPaymentRecordsResourceAmount>,
47    amount_canceled: Option<stripe_shared::PaymentsPrimitivesPaymentRecordsResourceAmount>,
48    amount_failed: Option<stripe_shared::PaymentsPrimitivesPaymentRecordsResourceAmount>,
49    amount_guaranteed: Option<stripe_shared::PaymentsPrimitivesPaymentRecordsResourceAmount>,
50    amount_refunded: Option<stripe_shared::PaymentsPrimitivesPaymentRecordsResourceAmount>,
51    amount_requested: Option<stripe_shared::PaymentsPrimitivesPaymentRecordsResourceAmount>,
52    application: Option<Option<String>>,
53    created: Option<stripe_types::Timestamp>,
54    customer_details:
55        Option<Option<stripe_shared::PaymentsPrimitivesPaymentRecordsResourceCustomerDetails>>,
56    customer_presence: Option<Option<stripe_shared::PaymentRecordCustomerPresence>>,
57    description: Option<Option<String>>,
58    id: Option<stripe_shared::PaymentRecordId>,
59    latest_payment_attempt_record: Option<Option<String>>,
60    livemode: Option<bool>,
61    metadata: Option<std::collections::HashMap<String, String>>,
62    payment_method_details:
63        Option<Option<stripe_shared::PaymentsPrimitivesPaymentRecordsResourcePaymentMethodDetails>>,
64    processor_details:
65        Option<stripe_shared::PaymentsPrimitivesPaymentRecordsResourceProcessorDetails>,
66    shipping_details:
67        Option<Option<stripe_shared::PaymentsPrimitivesPaymentRecordsResourceShippingDetails>>,
68}
69
70#[allow(
71    unused_variables,
72    irrefutable_let_patterns,
73    clippy::let_unit_value,
74    clippy::match_single_binding,
75    clippy::single_match
76)]
77const _: () = {
78    use miniserde::de::{Map, Visitor};
79    use miniserde::json::Value;
80    use miniserde::{Deserialize, Result, make_place};
81    use stripe_types::miniserde_helpers::FromValueOpt;
82    use stripe_types::{MapBuilder, ObjectDeser};
83
84    make_place!(Place);
85
86    impl Deserialize for PaymentRecord {
87        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
88            Place::new(out)
89        }
90    }
91
92    struct Builder<'a> {
93        out: &'a mut Option<PaymentRecord>,
94        builder: PaymentRecordBuilder,
95    }
96
97    impl Visitor for Place<PaymentRecord> {
98        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
99            Ok(Box::new(Builder {
100                out: &mut self.out,
101                builder: PaymentRecordBuilder::deser_default(),
102            }))
103        }
104    }
105
106    impl MapBuilder for PaymentRecordBuilder {
107        type Out = PaymentRecord;
108        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
109            Ok(match k {
110                "amount" => Deserialize::begin(&mut self.amount),
111                "amount_authorized" => Deserialize::begin(&mut self.amount_authorized),
112                "amount_canceled" => Deserialize::begin(&mut self.amount_canceled),
113                "amount_failed" => Deserialize::begin(&mut self.amount_failed),
114                "amount_guaranteed" => Deserialize::begin(&mut self.amount_guaranteed),
115                "amount_refunded" => Deserialize::begin(&mut self.amount_refunded),
116                "amount_requested" => Deserialize::begin(&mut self.amount_requested),
117                "application" => Deserialize::begin(&mut self.application),
118                "created" => Deserialize::begin(&mut self.created),
119                "customer_details" => Deserialize::begin(&mut self.customer_details),
120                "customer_presence" => Deserialize::begin(&mut self.customer_presence),
121                "description" => Deserialize::begin(&mut self.description),
122                "id" => Deserialize::begin(&mut self.id),
123                "latest_payment_attempt_record" => {
124                    Deserialize::begin(&mut self.latest_payment_attempt_record)
125                }
126                "livemode" => Deserialize::begin(&mut self.livemode),
127                "metadata" => Deserialize::begin(&mut self.metadata),
128                "payment_method_details" => Deserialize::begin(&mut self.payment_method_details),
129                "processor_details" => Deserialize::begin(&mut self.processor_details),
130                "shipping_details" => Deserialize::begin(&mut self.shipping_details),
131                _ => <dyn Visitor>::ignore(),
132            })
133        }
134
135        fn deser_default() -> Self {
136            Self {
137                amount: Deserialize::default(),
138                amount_authorized: Deserialize::default(),
139                amount_canceled: Deserialize::default(),
140                amount_failed: Deserialize::default(),
141                amount_guaranteed: Deserialize::default(),
142                amount_refunded: Deserialize::default(),
143                amount_requested: Deserialize::default(),
144                application: Deserialize::default(),
145                created: Deserialize::default(),
146                customer_details: Deserialize::default(),
147                customer_presence: Deserialize::default(),
148                description: Deserialize::default(),
149                id: Deserialize::default(),
150                latest_payment_attempt_record: Deserialize::default(),
151                livemode: Deserialize::default(),
152                metadata: Deserialize::default(),
153                payment_method_details: Deserialize::default(),
154                processor_details: Deserialize::default(),
155                shipping_details: Deserialize::default(),
156            }
157        }
158
159        fn take_out(&mut self) -> Option<Self::Out> {
160            let (
161                Some(amount),
162                Some(amount_authorized),
163                Some(amount_canceled),
164                Some(amount_failed),
165                Some(amount_guaranteed),
166                Some(amount_refunded),
167                Some(amount_requested),
168                Some(application),
169                Some(created),
170                Some(customer_details),
171                Some(customer_presence),
172                Some(description),
173                Some(id),
174                Some(latest_payment_attempt_record),
175                Some(livemode),
176                Some(metadata),
177                Some(payment_method_details),
178                Some(processor_details),
179                Some(shipping_details),
180            ) = (
181                self.amount.take(),
182                self.amount_authorized.take(),
183                self.amount_canceled.take(),
184                self.amount_failed.take(),
185                self.amount_guaranteed.take(),
186                self.amount_refunded.take(),
187                self.amount_requested.take(),
188                self.application.take(),
189                self.created,
190                self.customer_details.take(),
191                self.customer_presence,
192                self.description.take(),
193                self.id.take(),
194                self.latest_payment_attempt_record.take(),
195                self.livemode,
196                self.metadata.take(),
197                self.payment_method_details.take(),
198                self.processor_details.take(),
199                self.shipping_details.take(),
200            )
201            else {
202                return None;
203            };
204            Some(Self::Out {
205                amount,
206                amount_authorized,
207                amount_canceled,
208                amount_failed,
209                amount_guaranteed,
210                amount_refunded,
211                amount_requested,
212                application,
213                created,
214                customer_details,
215                customer_presence,
216                description,
217                id,
218                latest_payment_attempt_record,
219                livemode,
220                metadata,
221                payment_method_details,
222                processor_details,
223                shipping_details,
224            })
225        }
226    }
227
228    impl Map for Builder<'_> {
229        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
230            self.builder.key(k)
231        }
232
233        fn finish(&mut self) -> Result<()> {
234            *self.out = self.builder.take_out();
235            Ok(())
236        }
237    }
238
239    impl ObjectDeser for PaymentRecord {
240        type Builder = PaymentRecordBuilder;
241    }
242
243    impl FromValueOpt for PaymentRecord {
244        fn from_value(v: Value) -> Option<Self> {
245            let Value::Object(obj) = v else {
246                return None;
247            };
248            let mut b = PaymentRecordBuilder::deser_default();
249            for (k, v) in obj {
250                match k.as_str() {
251                    "amount" => b.amount = FromValueOpt::from_value(v),
252                    "amount_authorized" => b.amount_authorized = FromValueOpt::from_value(v),
253                    "amount_canceled" => b.amount_canceled = FromValueOpt::from_value(v),
254                    "amount_failed" => b.amount_failed = FromValueOpt::from_value(v),
255                    "amount_guaranteed" => b.amount_guaranteed = FromValueOpt::from_value(v),
256                    "amount_refunded" => b.amount_refunded = FromValueOpt::from_value(v),
257                    "amount_requested" => b.amount_requested = FromValueOpt::from_value(v),
258                    "application" => b.application = FromValueOpt::from_value(v),
259                    "created" => b.created = FromValueOpt::from_value(v),
260                    "customer_details" => b.customer_details = FromValueOpt::from_value(v),
261                    "customer_presence" => b.customer_presence = FromValueOpt::from_value(v),
262                    "description" => b.description = FromValueOpt::from_value(v),
263                    "id" => b.id = FromValueOpt::from_value(v),
264                    "latest_payment_attempt_record" => {
265                        b.latest_payment_attempt_record = FromValueOpt::from_value(v)
266                    }
267                    "livemode" => b.livemode = FromValueOpt::from_value(v),
268                    "metadata" => b.metadata = FromValueOpt::from_value(v),
269                    "payment_method_details" => {
270                        b.payment_method_details = FromValueOpt::from_value(v)
271                    }
272                    "processor_details" => b.processor_details = FromValueOpt::from_value(v),
273                    "shipping_details" => b.shipping_details = FromValueOpt::from_value(v),
274                    _ => {}
275                }
276            }
277            b.take_out()
278        }
279    }
280};
281#[cfg(feature = "serialize")]
282impl serde::Serialize for PaymentRecord {
283    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
284        use serde::ser::SerializeStruct;
285        let mut s = s.serialize_struct("PaymentRecord", 20)?;
286        s.serialize_field("amount", &self.amount)?;
287        s.serialize_field("amount_authorized", &self.amount_authorized)?;
288        s.serialize_field("amount_canceled", &self.amount_canceled)?;
289        s.serialize_field("amount_failed", &self.amount_failed)?;
290        s.serialize_field("amount_guaranteed", &self.amount_guaranteed)?;
291        s.serialize_field("amount_refunded", &self.amount_refunded)?;
292        s.serialize_field("amount_requested", &self.amount_requested)?;
293        s.serialize_field("application", &self.application)?;
294        s.serialize_field("created", &self.created)?;
295        s.serialize_field("customer_details", &self.customer_details)?;
296        s.serialize_field("customer_presence", &self.customer_presence)?;
297        s.serialize_field("description", &self.description)?;
298        s.serialize_field("id", &self.id)?;
299        s.serialize_field("latest_payment_attempt_record", &self.latest_payment_attempt_record)?;
300        s.serialize_field("livemode", &self.livemode)?;
301        s.serialize_field("metadata", &self.metadata)?;
302        s.serialize_field("payment_method_details", &self.payment_method_details)?;
303        s.serialize_field("processor_details", &self.processor_details)?;
304        s.serialize_field("shipping_details", &self.shipping_details)?;
305
306        s.serialize_field("object", "payment_record")?;
307        s.end()
308    }
309}
310impl stripe_types::Object for PaymentRecord {
311    type Id = stripe_shared::PaymentRecordId;
312    fn id(&self) -> &Self::Id {
313        &self.id
314    }
315
316    fn into_id(self) -> Self::Id {
317        self.id
318    }
319}
320stripe_types::def_id!(PaymentRecordId);
321#[derive(Copy, Clone, Eq, PartialEq)]
322pub enum PaymentRecordCustomerPresence {
323    OffSession,
324    OnSession,
325}
326impl PaymentRecordCustomerPresence {
327    pub fn as_str(self) -> &'static str {
328        use PaymentRecordCustomerPresence::*;
329        match self {
330            OffSession => "off_session",
331            OnSession => "on_session",
332        }
333    }
334}
335
336impl std::str::FromStr for PaymentRecordCustomerPresence {
337    type Err = stripe_types::StripeParseError;
338    fn from_str(s: &str) -> Result<Self, Self::Err> {
339        use PaymentRecordCustomerPresence::*;
340        match s {
341            "off_session" => Ok(OffSession),
342            "on_session" => Ok(OnSession),
343            _ => Err(stripe_types::StripeParseError),
344        }
345    }
346}
347impl std::fmt::Display for PaymentRecordCustomerPresence {
348    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
349        f.write_str(self.as_str())
350    }
351}
352
353impl std::fmt::Debug for PaymentRecordCustomerPresence {
354    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
355        f.write_str(self.as_str())
356    }
357}
358impl serde::Serialize for PaymentRecordCustomerPresence {
359    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
360    where
361        S: serde::Serializer,
362    {
363        serializer.serialize_str(self.as_str())
364    }
365}
366impl miniserde::Deserialize for PaymentRecordCustomerPresence {
367    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
368        crate::Place::new(out)
369    }
370}
371
372impl miniserde::de::Visitor for crate::Place<PaymentRecordCustomerPresence> {
373    fn string(&mut self, s: &str) -> miniserde::Result<()> {
374        use std::str::FromStr;
375        self.out = Some(PaymentRecordCustomerPresence::from_str(s).map_err(|_| miniserde::Error)?);
376        Ok(())
377    }
378}
379
380stripe_types::impl_from_val_with_from_str!(PaymentRecordCustomerPresence);
381#[cfg(feature = "deserialize")]
382impl<'de> serde::Deserialize<'de> for PaymentRecordCustomerPresence {
383    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
384        use std::str::FromStr;
385        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
386        Self::from_str(&s).map_err(|_| {
387            serde::de::Error::custom("Unknown value for PaymentRecordCustomerPresence")
388        })
389    }
390}