Skip to main content

stripe_shared/
charge.rs

1/// The `Charge` object represents a single attempt to move money into your Stripe account.
2/// PaymentIntent confirmation is the most common way to create Charges, but [Account Debits](https://docs.stripe.com/connect/account-debits) may also create Charges.
3/// Some legacy payment flows create Charges directly, which is not recommended for new integrations.
4///
5/// For more details see <<https://stripe.com/docs/api/charges/object>>.
6#[derive(Clone)]
7#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
8#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
9pub struct Charge {
10    /// Amount intended to be collected by this payment.
11    /// A positive integer representing how much to charge in the [smallest currency unit](https://docs.stripe.com/currencies#zero-decimal) (e.g., 100 cents to charge $1.00 or 100 to charge ¥100, a zero-decimal currency).
12    /// The minimum amount is $0.50 US or [equivalent in charge currency](https://docs.stripe.com/currencies#minimum-and-maximum-charge-amounts).
13    /// The amount value supports up to eight digits (e.g., a value of 99999999 for a USD charge of $999,999.99).
14    pub amount: i64,
15    /// Amount in cents (or local equivalent) captured (can be less than the amount attribute on the charge if a partial capture was made).
16    pub amount_captured: i64,
17    /// Amount in cents (or local equivalent) refunded (can be less than the amount attribute on the charge if a partial refund was issued).
18    pub amount_refunded: i64,
19    /// ID of the Connect application that created the charge.
20    pub application: Option<stripe_types::Expandable<stripe_shared::Application>>,
21    /// The application fee (if any) for the charge.
22    /// [See the Connect documentation](https://docs.stripe.com/connect/direct-charges#collect-fees) for details.
23    pub application_fee: Option<stripe_types::Expandable<stripe_shared::ApplicationFee>>,
24    /// The amount of the application fee (if any) requested for the charge.
25    /// [See the Connect documentation](https://docs.stripe.com/connect/direct-charges#collect-fees) for details.
26    pub application_fee_amount: Option<i64>,
27    /// Authorization code on the charge.
28    pub authorization_code: Option<String>,
29    /// ID of the balance transaction that describes the impact of this charge on your account balance (not including refunds or disputes).
30    pub balance_transaction: Option<stripe_types::Expandable<stripe_shared::BalanceTransaction>>,
31    pub billing_details: stripe_shared::BillingDetails,
32    /// The full statement descriptor that is passed to card networks, and that is displayed on your customers' credit card and bank statements.
33    /// Allows you to see what the statement descriptor looks like after the static and dynamic portions are combined.
34    /// This value only exists for card payments.
35    pub calculated_statement_descriptor: Option<String>,
36    /// If the charge was created without capturing, this Boolean represents whether it is still uncaptured or has since been captured.
37    pub captured: bool,
38    /// Time at which the object was created. Measured in seconds since the Unix epoch.
39    pub created: stripe_types::Timestamp,
40    /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
41    /// Must be a [supported currency](https://stripe.com/docs/currencies).
42    pub currency: stripe_types::Currency,
43    /// ID of the customer this charge is for if one exists.
44    pub customer: Option<stripe_types::Expandable<stripe_shared::Customer>>,
45    /// An arbitrary string attached to the object. Often useful for displaying to users.
46    pub description: Option<String>,
47    /// Whether the charge has been disputed.
48    pub disputed: bool,
49    /// ID of the balance transaction that describes the reversal of the balance on your account due to payment failure.
50    pub failure_balance_transaction:
51        Option<stripe_types::Expandable<stripe_shared::BalanceTransaction>>,
52    /// Error code explaining reason for charge failure if available (see [the errors section](https://docs.stripe.com/error-codes) for a list of codes).
53    pub failure_code: Option<String>,
54    /// Message to user further explaining reason for charge failure if available.
55    pub failure_message: Option<String>,
56    /// Information on fraud assessments for the charge.
57    pub fraud_details: Option<stripe_shared::ChargeFraudDetails>,
58    /// Unique identifier for the object.
59    pub id: stripe_shared::ChargeId,
60    pub level3: Option<stripe_shared::Level3>,
61    /// If the object exists in live mode, the value is `true`.
62    /// If the object exists in test mode, the value is `false`.
63    pub livemode: bool,
64    /// Set of [key-value pairs](https://docs.stripe.com/api/metadata) that you can attach to an object.
65    /// This can be useful for storing additional information about the object in a structured format.
66    pub metadata: std::collections::HashMap<String, String>,
67    /// The account (if any) the charge was made on behalf of without triggering an automatic transfer.
68    /// See the [Connect documentation](https://docs.stripe.com/connect/separate-charges-and-transfers) for details.
69    pub on_behalf_of: Option<stripe_types::Expandable<stripe_shared::Account>>,
70    /// Details about whether the payment was accepted, and why.
71    /// See [understanding declines](https://docs.stripe.com/declines) for details.
72    pub outcome: Option<stripe_shared::ChargeOutcome>,
73    /// `true` if the charge succeeded, or was successfully authorized for later capture.
74    pub paid: bool,
75    /// ID of the PaymentIntent associated with this charge, if one exists.
76    pub payment_intent: Option<stripe_types::Expandable<stripe_shared::PaymentIntent>>,
77    /// ID of the payment method used in this charge.
78    pub payment_method: Option<String>,
79    /// Details about the payment method at the time of the transaction.
80    pub payment_method_details: Option<stripe_shared::PaymentMethodDetails>,
81    pub presentment_details: Option<stripe_shared::PaymentFlowsPaymentIntentPresentmentDetails>,
82    pub radar_options: Option<stripe_shared::RadarRadarOptions>,
83    /// This is the email address that the receipt for this charge was sent to.
84    pub receipt_email: Option<String>,
85    /// This is the transaction number that appears on email receipts sent for this charge.
86    /// This attribute will be `null` until a receipt has been sent.
87    pub receipt_number: Option<String>,
88    /// This is the URL to view the receipt for this charge.
89    /// The receipt is kept up-to-date to the latest state of the charge, including any refunds.
90    /// If the charge is for an Invoice, the receipt will be stylized as an Invoice receipt.
91    pub receipt_url: Option<String>,
92    /// Whether the charge has been fully refunded.
93    /// If the charge is only partially refunded, this attribute will still be false.
94    pub refunded: bool,
95    /// A list of refunds that have been applied to the charge.
96    pub refunds: Option<stripe_types::List<stripe_shared::Refund>>,
97    /// ID of the review associated with this charge if one exists.
98    pub review: Option<stripe_types::Expandable<stripe_shared::Review>>,
99    /// Shipping information for the charge.
100    pub shipping: Option<stripe_shared::Shipping>,
101    /// This is a legacy field that will be removed in the future.
102    /// It contains the Source, Card, or BankAccount object used for the charge.
103    /// For details about the payment method used for this charge, refer to `payment_method` or `payment_method_details` instead.
104    pub source: Option<stripe_shared::PaymentSource>,
105    /// The transfer ID which created this charge.
106    /// Only present if the charge came from another Stripe account.
107    /// [See the Connect documentation](https://docs.stripe.com/connect/destination-charges) for details.
108    pub source_transfer: Option<stripe_types::Expandable<stripe_shared::Transfer>>,
109    /// For a non-card charge, text that appears on the customer's statement as the statement descriptor.
110    /// This value overrides the account's default statement descriptor.
111    /// For information about requirements, including the 22-character limit, see [the Statement Descriptor docs](https://docs.stripe.com/get-started/account/statement-descriptors).
112    ///
113    /// For a card charge, this value is ignored unless you don't specify a `statement_descriptor_suffix`, in which case this value is used as the suffix.
114    pub statement_descriptor: Option<String>,
115    /// Provides information about a card charge.
116    /// 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.
117    /// If the account has no prefix value, the suffix is concatenated to the account's statement descriptor.
118    pub statement_descriptor_suffix: Option<String>,
119    /// The status of the payment is either `succeeded`, `pending`, or `failed`.
120    pub status: ChargeStatus,
121    /// ID of the transfer to the `destination` account (only applicable if the charge was created using the `destination` parameter).
122    pub transfer: Option<stripe_types::Expandable<stripe_shared::Transfer>>,
123    /// An optional dictionary including the account to automatically transfer to as part of a destination charge.
124    /// [See the Connect documentation](https://docs.stripe.com/connect/destination-charges) for details.
125    pub transfer_data: Option<stripe_shared::ChargeTransferData>,
126    /// A string that identifies this transaction as part of a group.
127    /// See the [Connect documentation](https://docs.stripe.com/connect/separate-charges-and-transfers#transfer-options) for details.
128    pub transfer_group: Option<String>,
129}
130#[cfg(feature = "redact-generated-debug")]
131impl std::fmt::Debug for Charge {
132    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
133        f.debug_struct("Charge").finish_non_exhaustive()
134    }
135}
136#[doc(hidden)]
137pub struct ChargeBuilder {
138    amount: Option<i64>,
139    amount_captured: Option<i64>,
140    amount_refunded: Option<i64>,
141    application: Option<Option<stripe_types::Expandable<stripe_shared::Application>>>,
142    application_fee: Option<Option<stripe_types::Expandable<stripe_shared::ApplicationFee>>>,
143    application_fee_amount: Option<Option<i64>>,
144    authorization_code: Option<Option<String>>,
145    balance_transaction:
146        Option<Option<stripe_types::Expandable<stripe_shared::BalanceTransaction>>>,
147    billing_details: Option<stripe_shared::BillingDetails>,
148    calculated_statement_descriptor: Option<Option<String>>,
149    captured: Option<bool>,
150    created: Option<stripe_types::Timestamp>,
151    currency: Option<stripe_types::Currency>,
152    customer: Option<Option<stripe_types::Expandable<stripe_shared::Customer>>>,
153    description: Option<Option<String>>,
154    disputed: Option<bool>,
155    failure_balance_transaction:
156        Option<Option<stripe_types::Expandable<stripe_shared::BalanceTransaction>>>,
157    failure_code: Option<Option<String>>,
158    failure_message: Option<Option<String>>,
159    fraud_details: Option<Option<stripe_shared::ChargeFraudDetails>>,
160    id: Option<stripe_shared::ChargeId>,
161    level3: Option<Option<stripe_shared::Level3>>,
162    livemode: Option<bool>,
163    metadata: Option<std::collections::HashMap<String, String>>,
164    on_behalf_of: Option<Option<stripe_types::Expandable<stripe_shared::Account>>>,
165    outcome: Option<Option<stripe_shared::ChargeOutcome>>,
166    paid: Option<bool>,
167    payment_intent: Option<Option<stripe_types::Expandable<stripe_shared::PaymentIntent>>>,
168    payment_method: Option<Option<String>>,
169    payment_method_details: Option<Option<stripe_shared::PaymentMethodDetails>>,
170    presentment_details: Option<Option<stripe_shared::PaymentFlowsPaymentIntentPresentmentDetails>>,
171    radar_options: Option<Option<stripe_shared::RadarRadarOptions>>,
172    receipt_email: Option<Option<String>>,
173    receipt_number: Option<Option<String>>,
174    receipt_url: Option<Option<String>>,
175    refunded: Option<bool>,
176    refunds: Option<Option<stripe_types::List<stripe_shared::Refund>>>,
177    review: Option<Option<stripe_types::Expandable<stripe_shared::Review>>>,
178    shipping: Option<Option<stripe_shared::Shipping>>,
179    source: Option<Option<stripe_shared::PaymentSource>>,
180    source_transfer: Option<Option<stripe_types::Expandable<stripe_shared::Transfer>>>,
181    statement_descriptor: Option<Option<String>>,
182    statement_descriptor_suffix: Option<Option<String>>,
183    status: Option<ChargeStatus>,
184    transfer: Option<Option<stripe_types::Expandable<stripe_shared::Transfer>>>,
185    transfer_data: Option<Option<stripe_shared::ChargeTransferData>>,
186    transfer_group: Option<Option<String>>,
187}
188
189#[allow(
190    unused_variables,
191    irrefutable_let_patterns,
192    clippy::let_unit_value,
193    clippy::match_single_binding,
194    clippy::single_match
195)]
196const _: () = {
197    use miniserde::de::{Map, Visitor};
198    use miniserde::json::Value;
199    use miniserde::{Deserialize, Result, make_place};
200    use stripe_types::miniserde_helpers::FromValueOpt;
201    use stripe_types::{MapBuilder, ObjectDeser};
202
203    make_place!(Place);
204
205    impl Deserialize for Charge {
206        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
207            Place::new(out)
208        }
209    }
210
211    struct Builder<'a> {
212        out: &'a mut Option<Charge>,
213        builder: ChargeBuilder,
214    }
215
216    impl Visitor for Place<Charge> {
217        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
218            Ok(Box::new(Builder { out: &mut self.out, builder: ChargeBuilder::deser_default() }))
219        }
220    }
221
222    impl MapBuilder for ChargeBuilder {
223        type Out = Charge;
224        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
225            Ok(match k {
226                "amount" => Deserialize::begin(&mut self.amount),
227                "amount_captured" => Deserialize::begin(&mut self.amount_captured),
228                "amount_refunded" => Deserialize::begin(&mut self.amount_refunded),
229                "application" => Deserialize::begin(&mut self.application),
230                "application_fee" => Deserialize::begin(&mut self.application_fee),
231                "application_fee_amount" => Deserialize::begin(&mut self.application_fee_amount),
232                "authorization_code" => Deserialize::begin(&mut self.authorization_code),
233                "balance_transaction" => Deserialize::begin(&mut self.balance_transaction),
234                "billing_details" => Deserialize::begin(&mut self.billing_details),
235                "calculated_statement_descriptor" => {
236                    Deserialize::begin(&mut self.calculated_statement_descriptor)
237                }
238                "captured" => Deserialize::begin(&mut self.captured),
239                "created" => Deserialize::begin(&mut self.created),
240                "currency" => Deserialize::begin(&mut self.currency),
241                "customer" => Deserialize::begin(&mut self.customer),
242                "description" => Deserialize::begin(&mut self.description),
243                "disputed" => Deserialize::begin(&mut self.disputed),
244                "failure_balance_transaction" => {
245                    Deserialize::begin(&mut self.failure_balance_transaction)
246                }
247                "failure_code" => Deserialize::begin(&mut self.failure_code),
248                "failure_message" => Deserialize::begin(&mut self.failure_message),
249                "fraud_details" => Deserialize::begin(&mut self.fraud_details),
250                "id" => Deserialize::begin(&mut self.id),
251                "level3" => Deserialize::begin(&mut self.level3),
252                "livemode" => Deserialize::begin(&mut self.livemode),
253                "metadata" => Deserialize::begin(&mut self.metadata),
254                "on_behalf_of" => Deserialize::begin(&mut self.on_behalf_of),
255                "outcome" => Deserialize::begin(&mut self.outcome),
256                "paid" => Deserialize::begin(&mut self.paid),
257                "payment_intent" => Deserialize::begin(&mut self.payment_intent),
258                "payment_method" => Deserialize::begin(&mut self.payment_method),
259                "payment_method_details" => Deserialize::begin(&mut self.payment_method_details),
260                "presentment_details" => Deserialize::begin(&mut self.presentment_details),
261                "radar_options" => Deserialize::begin(&mut self.radar_options),
262                "receipt_email" => Deserialize::begin(&mut self.receipt_email),
263                "receipt_number" => Deserialize::begin(&mut self.receipt_number),
264                "receipt_url" => Deserialize::begin(&mut self.receipt_url),
265                "refunded" => Deserialize::begin(&mut self.refunded),
266                "refunds" => Deserialize::begin(&mut self.refunds),
267                "review" => Deserialize::begin(&mut self.review),
268                "shipping" => Deserialize::begin(&mut self.shipping),
269                "source" => Deserialize::begin(&mut self.source),
270                "source_transfer" => Deserialize::begin(&mut self.source_transfer),
271                "statement_descriptor" => Deserialize::begin(&mut self.statement_descriptor),
272                "statement_descriptor_suffix" => {
273                    Deserialize::begin(&mut self.statement_descriptor_suffix)
274                }
275                "status" => Deserialize::begin(&mut self.status),
276                "transfer" => Deserialize::begin(&mut self.transfer),
277                "transfer_data" => Deserialize::begin(&mut self.transfer_data),
278                "transfer_group" => Deserialize::begin(&mut self.transfer_group),
279                _ => <dyn Visitor>::ignore(),
280            })
281        }
282
283        fn deser_default() -> Self {
284            Self {
285                amount: None,
286                amount_captured: None,
287                amount_refunded: None,
288                application: Some(None),
289                application_fee: Some(None),
290                application_fee_amount: Some(None),
291                authorization_code: Some(None),
292                balance_transaction: Some(None),
293                billing_details: None,
294                calculated_statement_descriptor: Some(None),
295                captured: None,
296                created: None,
297                currency: None,
298                customer: Some(None),
299                description: Some(None),
300                disputed: None,
301                failure_balance_transaction: Some(None),
302                failure_code: Some(None),
303                failure_message: Some(None),
304                fraud_details: Some(None),
305                id: None,
306                level3: Some(None),
307                livemode: None,
308                metadata: None,
309                on_behalf_of: Some(None),
310                outcome: Some(None),
311                paid: None,
312                payment_intent: Some(None),
313                payment_method: Some(None),
314                payment_method_details: Some(None),
315                presentment_details: Some(None),
316                radar_options: Some(None),
317                receipt_email: Some(None),
318                receipt_number: Some(None),
319                receipt_url: Some(None),
320                refunded: None,
321                refunds: Some(None),
322                review: Some(None),
323                shipping: Some(None),
324                source: Some(None),
325                source_transfer: Some(None),
326                statement_descriptor: Some(None),
327                statement_descriptor_suffix: Some(None),
328                status: None,
329                transfer: Some(None),
330                transfer_data: Some(None),
331                transfer_group: Some(None),
332            }
333        }
334
335        fn take_out(&mut self) -> Option<Self::Out> {
336            let (
337                Some(amount),
338                Some(amount_captured),
339                Some(amount_refunded),
340                Some(application),
341                Some(application_fee),
342                Some(application_fee_amount),
343                Some(authorization_code),
344                Some(balance_transaction),
345                Some(billing_details),
346                Some(calculated_statement_descriptor),
347                Some(captured),
348                Some(created),
349                Some(currency),
350                Some(customer),
351                Some(description),
352                Some(disputed),
353                Some(failure_balance_transaction),
354                Some(failure_code),
355                Some(failure_message),
356                Some(fraud_details),
357                Some(id),
358                Some(level3),
359                Some(livemode),
360                Some(metadata),
361                Some(on_behalf_of),
362                Some(outcome),
363                Some(paid),
364                Some(payment_intent),
365                Some(payment_method),
366                Some(payment_method_details),
367                Some(presentment_details),
368                Some(radar_options),
369                Some(receipt_email),
370                Some(receipt_number),
371                Some(receipt_url),
372                Some(refunded),
373                Some(refunds),
374                Some(review),
375                Some(shipping),
376                Some(source),
377                Some(source_transfer),
378                Some(statement_descriptor),
379                Some(statement_descriptor_suffix),
380                Some(status),
381                Some(transfer),
382                Some(transfer_data),
383                Some(transfer_group),
384            ) = (
385                self.amount,
386                self.amount_captured,
387                self.amount_refunded,
388                self.application.take(),
389                self.application_fee.take(),
390                self.application_fee_amount,
391                self.authorization_code.take(),
392                self.balance_transaction.take(),
393                self.billing_details.take(),
394                self.calculated_statement_descriptor.take(),
395                self.captured,
396                self.created,
397                self.currency.take(),
398                self.customer.take(),
399                self.description.take(),
400                self.disputed,
401                self.failure_balance_transaction.take(),
402                self.failure_code.take(),
403                self.failure_message.take(),
404                self.fraud_details.take(),
405                self.id.take(),
406                self.level3.take(),
407                self.livemode,
408                self.metadata.take(),
409                self.on_behalf_of.take(),
410                self.outcome.take(),
411                self.paid,
412                self.payment_intent.take(),
413                self.payment_method.take(),
414                self.payment_method_details.take(),
415                self.presentment_details.take(),
416                self.radar_options.take(),
417                self.receipt_email.take(),
418                self.receipt_number.take(),
419                self.receipt_url.take(),
420                self.refunded,
421                self.refunds.take(),
422                self.review.take(),
423                self.shipping.take(),
424                self.source.take(),
425                self.source_transfer.take(),
426                self.statement_descriptor.take(),
427                self.statement_descriptor_suffix.take(),
428                self.status.take(),
429                self.transfer.take(),
430                self.transfer_data.take(),
431                self.transfer_group.take(),
432            )
433            else {
434                return None;
435            };
436            Some(Self::Out {
437                amount,
438                amount_captured,
439                amount_refunded,
440                application,
441                application_fee,
442                application_fee_amount,
443                authorization_code,
444                balance_transaction,
445                billing_details,
446                calculated_statement_descriptor,
447                captured,
448                created,
449                currency,
450                customer,
451                description,
452                disputed,
453                failure_balance_transaction,
454                failure_code,
455                failure_message,
456                fraud_details,
457                id,
458                level3,
459                livemode,
460                metadata,
461                on_behalf_of,
462                outcome,
463                paid,
464                payment_intent,
465                payment_method,
466                payment_method_details,
467                presentment_details,
468                radar_options,
469                receipt_email,
470                receipt_number,
471                receipt_url,
472                refunded,
473                refunds,
474                review,
475                shipping,
476                source,
477                source_transfer,
478                statement_descriptor,
479                statement_descriptor_suffix,
480                status,
481                transfer,
482                transfer_data,
483                transfer_group,
484            })
485        }
486    }
487
488    impl Map for Builder<'_> {
489        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
490            self.builder.key(k)
491        }
492
493        fn finish(&mut self) -> Result<()> {
494            *self.out = self.builder.take_out();
495            Ok(())
496        }
497    }
498
499    impl ObjectDeser for Charge {
500        type Builder = ChargeBuilder;
501    }
502
503    impl FromValueOpt for Charge {
504        fn from_value(v: Value) -> Option<Self> {
505            let Value::Object(obj) = v else {
506                return None;
507            };
508            let mut b = ChargeBuilder::deser_default();
509            for (k, v) in obj {
510                match k.as_str() {
511                    "amount" => b.amount = FromValueOpt::from_value(v),
512                    "amount_captured" => b.amount_captured = FromValueOpt::from_value(v),
513                    "amount_refunded" => b.amount_refunded = FromValueOpt::from_value(v),
514                    "application" => b.application = FromValueOpt::from_value(v),
515                    "application_fee" => b.application_fee = FromValueOpt::from_value(v),
516                    "application_fee_amount" => {
517                        b.application_fee_amount = FromValueOpt::from_value(v)
518                    }
519                    "authorization_code" => b.authorization_code = FromValueOpt::from_value(v),
520                    "balance_transaction" => b.balance_transaction = FromValueOpt::from_value(v),
521                    "billing_details" => b.billing_details = FromValueOpt::from_value(v),
522                    "calculated_statement_descriptor" => {
523                        b.calculated_statement_descriptor = FromValueOpt::from_value(v)
524                    }
525                    "captured" => b.captured = FromValueOpt::from_value(v),
526                    "created" => b.created = FromValueOpt::from_value(v),
527                    "currency" => b.currency = FromValueOpt::from_value(v),
528                    "customer" => b.customer = FromValueOpt::from_value(v),
529                    "description" => b.description = FromValueOpt::from_value(v),
530                    "disputed" => b.disputed = FromValueOpt::from_value(v),
531                    "failure_balance_transaction" => {
532                        b.failure_balance_transaction = FromValueOpt::from_value(v)
533                    }
534                    "failure_code" => b.failure_code = FromValueOpt::from_value(v),
535                    "failure_message" => b.failure_message = FromValueOpt::from_value(v),
536                    "fraud_details" => b.fraud_details = FromValueOpt::from_value(v),
537                    "id" => b.id = FromValueOpt::from_value(v),
538                    "level3" => b.level3 = FromValueOpt::from_value(v),
539                    "livemode" => b.livemode = FromValueOpt::from_value(v),
540                    "metadata" => b.metadata = FromValueOpt::from_value(v),
541                    "on_behalf_of" => b.on_behalf_of = FromValueOpt::from_value(v),
542                    "outcome" => b.outcome = FromValueOpt::from_value(v),
543                    "paid" => b.paid = FromValueOpt::from_value(v),
544                    "payment_intent" => b.payment_intent = FromValueOpt::from_value(v),
545                    "payment_method" => b.payment_method = FromValueOpt::from_value(v),
546                    "payment_method_details" => {
547                        b.payment_method_details = FromValueOpt::from_value(v)
548                    }
549                    "presentment_details" => b.presentment_details = FromValueOpt::from_value(v),
550                    "radar_options" => b.radar_options = FromValueOpt::from_value(v),
551                    "receipt_email" => b.receipt_email = FromValueOpt::from_value(v),
552                    "receipt_number" => b.receipt_number = FromValueOpt::from_value(v),
553                    "receipt_url" => b.receipt_url = FromValueOpt::from_value(v),
554                    "refunded" => b.refunded = FromValueOpt::from_value(v),
555                    "refunds" => b.refunds = FromValueOpt::from_value(v),
556                    "review" => b.review = FromValueOpt::from_value(v),
557                    "shipping" => b.shipping = FromValueOpt::from_value(v),
558                    "source" => b.source = FromValueOpt::from_value(v),
559                    "source_transfer" => b.source_transfer = FromValueOpt::from_value(v),
560                    "statement_descriptor" => b.statement_descriptor = FromValueOpt::from_value(v),
561                    "statement_descriptor_suffix" => {
562                        b.statement_descriptor_suffix = FromValueOpt::from_value(v)
563                    }
564                    "status" => b.status = FromValueOpt::from_value(v),
565                    "transfer" => b.transfer = FromValueOpt::from_value(v),
566                    "transfer_data" => b.transfer_data = FromValueOpt::from_value(v),
567                    "transfer_group" => b.transfer_group = FromValueOpt::from_value(v),
568                    _ => {}
569                }
570            }
571            b.take_out()
572        }
573    }
574};
575#[cfg(feature = "serialize")]
576impl serde::Serialize for Charge {
577    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
578        use serde::ser::SerializeStruct;
579        let mut s = s.serialize_struct("Charge", 48)?;
580        s.serialize_field("amount", &self.amount)?;
581        s.serialize_field("amount_captured", &self.amount_captured)?;
582        s.serialize_field("amount_refunded", &self.amount_refunded)?;
583        s.serialize_field("application", &self.application)?;
584        s.serialize_field("application_fee", &self.application_fee)?;
585        s.serialize_field("application_fee_amount", &self.application_fee_amount)?;
586        s.serialize_field("authorization_code", &self.authorization_code)?;
587        s.serialize_field("balance_transaction", &self.balance_transaction)?;
588        s.serialize_field("billing_details", &self.billing_details)?;
589        s.serialize_field(
590            "calculated_statement_descriptor",
591            &self.calculated_statement_descriptor,
592        )?;
593        s.serialize_field("captured", &self.captured)?;
594        s.serialize_field("created", &self.created)?;
595        s.serialize_field("currency", &self.currency)?;
596        s.serialize_field("customer", &self.customer)?;
597        s.serialize_field("description", &self.description)?;
598        s.serialize_field("disputed", &self.disputed)?;
599        s.serialize_field("failure_balance_transaction", &self.failure_balance_transaction)?;
600        s.serialize_field("failure_code", &self.failure_code)?;
601        s.serialize_field("failure_message", &self.failure_message)?;
602        s.serialize_field("fraud_details", &self.fraud_details)?;
603        s.serialize_field("id", &self.id)?;
604        s.serialize_field("level3", &self.level3)?;
605        s.serialize_field("livemode", &self.livemode)?;
606        s.serialize_field("metadata", &self.metadata)?;
607        s.serialize_field("on_behalf_of", &self.on_behalf_of)?;
608        s.serialize_field("outcome", &self.outcome)?;
609        s.serialize_field("paid", &self.paid)?;
610        s.serialize_field("payment_intent", &self.payment_intent)?;
611        s.serialize_field("payment_method", &self.payment_method)?;
612        s.serialize_field("payment_method_details", &self.payment_method_details)?;
613        s.serialize_field("presentment_details", &self.presentment_details)?;
614        s.serialize_field("radar_options", &self.radar_options)?;
615        s.serialize_field("receipt_email", &self.receipt_email)?;
616        s.serialize_field("receipt_number", &self.receipt_number)?;
617        s.serialize_field("receipt_url", &self.receipt_url)?;
618        s.serialize_field("refunded", &self.refunded)?;
619        s.serialize_field("refunds", &self.refunds)?;
620        s.serialize_field("review", &self.review)?;
621        s.serialize_field("shipping", &self.shipping)?;
622        s.serialize_field("source", &self.source)?;
623        s.serialize_field("source_transfer", &self.source_transfer)?;
624        s.serialize_field("statement_descriptor", &self.statement_descriptor)?;
625        s.serialize_field("statement_descriptor_suffix", &self.statement_descriptor_suffix)?;
626        s.serialize_field("status", &self.status)?;
627        s.serialize_field("transfer", &self.transfer)?;
628        s.serialize_field("transfer_data", &self.transfer_data)?;
629        s.serialize_field("transfer_group", &self.transfer_group)?;
630
631        s.serialize_field("object", "charge")?;
632        s.end()
633    }
634}
635/// The status of the payment is either `succeeded`, `pending`, or `failed`.
636#[derive(Clone, Eq, PartialEq)]
637#[non_exhaustive]
638pub enum ChargeStatus {
639    Failed,
640    Pending,
641    Succeeded,
642    /// An unrecognized value from Stripe. Should not be used as a request parameter.
643    Unknown(String),
644}
645impl ChargeStatus {
646    pub fn as_str(&self) -> &str {
647        use ChargeStatus::*;
648        match self {
649            Failed => "failed",
650            Pending => "pending",
651            Succeeded => "succeeded",
652            Unknown(v) => v,
653        }
654    }
655}
656
657impl std::str::FromStr for ChargeStatus {
658    type Err = std::convert::Infallible;
659    fn from_str(s: &str) -> Result<Self, Self::Err> {
660        use ChargeStatus::*;
661        match s {
662            "failed" => Ok(Failed),
663            "pending" => Ok(Pending),
664            "succeeded" => Ok(Succeeded),
665            v => {
666                tracing::warn!("Unknown value '{}' for enum '{}'", v, "ChargeStatus");
667                Ok(Unknown(v.to_owned()))
668            }
669        }
670    }
671}
672impl std::fmt::Display for ChargeStatus {
673    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
674        f.write_str(self.as_str())
675    }
676}
677
678#[cfg(not(feature = "redact-generated-debug"))]
679impl std::fmt::Debug for ChargeStatus {
680    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
681        f.write_str(self.as_str())
682    }
683}
684#[cfg(feature = "redact-generated-debug")]
685impl std::fmt::Debug for ChargeStatus {
686    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
687        f.debug_struct(stringify!(ChargeStatus)).finish_non_exhaustive()
688    }
689}
690#[cfg(feature = "serialize")]
691impl serde::Serialize for ChargeStatus {
692    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
693    where
694        S: serde::Serializer,
695    {
696        serializer.serialize_str(self.as_str())
697    }
698}
699impl miniserde::Deserialize for ChargeStatus {
700    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
701        crate::Place::new(out)
702    }
703}
704
705impl miniserde::de::Visitor for crate::Place<ChargeStatus> {
706    fn string(&mut self, s: &str) -> miniserde::Result<()> {
707        use std::str::FromStr;
708        self.out = Some(ChargeStatus::from_str(s).expect("infallible"));
709        Ok(())
710    }
711}
712
713stripe_types::impl_from_val_with_from_str!(ChargeStatus);
714#[cfg(feature = "deserialize")]
715impl<'de> serde::Deserialize<'de> for ChargeStatus {
716    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
717        use std::str::FromStr;
718        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
719        Ok(Self::from_str(&s).expect("infallible"))
720    }
721}
722impl stripe_types::Object for Charge {
723    type Id = stripe_shared::ChargeId;
724    fn id(&self) -> &Self::Id {
725        &self.id
726    }
727
728    fn into_id(self) -> Self::Id {
729        self.id
730    }
731}
732stripe_types::def_id!(ChargeId);