Skip to main content

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)]
6#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
7#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
8pub struct PaymentRecord {
9    pub amount: stripe_shared::PaymentsPrimitivesPaymentRecordsResourceAmount,
10    pub amount_authorized: stripe_shared::PaymentsPrimitivesPaymentRecordsResourceAmount,
11    pub amount_canceled: stripe_shared::PaymentsPrimitivesPaymentRecordsResourceAmount,
12    pub amount_failed: stripe_shared::PaymentsPrimitivesPaymentRecordsResourceAmount,
13    pub amount_guaranteed: stripe_shared::PaymentsPrimitivesPaymentRecordsResourceAmount,
14    pub amount_refunded: stripe_shared::PaymentsPrimitivesPaymentRecordsResourceAmount,
15    pub amount_requested: stripe_shared::PaymentsPrimitivesPaymentRecordsResourceAmount,
16    /// ID of the Connect application that created the PaymentRecord.
17    pub application: Option<String>,
18    /// Time at which the object was created. Measured in seconds since the Unix epoch.
19    pub created: stripe_types::Timestamp,
20    /// Customer information for this payment.
21    pub customer_details:
22        Option<stripe_shared::PaymentsPrimitivesPaymentRecordsResourceCustomerDetails>,
23    /// Indicates whether the customer was present in your checkout flow during this payment.
24    pub customer_presence: Option<stripe_shared::PaymentRecordCustomerPresence>,
25    /// An arbitrary string attached to the object. Often useful for displaying to users.
26    pub description: Option<String>,
27    /// Unique identifier for the object.
28    pub id: stripe_shared::PaymentRecordId,
29    /// ID of the latest Payment Attempt Record attached to this Payment Record.
30    pub latest_payment_attempt_record: Option<String>,
31    /// If the object exists in live mode, the value is `true`.
32    /// If the object exists in test mode, the value is `false`.
33    pub livemode: bool,
34    /// Set of [key-value pairs](https://docs.stripe.com/api/metadata) that you can attach to an object.
35    /// This can be useful for storing additional information about the object in a structured format.
36    pub metadata: std::collections::HashMap<String, String>,
37    /// Information about the Payment Method debited for this payment.
38    pub payment_method_details:
39        Option<stripe_shared::PaymentsPrimitivesPaymentRecordsResourcePaymentMethodDetails>,
40    pub processor_details: stripe_shared::PaymentsPrimitivesPaymentRecordsResourceProcessorDetails,
41    /// Indicates who reported the payment.
42    pub reported_by: PaymentRecordReportedBy,
43    /// Shipping information for this payment.
44    pub shipping_details:
45        Option<stripe_shared::PaymentsPrimitivesPaymentRecordsResourceShippingDetails>,
46}
47#[cfg(feature = "redact-generated-debug")]
48impl std::fmt::Debug for PaymentRecord {
49    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
50        f.debug_struct("PaymentRecord").finish_non_exhaustive()
51    }
52}
53#[doc(hidden)]
54pub struct PaymentRecordBuilder {
55    amount: Option<stripe_shared::PaymentsPrimitivesPaymentRecordsResourceAmount>,
56    amount_authorized: Option<stripe_shared::PaymentsPrimitivesPaymentRecordsResourceAmount>,
57    amount_canceled: Option<stripe_shared::PaymentsPrimitivesPaymentRecordsResourceAmount>,
58    amount_failed: Option<stripe_shared::PaymentsPrimitivesPaymentRecordsResourceAmount>,
59    amount_guaranteed: Option<stripe_shared::PaymentsPrimitivesPaymentRecordsResourceAmount>,
60    amount_refunded: Option<stripe_shared::PaymentsPrimitivesPaymentRecordsResourceAmount>,
61    amount_requested: Option<stripe_shared::PaymentsPrimitivesPaymentRecordsResourceAmount>,
62    application: Option<Option<String>>,
63    created: Option<stripe_types::Timestamp>,
64    customer_details:
65        Option<Option<stripe_shared::PaymentsPrimitivesPaymentRecordsResourceCustomerDetails>>,
66    customer_presence: Option<Option<stripe_shared::PaymentRecordCustomerPresence>>,
67    description: Option<Option<String>>,
68    id: Option<stripe_shared::PaymentRecordId>,
69    latest_payment_attempt_record: Option<Option<String>>,
70    livemode: Option<bool>,
71    metadata: Option<std::collections::HashMap<String, String>>,
72    payment_method_details:
73        Option<Option<stripe_shared::PaymentsPrimitivesPaymentRecordsResourcePaymentMethodDetails>>,
74    processor_details:
75        Option<stripe_shared::PaymentsPrimitivesPaymentRecordsResourceProcessorDetails>,
76    reported_by: Option<PaymentRecordReportedBy>,
77    shipping_details:
78        Option<Option<stripe_shared::PaymentsPrimitivesPaymentRecordsResourceShippingDetails>>,
79}
80
81#[allow(
82    unused_variables,
83    irrefutable_let_patterns,
84    clippy::let_unit_value,
85    clippy::match_single_binding,
86    clippy::single_match
87)]
88const _: () = {
89    use miniserde::de::{Map, Visitor};
90    use miniserde::json::Value;
91    use miniserde::{Deserialize, Result, make_place};
92    use stripe_types::miniserde_helpers::FromValueOpt;
93    use stripe_types::{MapBuilder, ObjectDeser};
94
95    make_place!(Place);
96
97    impl Deserialize for PaymentRecord {
98        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
99            Place::new(out)
100        }
101    }
102
103    struct Builder<'a> {
104        out: &'a mut Option<PaymentRecord>,
105        builder: PaymentRecordBuilder,
106    }
107
108    impl Visitor for Place<PaymentRecord> {
109        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
110            Ok(Box::new(Builder {
111                out: &mut self.out,
112                builder: PaymentRecordBuilder::deser_default(),
113            }))
114        }
115    }
116
117    impl MapBuilder for PaymentRecordBuilder {
118        type Out = PaymentRecord;
119        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
120            Ok(match k {
121                "amount" => Deserialize::begin(&mut self.amount),
122                "amount_authorized" => Deserialize::begin(&mut self.amount_authorized),
123                "amount_canceled" => Deserialize::begin(&mut self.amount_canceled),
124                "amount_failed" => Deserialize::begin(&mut self.amount_failed),
125                "amount_guaranteed" => Deserialize::begin(&mut self.amount_guaranteed),
126                "amount_refunded" => Deserialize::begin(&mut self.amount_refunded),
127                "amount_requested" => Deserialize::begin(&mut self.amount_requested),
128                "application" => Deserialize::begin(&mut self.application),
129                "created" => Deserialize::begin(&mut self.created),
130                "customer_details" => Deserialize::begin(&mut self.customer_details),
131                "customer_presence" => Deserialize::begin(&mut self.customer_presence),
132                "description" => Deserialize::begin(&mut self.description),
133                "id" => Deserialize::begin(&mut self.id),
134                "latest_payment_attempt_record" => {
135                    Deserialize::begin(&mut self.latest_payment_attempt_record)
136                }
137                "livemode" => Deserialize::begin(&mut self.livemode),
138                "metadata" => Deserialize::begin(&mut self.metadata),
139                "payment_method_details" => Deserialize::begin(&mut self.payment_method_details),
140                "processor_details" => Deserialize::begin(&mut self.processor_details),
141                "reported_by" => Deserialize::begin(&mut self.reported_by),
142                "shipping_details" => Deserialize::begin(&mut self.shipping_details),
143                _ => <dyn Visitor>::ignore(),
144            })
145        }
146
147        fn deser_default() -> Self {
148            Self {
149                amount: None,
150                amount_authorized: None,
151                amount_canceled: None,
152                amount_failed: None,
153                amount_guaranteed: None,
154                amount_refunded: None,
155                amount_requested: None,
156                application: Some(None),
157                created: None,
158                customer_details: Some(None),
159                customer_presence: Some(None),
160                description: Some(None),
161                id: None,
162                latest_payment_attempt_record: Some(None),
163                livemode: None,
164                metadata: None,
165                payment_method_details: Some(None),
166                processor_details: None,
167                reported_by: None,
168                shipping_details: Some(None),
169            }
170        }
171
172        fn take_out(&mut self) -> Option<Self::Out> {
173            let (
174                Some(amount),
175                Some(amount_authorized),
176                Some(amount_canceled),
177                Some(amount_failed),
178                Some(amount_guaranteed),
179                Some(amount_refunded),
180                Some(amount_requested),
181                Some(application),
182                Some(created),
183                Some(customer_details),
184                Some(customer_presence),
185                Some(description),
186                Some(id),
187                Some(latest_payment_attempt_record),
188                Some(livemode),
189                Some(metadata),
190                Some(payment_method_details),
191                Some(processor_details),
192                Some(reported_by),
193                Some(shipping_details),
194            ) = (
195                self.amount.take(),
196                self.amount_authorized.take(),
197                self.amount_canceled.take(),
198                self.amount_failed.take(),
199                self.amount_guaranteed.take(),
200                self.amount_refunded.take(),
201                self.amount_requested.take(),
202                self.application.take(),
203                self.created,
204                self.customer_details.take(),
205                self.customer_presence.take(),
206                self.description.take(),
207                self.id.take(),
208                self.latest_payment_attempt_record.take(),
209                self.livemode,
210                self.metadata.take(),
211                self.payment_method_details.take(),
212                self.processor_details.take(),
213                self.reported_by.take(),
214                self.shipping_details.take(),
215            )
216            else {
217                return None;
218            };
219            Some(Self::Out {
220                amount,
221                amount_authorized,
222                amount_canceled,
223                amount_failed,
224                amount_guaranteed,
225                amount_refunded,
226                amount_requested,
227                application,
228                created,
229                customer_details,
230                customer_presence,
231                description,
232                id,
233                latest_payment_attempt_record,
234                livemode,
235                metadata,
236                payment_method_details,
237                processor_details,
238                reported_by,
239                shipping_details,
240            })
241        }
242    }
243
244    impl Map for Builder<'_> {
245        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
246            self.builder.key(k)
247        }
248
249        fn finish(&mut self) -> Result<()> {
250            *self.out = self.builder.take_out();
251            Ok(())
252        }
253    }
254
255    impl ObjectDeser for PaymentRecord {
256        type Builder = PaymentRecordBuilder;
257    }
258
259    impl FromValueOpt for PaymentRecord {
260        fn from_value(v: Value) -> Option<Self> {
261            let Value::Object(obj) = v else {
262                return None;
263            };
264            let mut b = PaymentRecordBuilder::deser_default();
265            for (k, v) in obj {
266                match k.as_str() {
267                    "amount" => b.amount = FromValueOpt::from_value(v),
268                    "amount_authorized" => b.amount_authorized = FromValueOpt::from_value(v),
269                    "amount_canceled" => b.amount_canceled = FromValueOpt::from_value(v),
270                    "amount_failed" => b.amount_failed = FromValueOpt::from_value(v),
271                    "amount_guaranteed" => b.amount_guaranteed = FromValueOpt::from_value(v),
272                    "amount_refunded" => b.amount_refunded = FromValueOpt::from_value(v),
273                    "amount_requested" => b.amount_requested = FromValueOpt::from_value(v),
274                    "application" => b.application = FromValueOpt::from_value(v),
275                    "created" => b.created = FromValueOpt::from_value(v),
276                    "customer_details" => b.customer_details = FromValueOpt::from_value(v),
277                    "customer_presence" => b.customer_presence = FromValueOpt::from_value(v),
278                    "description" => b.description = FromValueOpt::from_value(v),
279                    "id" => b.id = FromValueOpt::from_value(v),
280                    "latest_payment_attempt_record" => {
281                        b.latest_payment_attempt_record = FromValueOpt::from_value(v)
282                    }
283                    "livemode" => b.livemode = FromValueOpt::from_value(v),
284                    "metadata" => b.metadata = FromValueOpt::from_value(v),
285                    "payment_method_details" => {
286                        b.payment_method_details = FromValueOpt::from_value(v)
287                    }
288                    "processor_details" => b.processor_details = FromValueOpt::from_value(v),
289                    "reported_by" => b.reported_by = FromValueOpt::from_value(v),
290                    "shipping_details" => b.shipping_details = FromValueOpt::from_value(v),
291                    _ => {}
292                }
293            }
294            b.take_out()
295        }
296    }
297};
298#[cfg(feature = "serialize")]
299impl serde::Serialize for PaymentRecord {
300    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
301        use serde::ser::SerializeStruct;
302        let mut s = s.serialize_struct("PaymentRecord", 21)?;
303        s.serialize_field("amount", &self.amount)?;
304        s.serialize_field("amount_authorized", &self.amount_authorized)?;
305        s.serialize_field("amount_canceled", &self.amount_canceled)?;
306        s.serialize_field("amount_failed", &self.amount_failed)?;
307        s.serialize_field("amount_guaranteed", &self.amount_guaranteed)?;
308        s.serialize_field("amount_refunded", &self.amount_refunded)?;
309        s.serialize_field("amount_requested", &self.amount_requested)?;
310        s.serialize_field("application", &self.application)?;
311        s.serialize_field("created", &self.created)?;
312        s.serialize_field("customer_details", &self.customer_details)?;
313        s.serialize_field("customer_presence", &self.customer_presence)?;
314        s.serialize_field("description", &self.description)?;
315        s.serialize_field("id", &self.id)?;
316        s.serialize_field("latest_payment_attempt_record", &self.latest_payment_attempt_record)?;
317        s.serialize_field("livemode", &self.livemode)?;
318        s.serialize_field("metadata", &self.metadata)?;
319        s.serialize_field("payment_method_details", &self.payment_method_details)?;
320        s.serialize_field("processor_details", &self.processor_details)?;
321        s.serialize_field("reported_by", &self.reported_by)?;
322        s.serialize_field("shipping_details", &self.shipping_details)?;
323
324        s.serialize_field("object", "payment_record")?;
325        s.end()
326    }
327}
328/// Indicates who reported the payment.
329#[derive(Clone, Eq, PartialEq)]
330#[non_exhaustive]
331pub enum PaymentRecordReportedBy {
332    Self_,
333    Stripe,
334    /// An unrecognized value from Stripe. Should not be used as a request parameter.
335    Unknown(String),
336}
337impl PaymentRecordReportedBy {
338    pub fn as_str(&self) -> &str {
339        use PaymentRecordReportedBy::*;
340        match self {
341            Self_ => "self",
342            Stripe => "stripe",
343            Unknown(v) => v,
344        }
345    }
346}
347
348impl std::str::FromStr for PaymentRecordReportedBy {
349    type Err = std::convert::Infallible;
350    fn from_str(s: &str) -> Result<Self, Self::Err> {
351        use PaymentRecordReportedBy::*;
352        match s {
353            "self" => Ok(Self_),
354            "stripe" => Ok(Stripe),
355            v => {
356                tracing::warn!("Unknown value '{}' for enum '{}'", v, "PaymentRecordReportedBy");
357                Ok(Unknown(v.to_owned()))
358            }
359        }
360    }
361}
362impl std::fmt::Display for PaymentRecordReportedBy {
363    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
364        f.write_str(self.as_str())
365    }
366}
367
368#[cfg(not(feature = "redact-generated-debug"))]
369impl std::fmt::Debug for PaymentRecordReportedBy {
370    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
371        f.write_str(self.as_str())
372    }
373}
374#[cfg(feature = "redact-generated-debug")]
375impl std::fmt::Debug for PaymentRecordReportedBy {
376    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
377        f.debug_struct(stringify!(PaymentRecordReportedBy)).finish_non_exhaustive()
378    }
379}
380#[cfg(feature = "serialize")]
381impl serde::Serialize for PaymentRecordReportedBy {
382    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
383    where
384        S: serde::Serializer,
385    {
386        serializer.serialize_str(self.as_str())
387    }
388}
389impl miniserde::Deserialize for PaymentRecordReportedBy {
390    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
391        crate::Place::new(out)
392    }
393}
394
395impl miniserde::de::Visitor for crate::Place<PaymentRecordReportedBy> {
396    fn string(&mut self, s: &str) -> miniserde::Result<()> {
397        use std::str::FromStr;
398        self.out = Some(PaymentRecordReportedBy::from_str(s).expect("infallible"));
399        Ok(())
400    }
401}
402
403stripe_types::impl_from_val_with_from_str!(PaymentRecordReportedBy);
404#[cfg(feature = "deserialize")]
405impl<'de> serde::Deserialize<'de> for PaymentRecordReportedBy {
406    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
407        use std::str::FromStr;
408        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
409        Ok(Self::from_str(&s).expect("infallible"))
410    }
411}
412impl stripe_types::Object for PaymentRecord {
413    type Id = stripe_shared::PaymentRecordId;
414    fn id(&self) -> &Self::Id {
415        &self.id
416    }
417
418    fn into_id(self) -> Self::Id {
419        self.id
420    }
421}
422stripe_types::def_id!(PaymentRecordId);
423#[derive(Clone, Eq, PartialEq)]
424#[non_exhaustive]
425pub enum PaymentRecordCustomerPresence {
426    OffSession,
427    OnSession,
428    /// An unrecognized value from Stripe. Should not be used as a request parameter.
429    Unknown(String),
430}
431impl PaymentRecordCustomerPresence {
432    pub fn as_str(&self) -> &str {
433        use PaymentRecordCustomerPresence::*;
434        match self {
435            OffSession => "off_session",
436            OnSession => "on_session",
437            Unknown(v) => v,
438        }
439    }
440}
441
442impl std::str::FromStr for PaymentRecordCustomerPresence {
443    type Err = std::convert::Infallible;
444    fn from_str(s: &str) -> Result<Self, Self::Err> {
445        use PaymentRecordCustomerPresence::*;
446        match s {
447            "off_session" => Ok(OffSession),
448            "on_session" => Ok(OnSession),
449            v => {
450                tracing::warn!(
451                    "Unknown value '{}' for enum '{}'",
452                    v,
453                    "PaymentRecordCustomerPresence"
454                );
455                Ok(Unknown(v.to_owned()))
456            }
457        }
458    }
459}
460impl std::fmt::Display for PaymentRecordCustomerPresence {
461    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
462        f.write_str(self.as_str())
463    }
464}
465
466#[cfg(not(feature = "redact-generated-debug"))]
467impl std::fmt::Debug for PaymentRecordCustomerPresence {
468    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
469        f.write_str(self.as_str())
470    }
471}
472#[cfg(feature = "redact-generated-debug")]
473impl std::fmt::Debug for PaymentRecordCustomerPresence {
474    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
475        f.debug_struct(stringify!(PaymentRecordCustomerPresence)).finish_non_exhaustive()
476    }
477}
478impl serde::Serialize for PaymentRecordCustomerPresence {
479    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
480    where
481        S: serde::Serializer,
482    {
483        serializer.serialize_str(self.as_str())
484    }
485}
486impl miniserde::Deserialize for PaymentRecordCustomerPresence {
487    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
488        crate::Place::new(out)
489    }
490}
491
492impl miniserde::de::Visitor for crate::Place<PaymentRecordCustomerPresence> {
493    fn string(&mut self, s: &str) -> miniserde::Result<()> {
494        use std::str::FromStr;
495        self.out = Some(PaymentRecordCustomerPresence::from_str(s).expect("infallible"));
496        Ok(())
497    }
498}
499
500stripe_types::impl_from_val_with_from_str!(PaymentRecordCustomerPresence);
501#[cfg(feature = "deserialize")]
502impl<'de> serde::Deserialize<'de> for PaymentRecordCustomerPresence {
503    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
504        use std::str::FromStr;
505        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
506        Ok(Self::from_str(&s).expect("infallible"))
507    }
508}