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