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