stripe_shared/
payment_intent.rs

1/// A PaymentIntent guides you through the process of collecting a payment from your customer.
2/// We recommend that you create exactly one PaymentIntent for each order or
3/// customer session in your system. You can reference the PaymentIntent later to
4/// see the history of payment attempts for a particular session.
5///
6/// A PaymentIntent transitions through
7/// [multiple statuses](https://stripe.com/docs/payments/intents#intent-statuses)
8/// throughout its lifetime as it interfaces with Stripe.js to perform
9/// authentication flows and ultimately creates at most one successful charge.
10///
11/// Related guide: [Payment Intents API](https://stripe.com/docs/payments/payment-intents)
12///
13/// For more details see <<https://stripe.com/docs/api/payment_intents/object>>.
14#[derive(Clone, Debug)]
15#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
16pub struct PaymentIntent {
17    /// Amount intended to be collected by this PaymentIntent.
18    /// A positive integer representing how much to charge in the [smallest currency unit](https://stripe.com/docs/currencies#zero-decimal) (e.g., 100 cents to charge $1.00 or 100 to charge ¥100, a zero-decimal currency).
19    /// The minimum amount is $0.50 US or [equivalent in charge currency](https://stripe.com/docs/currencies#minimum-and-maximum-charge-amounts).
20    /// The amount value supports up to eight digits (e.g., a value of 99999999 for a USD charge of $999,999.99).
21    pub amount: i64,
22    /// Amount that can be captured from this PaymentIntent.
23    pub amount_capturable: i64,
24    pub amount_details: Option<stripe_shared::PaymentFlowsAmountDetails>,
25    /// Amount that this PaymentIntent collects.
26    pub amount_received: i64,
27    /// ID of the Connect application that created the PaymentIntent.
28    pub application: Option<stripe_types::Expandable<stripe_shared::Application>>,
29    /// The amount of the application fee (if any) that will be requested to be applied to the payment and transferred to the application owner's Stripe account.
30    /// The amount of the application fee collected will be capped at the total amount captured.
31    /// For more information, see the PaymentIntents [use case for connected accounts](https://stripe.com/docs/payments/connected-accounts).
32    pub application_fee_amount: Option<i64>,
33    /// Settings to configure compatible payment methods from the [Stripe Dashboard](https://dashboard.stripe.com/settings/payment_methods).
34    pub automatic_payment_methods:
35        Option<stripe_shared::PaymentFlowsAutomaticPaymentMethodsPaymentIntent>,
36    /// Populated when `status` is `canceled`, this is the time at which the PaymentIntent was canceled.
37    /// Measured in seconds since the Unix epoch.
38    pub canceled_at: Option<stripe_types::Timestamp>,
39    /// Reason for cancellation of this PaymentIntent, either user-provided (`duplicate`, `fraudulent`, `requested_by_customer`, or `abandoned`) or generated by Stripe internally (`failed_invoice`, `void_invoice`, `automatic`, or `expired`).
40    pub cancellation_reason: Option<PaymentIntentCancellationReason>,
41    /// Controls when the funds will be captured from the customer's account.
42    pub capture_method: stripe_shared::PaymentIntentCaptureMethod,
43    /// The client secret of this PaymentIntent. Used for client-side retrieval using a publishable key.
44    ///
45    /// The client secret can be used to complete a payment from your frontend.
46    /// It should not be stored, logged, or exposed to anyone other than the customer.
47    /// Make sure that you have TLS enabled on any page that includes the client secret.
48    ///
49    /// Refer to our docs to [accept a payment](https://stripe.com/docs/payments/accept-a-payment?ui=elements) and learn about how `client_secret` should be handled.
50    pub client_secret: Option<String>,
51    /// Describes whether we can confirm this PaymentIntent automatically, or if it requires customer action to confirm the payment.
52    pub confirmation_method: stripe_shared::PaymentIntentConfirmationMethod,
53    /// Time at which the object was created. Measured in seconds since the Unix epoch.
54    pub created: stripe_types::Timestamp,
55    /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
56    /// Must be a [supported currency](https://stripe.com/docs/currencies).
57    pub currency: stripe_types::Currency,
58    /// ID of the Customer this PaymentIntent belongs to, if one exists.
59    ///
60    /// Payment methods attached to other Customers cannot be used with this PaymentIntent.
61    ///
62    /// If [setup_future_usage](https://stripe.com/docs/api#payment_intent_object-setup_future_usage) is set and this PaymentIntent's payment method is not `card_present`, then the payment method attaches to the Customer after the PaymentIntent has been confirmed and any required actions from the user are complete.
63    /// If the payment method is `card_present` and isn't a digital wallet, then a [generated_card](https://docs.stripe.com/api/charges/object#charge_object-payment_method_details-card_present-generated_card) payment method representing the card is created and attached to the Customer instead.
64    pub customer: Option<stripe_types::Expandable<stripe_shared::Customer>>,
65    /// An arbitrary string attached to the object. Often useful for displaying to users.
66    pub description: Option<String>,
67    /// Unique identifier for the object.
68    pub id: stripe_shared::PaymentIntentId,
69    /// The payment error encountered in the previous PaymentIntent confirmation.
70    /// It will be cleared if the PaymentIntent is later updated for any reason.
71    pub last_payment_error: Option<Box<stripe_shared::ApiErrors>>,
72    /// ID of the latest [Charge object](https://stripe.com/docs/api/charges) created by this PaymentIntent.
73    /// This property is `null` until PaymentIntent confirmation is attempted.
74    pub latest_charge: Option<stripe_types::Expandable<stripe_shared::Charge>>,
75    /// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
76    pub livemode: bool,
77    /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
78    /// This can be useful for storing additional information about the object in a structured format.
79    /// Learn more about [storing information in metadata](https://stripe.com/docs/payments/payment-intents/creating-payment-intents#storing-information-in-metadata).
80    pub metadata: std::collections::HashMap<String, String>,
81    /// If present, this property tells you what actions you need to take in order for your customer to fulfill a payment using the provided source.
82    pub next_action: Option<stripe_shared::PaymentIntentNextAction>,
83    /// The account (if any) for which the funds of the PaymentIntent are intended.
84    /// See the PaymentIntents [use case for connected accounts](https://stripe.com/docs/payments/connected-accounts) for details.
85    pub on_behalf_of: Option<stripe_types::Expandable<stripe_shared::Account>>,
86    /// ID of the payment method used in this PaymentIntent.
87    pub payment_method: Option<stripe_types::Expandable<stripe_shared::PaymentMethod>>,
88    /// Information about the [payment method configuration](https://stripe.com/docs/api/payment_method_configurations) used for this PaymentIntent.
89    pub payment_method_configuration_details:
90        Option<stripe_shared::PaymentMethodConfigBizPaymentMethodConfigurationDetails>,
91    /// Payment-method-specific configuration for this PaymentIntent.
92    pub payment_method_options: Option<stripe_shared::PaymentIntentPaymentMethodOptions>,
93    /// The list of payment method types (e.g.
94    /// card) that this PaymentIntent is allowed to use.
95    /// A comprehensive list of valid payment method types can be found [here](https://docs.stripe.com/api/payment_methods/object#payment_method_object-type).
96    pub payment_method_types: Vec<String>,
97    pub presentment_details: Option<stripe_shared::PaymentFlowsPaymentIntentPresentmentDetails>,
98    /// If present, this property tells you about the processing state of the payment.
99    pub processing: Option<stripe_shared::PaymentIntentProcessing>,
100    /// Email address that the receipt for the resulting payment will be sent to.
101    /// If `receipt_email` is specified for a payment in live mode, a receipt will be sent regardless of your [email settings](https://dashboard.stripe.com/account/emails).
102    pub receipt_email: Option<String>,
103    /// ID of the review associated with this PaymentIntent, if any.
104    pub review: Option<stripe_types::Expandable<stripe_shared::Review>>,
105    /// Indicates that you intend to make future payments with this PaymentIntent's payment method.
106    ///
107    /// If you provide a Customer with the PaymentIntent, you can use this parameter to [attach the payment method](/payments/save-during-payment) to the Customer after the PaymentIntent is confirmed and the customer completes any required actions.
108    /// If you don't provide a Customer, you can still [attach](/api/payment_methods/attach) the payment method to a Customer after the transaction completes.
109    ///
110    /// If the payment method is `card_present` and isn't a digital wallet, Stripe creates and attaches a [generated_card](/api/charges/object#charge_object-payment_method_details-card_present-generated_card) payment method representing the card to the Customer instead.
111    ///
112    /// When processing card payments, Stripe uses `setup_future_usage` to help you comply with regional legislation and network rules, such as [SCA](/strong-customer-authentication).
113    pub setup_future_usage: Option<stripe_shared::PaymentIntentSetupFutureUsage>,
114    /// Shipping information for this PaymentIntent.
115    pub shipping: Option<stripe_shared::Shipping>,
116    /// This is a legacy field that will be removed in the future.
117    /// It is the ID of the Source object that is associated with this PaymentIntent, if one was supplied.
118    pub source: Option<stripe_types::Expandable<stripe_shared::PaymentSource>>,
119    /// Text that appears on the customer's statement as the statement descriptor for a non-card charge.
120    /// This value overrides the account's default statement descriptor.
121    /// For information about requirements, including the 22-character limit, see [the Statement Descriptor docs](https://docs.stripe.com/get-started/account/statement-descriptors).
122    ///
123    /// Setting this value for a card charge returns an error.
124    /// For card charges, set the [statement_descriptor_suffix](https://docs.stripe.com/get-started/account/statement-descriptors#dynamic) instead.
125    pub statement_descriptor: Option<String>,
126    /// Provides information about a card charge.
127    /// Concatenated to the account's [statement descriptor prefix](https://docs.stripe.com/get-started/account/statement-descriptors#static) to form the complete statement descriptor that appears on the customer's statement.
128    pub statement_descriptor_suffix: Option<String>,
129    /// Status of this PaymentIntent, one of `requires_payment_method`, `requires_confirmation`, `requires_action`, `processing`, `requires_capture`, `canceled`, or `succeeded`.
130    /// Read more about each PaymentIntent [status](https://stripe.com/docs/payments/intents#intent-statuses).
131    pub status: PaymentIntentStatus,
132    /// The data that automatically creates a Transfer after the payment finalizes.
133    /// Learn more about the [use case for connected accounts](https://stripe.com/docs/payments/connected-accounts).
134    pub transfer_data: Option<stripe_shared::TransferData>,
135    /// A string that identifies the resulting payment as part of a group.
136    /// Learn more about the [use case for connected accounts](https://stripe.com/docs/connect/separate-charges-and-transfers).
137    pub transfer_group: Option<String>,
138}
139#[doc(hidden)]
140pub struct PaymentIntentBuilder {
141    amount: Option<i64>,
142    amount_capturable: Option<i64>,
143    amount_details: Option<Option<stripe_shared::PaymentFlowsAmountDetails>>,
144    amount_received: Option<i64>,
145    application: Option<Option<stripe_types::Expandable<stripe_shared::Application>>>,
146    application_fee_amount: Option<Option<i64>>,
147    automatic_payment_methods:
148        Option<Option<stripe_shared::PaymentFlowsAutomaticPaymentMethodsPaymentIntent>>,
149    canceled_at: Option<Option<stripe_types::Timestamp>>,
150    cancellation_reason: Option<Option<PaymentIntentCancellationReason>>,
151    capture_method: Option<stripe_shared::PaymentIntentCaptureMethod>,
152    client_secret: Option<Option<String>>,
153    confirmation_method: Option<stripe_shared::PaymentIntentConfirmationMethod>,
154    created: Option<stripe_types::Timestamp>,
155    currency: Option<stripe_types::Currency>,
156    customer: Option<Option<stripe_types::Expandable<stripe_shared::Customer>>>,
157    description: Option<Option<String>>,
158    id: Option<stripe_shared::PaymentIntentId>,
159    last_payment_error: Option<Option<Box<stripe_shared::ApiErrors>>>,
160    latest_charge: Option<Option<stripe_types::Expandable<stripe_shared::Charge>>>,
161    livemode: Option<bool>,
162    metadata: Option<std::collections::HashMap<String, String>>,
163    next_action: Option<Option<stripe_shared::PaymentIntentNextAction>>,
164    on_behalf_of: Option<Option<stripe_types::Expandable<stripe_shared::Account>>>,
165    payment_method: Option<Option<stripe_types::Expandable<stripe_shared::PaymentMethod>>>,
166    payment_method_configuration_details:
167        Option<Option<stripe_shared::PaymentMethodConfigBizPaymentMethodConfigurationDetails>>,
168    payment_method_options: Option<Option<stripe_shared::PaymentIntentPaymentMethodOptions>>,
169    payment_method_types: Option<Vec<String>>,
170    presentment_details: Option<Option<stripe_shared::PaymentFlowsPaymentIntentPresentmentDetails>>,
171    processing: Option<Option<stripe_shared::PaymentIntentProcessing>>,
172    receipt_email: Option<Option<String>>,
173    review: Option<Option<stripe_types::Expandable<stripe_shared::Review>>>,
174    setup_future_usage: Option<Option<stripe_shared::PaymentIntentSetupFutureUsage>>,
175    shipping: Option<Option<stripe_shared::Shipping>>,
176    source: Option<Option<stripe_types::Expandable<stripe_shared::PaymentSource>>>,
177    statement_descriptor: Option<Option<String>>,
178    statement_descriptor_suffix: Option<Option<String>>,
179    status: Option<PaymentIntentStatus>,
180    transfer_data: Option<Option<stripe_shared::TransferData>>,
181    transfer_group: Option<Option<String>>,
182}
183
184#[allow(
185    unused_variables,
186    irrefutable_let_patterns,
187    clippy::let_unit_value,
188    clippy::match_single_binding,
189    clippy::single_match
190)]
191const _: () = {
192    use miniserde::de::{Map, Visitor};
193    use miniserde::json::Value;
194    use miniserde::{make_place, Deserialize, Result};
195    use stripe_types::miniserde_helpers::FromValueOpt;
196    use stripe_types::{MapBuilder, ObjectDeser};
197
198    make_place!(Place);
199
200    impl Deserialize for PaymentIntent {
201        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
202            Place::new(out)
203        }
204    }
205
206    struct Builder<'a> {
207        out: &'a mut Option<PaymentIntent>,
208        builder: PaymentIntentBuilder,
209    }
210
211    impl Visitor for Place<PaymentIntent> {
212        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
213            Ok(Box::new(Builder {
214                out: &mut self.out,
215                builder: PaymentIntentBuilder::deser_default(),
216            }))
217        }
218    }
219
220    impl MapBuilder for PaymentIntentBuilder {
221        type Out = PaymentIntent;
222        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
223            Ok(match k {
224                "amount" => Deserialize::begin(&mut self.amount),
225                "amount_capturable" => Deserialize::begin(&mut self.amount_capturable),
226                "amount_details" => Deserialize::begin(&mut self.amount_details),
227                "amount_received" => Deserialize::begin(&mut self.amount_received),
228                "application" => Deserialize::begin(&mut self.application),
229                "application_fee_amount" => Deserialize::begin(&mut self.application_fee_amount),
230                "automatic_payment_methods" => {
231                    Deserialize::begin(&mut self.automatic_payment_methods)
232                }
233                "canceled_at" => Deserialize::begin(&mut self.canceled_at),
234                "cancellation_reason" => Deserialize::begin(&mut self.cancellation_reason),
235                "capture_method" => Deserialize::begin(&mut self.capture_method),
236                "client_secret" => Deserialize::begin(&mut self.client_secret),
237                "confirmation_method" => Deserialize::begin(&mut self.confirmation_method),
238                "created" => Deserialize::begin(&mut self.created),
239                "currency" => Deserialize::begin(&mut self.currency),
240                "customer" => Deserialize::begin(&mut self.customer),
241                "description" => Deserialize::begin(&mut self.description),
242                "id" => Deserialize::begin(&mut self.id),
243                "last_payment_error" => Deserialize::begin(&mut self.last_payment_error),
244                "latest_charge" => Deserialize::begin(&mut self.latest_charge),
245                "livemode" => Deserialize::begin(&mut self.livemode),
246                "metadata" => Deserialize::begin(&mut self.metadata),
247                "next_action" => Deserialize::begin(&mut self.next_action),
248                "on_behalf_of" => Deserialize::begin(&mut self.on_behalf_of),
249                "payment_method" => Deserialize::begin(&mut self.payment_method),
250                "payment_method_configuration_details" => {
251                    Deserialize::begin(&mut self.payment_method_configuration_details)
252                }
253                "payment_method_options" => Deserialize::begin(&mut self.payment_method_options),
254                "payment_method_types" => Deserialize::begin(&mut self.payment_method_types),
255                "presentment_details" => Deserialize::begin(&mut self.presentment_details),
256                "processing" => Deserialize::begin(&mut self.processing),
257                "receipt_email" => Deserialize::begin(&mut self.receipt_email),
258                "review" => Deserialize::begin(&mut self.review),
259                "setup_future_usage" => Deserialize::begin(&mut self.setup_future_usage),
260                "shipping" => Deserialize::begin(&mut self.shipping),
261                "source" => Deserialize::begin(&mut self.source),
262                "statement_descriptor" => Deserialize::begin(&mut self.statement_descriptor),
263                "statement_descriptor_suffix" => {
264                    Deserialize::begin(&mut self.statement_descriptor_suffix)
265                }
266                "status" => Deserialize::begin(&mut self.status),
267                "transfer_data" => Deserialize::begin(&mut self.transfer_data),
268                "transfer_group" => Deserialize::begin(&mut self.transfer_group),
269
270                _ => <dyn Visitor>::ignore(),
271            })
272        }
273
274        fn deser_default() -> Self {
275            Self {
276                amount: Deserialize::default(),
277                amount_capturable: Deserialize::default(),
278                amount_details: Deserialize::default(),
279                amount_received: Deserialize::default(),
280                application: Deserialize::default(),
281                application_fee_amount: Deserialize::default(),
282                automatic_payment_methods: Deserialize::default(),
283                canceled_at: Deserialize::default(),
284                cancellation_reason: Deserialize::default(),
285                capture_method: Deserialize::default(),
286                client_secret: Deserialize::default(),
287                confirmation_method: Deserialize::default(),
288                created: Deserialize::default(),
289                currency: Deserialize::default(),
290                customer: Deserialize::default(),
291                description: Deserialize::default(),
292                id: Deserialize::default(),
293                last_payment_error: Deserialize::default(),
294                latest_charge: Deserialize::default(),
295                livemode: Deserialize::default(),
296                metadata: Deserialize::default(),
297                next_action: Deserialize::default(),
298                on_behalf_of: Deserialize::default(),
299                payment_method: Deserialize::default(),
300                payment_method_configuration_details: Deserialize::default(),
301                payment_method_options: Deserialize::default(),
302                payment_method_types: Deserialize::default(),
303                presentment_details: Deserialize::default(),
304                processing: Deserialize::default(),
305                receipt_email: Deserialize::default(),
306                review: Deserialize::default(),
307                setup_future_usage: Deserialize::default(),
308                shipping: Deserialize::default(),
309                source: Deserialize::default(),
310                statement_descriptor: Deserialize::default(),
311                statement_descriptor_suffix: Deserialize::default(),
312                status: Deserialize::default(),
313                transfer_data: Deserialize::default(),
314                transfer_group: Deserialize::default(),
315            }
316        }
317
318        fn take_out(&mut self) -> Option<Self::Out> {
319            let (
320                Some(amount),
321                Some(amount_capturable),
322                Some(amount_details),
323                Some(amount_received),
324                Some(application),
325                Some(application_fee_amount),
326                Some(automatic_payment_methods),
327                Some(canceled_at),
328                Some(cancellation_reason),
329                Some(capture_method),
330                Some(client_secret),
331                Some(confirmation_method),
332                Some(created),
333                Some(currency),
334                Some(customer),
335                Some(description),
336                Some(id),
337                Some(last_payment_error),
338                Some(latest_charge),
339                Some(livemode),
340                Some(metadata),
341                Some(next_action),
342                Some(on_behalf_of),
343                Some(payment_method),
344                Some(payment_method_configuration_details),
345                Some(payment_method_options),
346                Some(payment_method_types),
347                Some(presentment_details),
348                Some(processing),
349                Some(receipt_email),
350                Some(review),
351                Some(setup_future_usage),
352                Some(shipping),
353                Some(source),
354                Some(statement_descriptor),
355                Some(statement_descriptor_suffix),
356                Some(status),
357                Some(transfer_data),
358                Some(transfer_group),
359            ) = (
360                self.amount,
361                self.amount_capturable,
362                self.amount_details,
363                self.amount_received,
364                self.application.take(),
365                self.application_fee_amount,
366                self.automatic_payment_methods,
367                self.canceled_at,
368                self.cancellation_reason,
369                self.capture_method,
370                self.client_secret.take(),
371                self.confirmation_method,
372                self.created,
373                self.currency,
374                self.customer.take(),
375                self.description.take(),
376                self.id.take(),
377                self.last_payment_error.take(),
378                self.latest_charge.take(),
379                self.livemode,
380                self.metadata.take(),
381                self.next_action.take(),
382                self.on_behalf_of.take(),
383                self.payment_method.take(),
384                self.payment_method_configuration_details.take(),
385                self.payment_method_options.take(),
386                self.payment_method_types.take(),
387                self.presentment_details,
388                self.processing,
389                self.receipt_email.take(),
390                self.review.take(),
391                self.setup_future_usage,
392                self.shipping.take(),
393                self.source.take(),
394                self.statement_descriptor.take(),
395                self.statement_descriptor_suffix.take(),
396                self.status,
397                self.transfer_data.take(),
398                self.transfer_group.take(),
399            )
400            else {
401                return None;
402            };
403            Some(Self::Out {
404                amount,
405                amount_capturable,
406                amount_details,
407                amount_received,
408                application,
409                application_fee_amount,
410                automatic_payment_methods,
411                canceled_at,
412                cancellation_reason,
413                capture_method,
414                client_secret,
415                confirmation_method,
416                created,
417                currency,
418                customer,
419                description,
420                id,
421                last_payment_error,
422                latest_charge,
423                livemode,
424                metadata,
425                next_action,
426                on_behalf_of,
427                payment_method,
428                payment_method_configuration_details,
429                payment_method_options,
430                payment_method_types,
431                presentment_details,
432                processing,
433                receipt_email,
434                review,
435                setup_future_usage,
436                shipping,
437                source,
438                statement_descriptor,
439                statement_descriptor_suffix,
440                status,
441                transfer_data,
442                transfer_group,
443            })
444        }
445    }
446
447    impl<'a> Map for Builder<'a> {
448        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
449            self.builder.key(k)
450        }
451
452        fn finish(&mut self) -> Result<()> {
453            *self.out = self.builder.take_out();
454            Ok(())
455        }
456    }
457
458    impl ObjectDeser for PaymentIntent {
459        type Builder = PaymentIntentBuilder;
460    }
461
462    impl FromValueOpt for PaymentIntent {
463        fn from_value(v: Value) -> Option<Self> {
464            let Value::Object(obj) = v else {
465                return None;
466            };
467            let mut b = PaymentIntentBuilder::deser_default();
468            for (k, v) in obj {
469                match k.as_str() {
470                    "amount" => b.amount = FromValueOpt::from_value(v),
471                    "amount_capturable" => b.amount_capturable = FromValueOpt::from_value(v),
472                    "amount_details" => b.amount_details = FromValueOpt::from_value(v),
473                    "amount_received" => b.amount_received = FromValueOpt::from_value(v),
474                    "application" => b.application = FromValueOpt::from_value(v),
475                    "application_fee_amount" => {
476                        b.application_fee_amount = FromValueOpt::from_value(v)
477                    }
478                    "automatic_payment_methods" => {
479                        b.automatic_payment_methods = FromValueOpt::from_value(v)
480                    }
481                    "canceled_at" => b.canceled_at = FromValueOpt::from_value(v),
482                    "cancellation_reason" => b.cancellation_reason = FromValueOpt::from_value(v),
483                    "capture_method" => b.capture_method = FromValueOpt::from_value(v),
484                    "client_secret" => b.client_secret = FromValueOpt::from_value(v),
485                    "confirmation_method" => b.confirmation_method = FromValueOpt::from_value(v),
486                    "created" => b.created = FromValueOpt::from_value(v),
487                    "currency" => b.currency = FromValueOpt::from_value(v),
488                    "customer" => b.customer = FromValueOpt::from_value(v),
489                    "description" => b.description = FromValueOpt::from_value(v),
490                    "id" => b.id = FromValueOpt::from_value(v),
491                    "last_payment_error" => b.last_payment_error = FromValueOpt::from_value(v),
492                    "latest_charge" => b.latest_charge = FromValueOpt::from_value(v),
493                    "livemode" => b.livemode = FromValueOpt::from_value(v),
494                    "metadata" => b.metadata = FromValueOpt::from_value(v),
495                    "next_action" => b.next_action = FromValueOpt::from_value(v),
496                    "on_behalf_of" => b.on_behalf_of = FromValueOpt::from_value(v),
497                    "payment_method" => b.payment_method = FromValueOpt::from_value(v),
498                    "payment_method_configuration_details" => {
499                        b.payment_method_configuration_details = FromValueOpt::from_value(v)
500                    }
501                    "payment_method_options" => {
502                        b.payment_method_options = FromValueOpt::from_value(v)
503                    }
504                    "payment_method_types" => b.payment_method_types = FromValueOpt::from_value(v),
505                    "presentment_details" => b.presentment_details = FromValueOpt::from_value(v),
506                    "processing" => b.processing = FromValueOpt::from_value(v),
507                    "receipt_email" => b.receipt_email = FromValueOpt::from_value(v),
508                    "review" => b.review = FromValueOpt::from_value(v),
509                    "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
510                    "shipping" => b.shipping = FromValueOpt::from_value(v),
511                    "source" => b.source = FromValueOpt::from_value(v),
512                    "statement_descriptor" => b.statement_descriptor = FromValueOpt::from_value(v),
513                    "statement_descriptor_suffix" => {
514                        b.statement_descriptor_suffix = FromValueOpt::from_value(v)
515                    }
516                    "status" => b.status = FromValueOpt::from_value(v),
517                    "transfer_data" => b.transfer_data = FromValueOpt::from_value(v),
518                    "transfer_group" => b.transfer_group = FromValueOpt::from_value(v),
519
520                    _ => {}
521                }
522            }
523            b.take_out()
524        }
525    }
526};
527#[cfg(feature = "serialize")]
528impl serde::Serialize for PaymentIntent {
529    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
530        use serde::ser::SerializeStruct;
531        let mut s = s.serialize_struct("PaymentIntent", 40)?;
532        s.serialize_field("amount", &self.amount)?;
533        s.serialize_field("amount_capturable", &self.amount_capturable)?;
534        s.serialize_field("amount_details", &self.amount_details)?;
535        s.serialize_field("amount_received", &self.amount_received)?;
536        s.serialize_field("application", &self.application)?;
537        s.serialize_field("application_fee_amount", &self.application_fee_amount)?;
538        s.serialize_field("automatic_payment_methods", &self.automatic_payment_methods)?;
539        s.serialize_field("canceled_at", &self.canceled_at)?;
540        s.serialize_field("cancellation_reason", &self.cancellation_reason)?;
541        s.serialize_field("capture_method", &self.capture_method)?;
542        s.serialize_field("client_secret", &self.client_secret)?;
543        s.serialize_field("confirmation_method", &self.confirmation_method)?;
544        s.serialize_field("created", &self.created)?;
545        s.serialize_field("currency", &self.currency)?;
546        s.serialize_field("customer", &self.customer)?;
547        s.serialize_field("description", &self.description)?;
548        s.serialize_field("id", &self.id)?;
549        s.serialize_field("last_payment_error", &self.last_payment_error)?;
550        s.serialize_field("latest_charge", &self.latest_charge)?;
551        s.serialize_field("livemode", &self.livemode)?;
552        s.serialize_field("metadata", &self.metadata)?;
553        s.serialize_field("next_action", &self.next_action)?;
554        s.serialize_field("on_behalf_of", &self.on_behalf_of)?;
555        s.serialize_field("payment_method", &self.payment_method)?;
556        s.serialize_field(
557            "payment_method_configuration_details",
558            &self.payment_method_configuration_details,
559        )?;
560        s.serialize_field("payment_method_options", &self.payment_method_options)?;
561        s.serialize_field("payment_method_types", &self.payment_method_types)?;
562        s.serialize_field("presentment_details", &self.presentment_details)?;
563        s.serialize_field("processing", &self.processing)?;
564        s.serialize_field("receipt_email", &self.receipt_email)?;
565        s.serialize_field("review", &self.review)?;
566        s.serialize_field("setup_future_usage", &self.setup_future_usage)?;
567        s.serialize_field("shipping", &self.shipping)?;
568        s.serialize_field("source", &self.source)?;
569        s.serialize_field("statement_descriptor", &self.statement_descriptor)?;
570        s.serialize_field("statement_descriptor_suffix", &self.statement_descriptor_suffix)?;
571        s.serialize_field("status", &self.status)?;
572        s.serialize_field("transfer_data", &self.transfer_data)?;
573        s.serialize_field("transfer_group", &self.transfer_group)?;
574
575        s.serialize_field("object", "payment_intent")?;
576        s.end()
577    }
578}
579/// Reason for cancellation of this PaymentIntent, either user-provided (`duplicate`, `fraudulent`, `requested_by_customer`, or `abandoned`) or generated by Stripe internally (`failed_invoice`, `void_invoice`, `automatic`, or `expired`).
580#[derive(Copy, Clone, Eq, PartialEq)]
581pub enum PaymentIntentCancellationReason {
582    Abandoned,
583    Automatic,
584    Duplicate,
585    Expired,
586    FailedInvoice,
587    Fraudulent,
588    RequestedByCustomer,
589    VoidInvoice,
590}
591impl PaymentIntentCancellationReason {
592    pub fn as_str(self) -> &'static str {
593        use PaymentIntentCancellationReason::*;
594        match self {
595            Abandoned => "abandoned",
596            Automatic => "automatic",
597            Duplicate => "duplicate",
598            Expired => "expired",
599            FailedInvoice => "failed_invoice",
600            Fraudulent => "fraudulent",
601            RequestedByCustomer => "requested_by_customer",
602            VoidInvoice => "void_invoice",
603        }
604    }
605}
606
607impl std::str::FromStr for PaymentIntentCancellationReason {
608    type Err = stripe_types::StripeParseError;
609    fn from_str(s: &str) -> Result<Self, Self::Err> {
610        use PaymentIntentCancellationReason::*;
611        match s {
612            "abandoned" => Ok(Abandoned),
613            "automatic" => Ok(Automatic),
614            "duplicate" => Ok(Duplicate),
615            "expired" => Ok(Expired),
616            "failed_invoice" => Ok(FailedInvoice),
617            "fraudulent" => Ok(Fraudulent),
618            "requested_by_customer" => Ok(RequestedByCustomer),
619            "void_invoice" => Ok(VoidInvoice),
620            _ => Err(stripe_types::StripeParseError),
621        }
622    }
623}
624impl std::fmt::Display for PaymentIntentCancellationReason {
625    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
626        f.write_str(self.as_str())
627    }
628}
629
630impl std::fmt::Debug for PaymentIntentCancellationReason {
631    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
632        f.write_str(self.as_str())
633    }
634}
635#[cfg(feature = "serialize")]
636impl serde::Serialize for PaymentIntentCancellationReason {
637    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
638    where
639        S: serde::Serializer,
640    {
641        serializer.serialize_str(self.as_str())
642    }
643}
644impl miniserde::Deserialize for PaymentIntentCancellationReason {
645    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
646        crate::Place::new(out)
647    }
648}
649
650impl miniserde::de::Visitor for crate::Place<PaymentIntentCancellationReason> {
651    fn string(&mut self, s: &str) -> miniserde::Result<()> {
652        use std::str::FromStr;
653        self.out =
654            Some(PaymentIntentCancellationReason::from_str(s).map_err(|_| miniserde::Error)?);
655        Ok(())
656    }
657}
658
659stripe_types::impl_from_val_with_from_str!(PaymentIntentCancellationReason);
660#[cfg(feature = "deserialize")]
661impl<'de> serde::Deserialize<'de> for PaymentIntentCancellationReason {
662    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
663        use std::str::FromStr;
664        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
665        Self::from_str(&s).map_err(|_| {
666            serde::de::Error::custom("Unknown value for PaymentIntentCancellationReason")
667        })
668    }
669}
670/// Status of this PaymentIntent, one of `requires_payment_method`, `requires_confirmation`, `requires_action`, `processing`, `requires_capture`, `canceled`, or `succeeded`.
671/// Read more about each PaymentIntent [status](https://stripe.com/docs/payments/intents#intent-statuses).
672#[derive(Copy, Clone, Eq, PartialEq)]
673pub enum PaymentIntentStatus {
674    Canceled,
675    Processing,
676    RequiresAction,
677    RequiresCapture,
678    RequiresConfirmation,
679    RequiresPaymentMethod,
680    Succeeded,
681}
682impl PaymentIntentStatus {
683    pub fn as_str(self) -> &'static str {
684        use PaymentIntentStatus::*;
685        match self {
686            Canceled => "canceled",
687            Processing => "processing",
688            RequiresAction => "requires_action",
689            RequiresCapture => "requires_capture",
690            RequiresConfirmation => "requires_confirmation",
691            RequiresPaymentMethod => "requires_payment_method",
692            Succeeded => "succeeded",
693        }
694    }
695}
696
697impl std::str::FromStr for PaymentIntentStatus {
698    type Err = stripe_types::StripeParseError;
699    fn from_str(s: &str) -> Result<Self, Self::Err> {
700        use PaymentIntentStatus::*;
701        match s {
702            "canceled" => Ok(Canceled),
703            "processing" => Ok(Processing),
704            "requires_action" => Ok(RequiresAction),
705            "requires_capture" => Ok(RequiresCapture),
706            "requires_confirmation" => Ok(RequiresConfirmation),
707            "requires_payment_method" => Ok(RequiresPaymentMethod),
708            "succeeded" => Ok(Succeeded),
709            _ => Err(stripe_types::StripeParseError),
710        }
711    }
712}
713impl std::fmt::Display for PaymentIntentStatus {
714    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
715        f.write_str(self.as_str())
716    }
717}
718
719impl std::fmt::Debug for PaymentIntentStatus {
720    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
721        f.write_str(self.as_str())
722    }
723}
724#[cfg(feature = "serialize")]
725impl serde::Serialize for PaymentIntentStatus {
726    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
727    where
728        S: serde::Serializer,
729    {
730        serializer.serialize_str(self.as_str())
731    }
732}
733impl miniserde::Deserialize for PaymentIntentStatus {
734    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
735        crate::Place::new(out)
736    }
737}
738
739impl miniserde::de::Visitor for crate::Place<PaymentIntentStatus> {
740    fn string(&mut self, s: &str) -> miniserde::Result<()> {
741        use std::str::FromStr;
742        self.out = Some(PaymentIntentStatus::from_str(s).map_err(|_| miniserde::Error)?);
743        Ok(())
744    }
745}
746
747stripe_types::impl_from_val_with_from_str!(PaymentIntentStatus);
748#[cfg(feature = "deserialize")]
749impl<'de> serde::Deserialize<'de> for PaymentIntentStatus {
750    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
751        use std::str::FromStr;
752        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
753        Self::from_str(&s)
754            .map_err(|_| serde::de::Error::custom("Unknown value for PaymentIntentStatus"))
755    }
756}
757impl stripe_types::Object for PaymentIntent {
758    type Id = stripe_shared::PaymentIntentId;
759    fn id(&self) -> &Self::Id {
760        &self.id
761    }
762
763    fn into_id(self) -> Self::Id {
764        self.id
765    }
766}
767stripe_types::def_id!(PaymentIntentId);
768#[derive(Copy, Clone, Eq, PartialEq)]
769pub enum PaymentIntentCaptureMethod {
770    Automatic,
771    AutomaticAsync,
772    Manual,
773}
774impl PaymentIntentCaptureMethod {
775    pub fn as_str(self) -> &'static str {
776        use PaymentIntentCaptureMethod::*;
777        match self {
778            Automatic => "automatic",
779            AutomaticAsync => "automatic_async",
780            Manual => "manual",
781        }
782    }
783}
784
785impl std::str::FromStr for PaymentIntentCaptureMethod {
786    type Err = stripe_types::StripeParseError;
787    fn from_str(s: &str) -> Result<Self, Self::Err> {
788        use PaymentIntentCaptureMethod::*;
789        match s {
790            "automatic" => Ok(Automatic),
791            "automatic_async" => Ok(AutomaticAsync),
792            "manual" => Ok(Manual),
793            _ => Err(stripe_types::StripeParseError),
794        }
795    }
796}
797impl std::fmt::Display for PaymentIntentCaptureMethod {
798    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
799        f.write_str(self.as_str())
800    }
801}
802
803impl std::fmt::Debug for PaymentIntentCaptureMethod {
804    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
805        f.write_str(self.as_str())
806    }
807}
808impl serde::Serialize for PaymentIntentCaptureMethod {
809    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
810    where
811        S: serde::Serializer,
812    {
813        serializer.serialize_str(self.as_str())
814    }
815}
816impl miniserde::Deserialize for PaymentIntentCaptureMethod {
817    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
818        crate::Place::new(out)
819    }
820}
821
822impl miniserde::de::Visitor for crate::Place<PaymentIntentCaptureMethod> {
823    fn string(&mut self, s: &str) -> miniserde::Result<()> {
824        use std::str::FromStr;
825        self.out = Some(PaymentIntentCaptureMethod::from_str(s).map_err(|_| miniserde::Error)?);
826        Ok(())
827    }
828}
829
830stripe_types::impl_from_val_with_from_str!(PaymentIntentCaptureMethod);
831#[cfg(feature = "deserialize")]
832impl<'de> serde::Deserialize<'de> for PaymentIntentCaptureMethod {
833    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
834        use std::str::FromStr;
835        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
836        Self::from_str(&s)
837            .map_err(|_| serde::de::Error::custom("Unknown value for PaymentIntentCaptureMethod"))
838    }
839}
840#[derive(Copy, Clone, Eq, PartialEq)]
841pub enum PaymentIntentConfirmationMethod {
842    Automatic,
843    Manual,
844}
845impl PaymentIntentConfirmationMethod {
846    pub fn as_str(self) -> &'static str {
847        use PaymentIntentConfirmationMethod::*;
848        match self {
849            Automatic => "automatic",
850            Manual => "manual",
851        }
852    }
853}
854
855impl std::str::FromStr for PaymentIntentConfirmationMethod {
856    type Err = stripe_types::StripeParseError;
857    fn from_str(s: &str) -> Result<Self, Self::Err> {
858        use PaymentIntentConfirmationMethod::*;
859        match s {
860            "automatic" => Ok(Automatic),
861            "manual" => Ok(Manual),
862            _ => Err(stripe_types::StripeParseError),
863        }
864    }
865}
866impl std::fmt::Display for PaymentIntentConfirmationMethod {
867    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
868        f.write_str(self.as_str())
869    }
870}
871
872impl std::fmt::Debug for PaymentIntentConfirmationMethod {
873    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
874        f.write_str(self.as_str())
875    }
876}
877impl serde::Serialize for PaymentIntentConfirmationMethod {
878    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
879    where
880        S: serde::Serializer,
881    {
882        serializer.serialize_str(self.as_str())
883    }
884}
885impl miniserde::Deserialize for PaymentIntentConfirmationMethod {
886    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
887        crate::Place::new(out)
888    }
889}
890
891impl miniserde::de::Visitor for crate::Place<PaymentIntentConfirmationMethod> {
892    fn string(&mut self, s: &str) -> miniserde::Result<()> {
893        use std::str::FromStr;
894        self.out =
895            Some(PaymentIntentConfirmationMethod::from_str(s).map_err(|_| miniserde::Error)?);
896        Ok(())
897    }
898}
899
900stripe_types::impl_from_val_with_from_str!(PaymentIntentConfirmationMethod);
901#[cfg(feature = "deserialize")]
902impl<'de> serde::Deserialize<'de> for PaymentIntentConfirmationMethod {
903    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
904        use std::str::FromStr;
905        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
906        Self::from_str(&s).map_err(|_| {
907            serde::de::Error::custom("Unknown value for PaymentIntentConfirmationMethod")
908        })
909    }
910}
911#[derive(Copy, Clone, Eq, PartialEq)]
912pub enum PaymentIntentSetupFutureUsage {
913    OffSession,
914    OnSession,
915}
916impl PaymentIntentSetupFutureUsage {
917    pub fn as_str(self) -> &'static str {
918        use PaymentIntentSetupFutureUsage::*;
919        match self {
920            OffSession => "off_session",
921            OnSession => "on_session",
922        }
923    }
924}
925
926impl std::str::FromStr for PaymentIntentSetupFutureUsage {
927    type Err = stripe_types::StripeParseError;
928    fn from_str(s: &str) -> Result<Self, Self::Err> {
929        use PaymentIntentSetupFutureUsage::*;
930        match s {
931            "off_session" => Ok(OffSession),
932            "on_session" => Ok(OnSession),
933            _ => Err(stripe_types::StripeParseError),
934        }
935    }
936}
937impl std::fmt::Display for PaymentIntentSetupFutureUsage {
938    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
939        f.write_str(self.as_str())
940    }
941}
942
943impl std::fmt::Debug for PaymentIntentSetupFutureUsage {
944    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
945        f.write_str(self.as_str())
946    }
947}
948impl serde::Serialize for PaymentIntentSetupFutureUsage {
949    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
950    where
951        S: serde::Serializer,
952    {
953        serializer.serialize_str(self.as_str())
954    }
955}
956impl miniserde::Deserialize for PaymentIntentSetupFutureUsage {
957    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
958        crate::Place::new(out)
959    }
960}
961
962impl miniserde::de::Visitor for crate::Place<PaymentIntentSetupFutureUsage> {
963    fn string(&mut self, s: &str) -> miniserde::Result<()> {
964        use std::str::FromStr;
965        self.out = Some(PaymentIntentSetupFutureUsage::from_str(s).map_err(|_| miniserde::Error)?);
966        Ok(())
967    }
968}
969
970stripe_types::impl_from_val_with_from_str!(PaymentIntentSetupFutureUsage);
971#[cfg(feature = "deserialize")]
972impl<'de> serde::Deserialize<'de> for PaymentIntentSetupFutureUsage {
973    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
974        use std::str::FromStr;
975        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
976        Self::from_str(&s).map_err(|_| {
977            serde::de::Error::custom("Unknown value for PaymentIntentSetupFutureUsage")
978        })
979    }
980}