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