async-stripe-shared 1.0.0-rc.6

API bindings for the Stripe HTTP API
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
/// Subscriptions allow you to charge a customer on a recurring basis.
///
/// Related guide: [Creating subscriptions](https://docs.stripe.com/billing/subscriptions/creating)
///
/// For more details see <<https://stripe.com/docs/api/subscriptions/object>>.
#[derive(Clone)]
#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
pub struct Subscription {
    /// ID of the Connect Application that created the subscription.
    pub application: Option<stripe_types::Expandable<stripe_shared::Application>>,
    /// A non-negative decimal between 0 and 100, with at most two decimal places.
    /// This represents the percentage of the subscription invoice total that will be transferred to the application owner's Stripe account.
    pub application_fee_percent: Option<f64>,
    pub automatic_tax: stripe_shared::SubscriptionAutomaticTax,
    /// The reference point that aligns future [billing cycle](https://docs.stripe.com/subscriptions/billing-cycle) dates.
    /// It sets the day of week for `week` intervals, the day of month for `month` and `year` intervals, and the month of year for `year` intervals.
    /// The timestamp is in UTC format.
    pub billing_cycle_anchor: stripe_types::Timestamp,
    /// The fixed values used to calculate the `billing_cycle_anchor`.
    pub billing_cycle_anchor_config:
        Option<stripe_shared::SubscriptionsResourceBillingCycleAnchorConfig>,
    pub billing_mode: stripe_shared::SubscriptionsResourceBillingMode,
    /// Define thresholds at which an invoice will be sent, and the subscription advanced to a new billing period.
    pub billing_thresholds: Option<stripe_shared::SubscriptionBillingThresholds>,
    /// A date in the future at which the subscription will automatically get canceled
    pub cancel_at: Option<stripe_types::Timestamp>,
    /// Whether this subscription will (if `status=active`) or did (if `status=canceled`) cancel at the end of the current billing period.
    pub cancel_at_period_end: bool,
    /// If the subscription has been canceled, the date of that cancellation.
    /// If the subscription was canceled with `cancel_at_period_end`, `canceled_at` will reflect the time of the most recent update request, not the end of the subscription period when the subscription is automatically moved to a canceled state.
    pub canceled_at: Option<stripe_types::Timestamp>,
    /// Details about why this subscription was cancelled
    pub cancellation_details: Option<stripe_shared::CancellationDetails>,
    /// Either `charge_automatically`, or `send_invoice`.
    /// When charging automatically, Stripe will attempt to pay this subscription at the end of the cycle using the default source attached to the customer.
    /// When sending an invoice, Stripe will email your customer an invoice with payment instructions and mark the subscription as `active`.
    pub collection_method: stripe_shared::SubscriptionCollectionMethod,
    /// Time at which the object was created. Measured in seconds since the Unix epoch.
    pub created: stripe_types::Timestamp,
    /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
    /// Must be a [supported currency](https://stripe.com/docs/currencies).
    pub currency: stripe_types::Currency,
    /// ID of the customer who owns the subscription.
    pub customer: stripe_types::Expandable<stripe_shared::Customer>,
    /// ID of the account representing the customer who owns the subscription.
    pub customer_account: Option<String>,
    /// Number of days a customer has to pay invoices generated by this subscription.
    /// This value will be `null` for subscriptions where `collection_method=charge_automatically`.
    pub days_until_due: Option<u32>,
    /// ID of the default payment method for the subscription.
    /// It must belong to the customer associated with the subscription.
    /// This takes precedence over `default_source`.
    /// If neither are set, invoices will use the customer's [invoice_settings.default_payment_method](https://docs.stripe.com/api/customers/object#customer_object-invoice_settings-default_payment_method) or [default_source](https://docs.stripe.com/api/customers/object#customer_object-default_source).
    pub default_payment_method: Option<stripe_types::Expandable<stripe_shared::PaymentMethod>>,
    /// ID of the default payment source for the subscription.
    /// It must belong to the customer associated with the subscription and be in a chargeable state.
    /// If `default_payment_method` is also set, `default_payment_method` will take precedence.
    /// If neither are set, invoices will use the customer's [invoice_settings.default_payment_method](https://docs.stripe.com/api/customers/object#customer_object-invoice_settings-default_payment_method) or [default_source](https://docs.stripe.com/api/customers/object#customer_object-default_source).
    pub default_source: Option<stripe_types::Expandable<stripe_shared::PaymentSource>>,
    /// The tax rates that will apply to any subscription item that does not have `tax_rates` set.
    /// Invoices created will have their `default_tax_rates` populated from the subscription.
    pub default_tax_rates: Option<Vec<stripe_shared::TaxRate>>,
    /// The subscription's description, meant to be displayable to the customer.
    /// Use this field to optionally store an explanation of the subscription for rendering in Stripe surfaces and certain local payment methods UIs.
    pub description: Option<String>,
    /// The discounts applied to the subscription.
    /// Subscription item discounts are applied before subscription discounts.
    /// Use `expand[]=discounts` to expand each discount.
    pub discounts: Vec<stripe_types::Expandable<stripe_shared::Discount>>,
    /// If the subscription has ended, the date the subscription ended.
    pub ended_at: Option<stripe_types::Timestamp>,
    /// Unique identifier for the object.
    pub id: stripe_shared::SubscriptionId,
    pub invoice_settings: stripe_shared::SubscriptionsResourceSubscriptionInvoiceSettings,
    /// List of subscription items, each with an attached price.
    pub items: stripe_types::List<stripe_shared::SubscriptionItem>,
    /// The most recent invoice this subscription has generated over its lifecycle (for example, when it cycles or is updated).
    pub latest_invoice: Option<stripe_types::Expandable<stripe_shared::Invoice>>,
    /// If the object exists in live mode, the value is `true`.
    /// If the object exists in test mode, the value is `false`.
    pub livemode: bool,
    /// Settings for Managed Payments for this Subscription and resulting [Invoices](/api/invoices/object) and [PaymentIntents](/api/payment_intents/object).
    pub managed_payments: Option<stripe_shared::SmorResourceManagedPayments>,
    /// Set of [key-value pairs](https://docs.stripe.com/api/metadata) that you can attach to an object.
    /// This can be useful for storing additional information about the object in a structured format.
    pub metadata: std::collections::HashMap<String, String>,
    /// Specifies the approximate timestamp on which any pending invoice items will be billed according to the schedule provided at `pending_invoice_item_interval`.
    pub next_pending_invoice_item_invoice: Option<stripe_types::Timestamp>,
    /// The account (if any) the charge was made on behalf of for charges associated with this subscription.
    /// See the [Connect documentation](https://docs.stripe.com/connect/subscriptions#on-behalf-of) for details.
    pub on_behalf_of: Option<stripe_types::Expandable<stripe_shared::Account>>,
    /// If specified, payment collection for this subscription will be paused.
    /// Note that the subscription status will be unchanged and will not be updated to `paused`.
    /// Learn more about [pausing collection](https://docs.stripe.com/billing/subscriptions/pause-payment).
    pub pause_collection: Option<stripe_shared::SubscriptionsResourcePauseCollection>,
    /// Payment settings passed on to invoices created by the subscription.
    pub payment_settings: Option<stripe_shared::SubscriptionsResourcePaymentSettings>,
    /// Specifies an interval for how often to bill for any pending invoice items.
    /// It is analogous to calling [Create an invoice](/api/invoices/create) for the given subscription at the specified interval.
    pub pending_invoice_item_interval:
        Option<stripe_shared::SubscriptionPendingInvoiceItemInterval>,
    /// You can use this [SetupIntent](https://docs.stripe.com/api/setup_intents) to collect user authentication when creating a subscription without immediate payment or updating a subscription's payment method, allowing you to optimize for off-session payments.
    /// Learn more in the [SCA Migration Guide](https://docs.stripe.com/billing/migration/strong-customer-authentication#scenario-2).
    pub pending_setup_intent: Option<stripe_types::Expandable<stripe_shared::SetupIntent>>,
    /// If specified, [pending updates](https://docs.stripe.com/billing/subscriptions/pending-updates) that will be applied to the subscription once the `latest_invoice` has been paid.
    pub pending_update: Option<stripe_shared::SubscriptionsResourcePendingUpdate>,
    pub presentment_details:
        Option<stripe_shared::SubscriptionsResourceSubscriptionPresentmentDetails>,
    /// The schedule attached to the subscription
    pub schedule: Option<stripe_types::Expandable<stripe_shared::SubscriptionSchedule>>,
    /// Date when the subscription was first created.
    /// The date might differ from the `created` date due to backdating.
    pub start_date: stripe_types::Timestamp,
    /// Possible values are `incomplete`, `incomplete_expired`, `trialing`, `active`, `past_due`, `canceled`, `unpaid`, or `paused`.
    ///
    ///
    /// For `collection_method=charge_automatically` a subscription moves into `incomplete` if the initial payment attempt fails.
    /// A subscription in this status can only have metadata and default_source updated.
    /// Once the first invoice is paid, the subscription moves into an `active` status.
    /// If the first invoice is not paid within 23 hours, the subscription transitions to `incomplete_expired`.
    /// This is a terminal status, the open invoice will be voided and no further invoices will be generated.
    ///
    ///
    /// A subscription that is currently in a trial period is `trialing` and moves to `active` when the trial period is over.
    ///
    ///
    /// A subscription can only enter a `paused` status [when a trial ends without a payment method](https://docs.stripe.com/billing/subscriptions/trials#create-free-trials-without-payment).
    /// A `paused` subscription doesn't generate invoices and can be resumed after your customer adds their payment method.
    /// The `paused` status is different from [pausing collection](https://docs.stripe.com/billing/subscriptions/pause-payment), which still generates invoices and leaves the subscription's status unchanged.
    ///
    ///
    /// If subscription `collection_method=charge_automatically`, it becomes `past_due` when payment is required but cannot be paid (due to failed payment or awaiting additional user actions).
    /// Once Stripe has exhausted all payment retry attempts, the subscription will become `canceled` or `unpaid` (depending on your subscriptions settings).
    ///
    ///
    /// If subscription `collection_method=send_invoice` it becomes `past_due` when its invoice is not paid by the due date, and `canceled` or `unpaid` if it is still not paid by an additional deadline after that.
    /// Note that when a subscription has a status of `unpaid`, no subsequent invoices will be attempted (invoices will be created, but then immediately automatically closed).
    /// After receiving updated payment information from a customer, you may choose to reopen and pay their closed invoices.
    pub status: SubscriptionStatus,
    /// ID of the test clock this subscription belongs to.
    pub test_clock: Option<stripe_types::Expandable<stripe_shared::TestHelpersTestClock>>,
    /// The account (if any) the subscription's payments will be attributed to for tax reporting, and where funds from each payment will be transferred to for each of the subscription's invoices.
    pub transfer_data: Option<stripe_shared::SubscriptionTransferData>,
    /// If the subscription has a trial, the end of that trial.
    pub trial_end: Option<stripe_types::Timestamp>,
    /// Settings related to subscription trials.
    pub trial_settings: Option<stripe_shared::SubscriptionsResourceTrialSettingsTrialSettings>,
    /// If the subscription has a trial, the beginning of that trial.
    pub trial_start: Option<stripe_types::Timestamp>,
}
#[cfg(feature = "redact-generated-debug")]
impl std::fmt::Debug for Subscription {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        f.debug_struct("Subscription").finish_non_exhaustive()
    }
}
#[doc(hidden)]
pub struct SubscriptionBuilder {
    application: Option<Option<stripe_types::Expandable<stripe_shared::Application>>>,
    application_fee_percent: Option<Option<f64>>,
    automatic_tax: Option<stripe_shared::SubscriptionAutomaticTax>,
    billing_cycle_anchor: Option<stripe_types::Timestamp>,
    billing_cycle_anchor_config:
        Option<Option<stripe_shared::SubscriptionsResourceBillingCycleAnchorConfig>>,
    billing_mode: Option<stripe_shared::SubscriptionsResourceBillingMode>,
    billing_thresholds: Option<Option<stripe_shared::SubscriptionBillingThresholds>>,
    cancel_at: Option<Option<stripe_types::Timestamp>>,
    cancel_at_period_end: Option<bool>,
    canceled_at: Option<Option<stripe_types::Timestamp>>,
    cancellation_details: Option<Option<stripe_shared::CancellationDetails>>,
    collection_method: Option<stripe_shared::SubscriptionCollectionMethod>,
    created: Option<stripe_types::Timestamp>,
    currency: Option<stripe_types::Currency>,
    customer: Option<stripe_types::Expandable<stripe_shared::Customer>>,
    customer_account: Option<Option<String>>,
    days_until_due: Option<Option<u32>>,
    default_payment_method: Option<Option<stripe_types::Expandable<stripe_shared::PaymentMethod>>>,
    default_source: Option<Option<stripe_types::Expandable<stripe_shared::PaymentSource>>>,
    default_tax_rates: Option<Option<Vec<stripe_shared::TaxRate>>>,
    description: Option<Option<String>>,
    discounts: Option<Vec<stripe_types::Expandable<stripe_shared::Discount>>>,
    ended_at: Option<Option<stripe_types::Timestamp>>,
    id: Option<stripe_shared::SubscriptionId>,
    invoice_settings: Option<stripe_shared::SubscriptionsResourceSubscriptionInvoiceSettings>,
    items: Option<stripe_types::List<stripe_shared::SubscriptionItem>>,
    latest_invoice: Option<Option<stripe_types::Expandable<stripe_shared::Invoice>>>,
    livemode: Option<bool>,
    managed_payments: Option<Option<stripe_shared::SmorResourceManagedPayments>>,
    metadata: Option<std::collections::HashMap<String, String>>,
    next_pending_invoice_item_invoice: Option<Option<stripe_types::Timestamp>>,
    on_behalf_of: Option<Option<stripe_types::Expandable<stripe_shared::Account>>>,
    pause_collection: Option<Option<stripe_shared::SubscriptionsResourcePauseCollection>>,
    payment_settings: Option<Option<stripe_shared::SubscriptionsResourcePaymentSettings>>,
    pending_invoice_item_interval:
        Option<Option<stripe_shared::SubscriptionPendingInvoiceItemInterval>>,
    pending_setup_intent: Option<Option<stripe_types::Expandable<stripe_shared::SetupIntent>>>,
    pending_update: Option<Option<stripe_shared::SubscriptionsResourcePendingUpdate>>,
    presentment_details:
        Option<Option<stripe_shared::SubscriptionsResourceSubscriptionPresentmentDetails>>,
    schedule: Option<Option<stripe_types::Expandable<stripe_shared::SubscriptionSchedule>>>,
    start_date: Option<stripe_types::Timestamp>,
    status: Option<SubscriptionStatus>,
    test_clock: Option<Option<stripe_types::Expandable<stripe_shared::TestHelpersTestClock>>>,
    transfer_data: Option<Option<stripe_shared::SubscriptionTransferData>>,
    trial_end: Option<Option<stripe_types::Timestamp>>,
    trial_settings: Option<Option<stripe_shared::SubscriptionsResourceTrialSettingsTrialSettings>>,
    trial_start: Option<Option<stripe_types::Timestamp>>,
}

#[allow(
    unused_variables,
    irrefutable_let_patterns,
    clippy::let_unit_value,
    clippy::match_single_binding,
    clippy::single_match
)]
const _: () = {
    use miniserde::de::{Map, Visitor};
    use miniserde::json::Value;
    use miniserde::{Deserialize, Result, make_place};
    use stripe_types::miniserde_helpers::FromValueOpt;
    use stripe_types::{MapBuilder, ObjectDeser};

    make_place!(Place);

    impl Deserialize for Subscription {
        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
            Place::new(out)
        }
    }

    struct Builder<'a> {
        out: &'a mut Option<Subscription>,
        builder: SubscriptionBuilder,
    }

    impl Visitor for Place<Subscription> {
        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
            Ok(Box::new(Builder {
                out: &mut self.out,
                builder: SubscriptionBuilder::deser_default(),
            }))
        }
    }

    impl MapBuilder for SubscriptionBuilder {
        type Out = Subscription;
        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
            Ok(match k {
                "application" => Deserialize::begin(&mut self.application),
                "application_fee_percent" => Deserialize::begin(&mut self.application_fee_percent),
                "automatic_tax" => Deserialize::begin(&mut self.automatic_tax),
                "billing_cycle_anchor" => Deserialize::begin(&mut self.billing_cycle_anchor),
                "billing_cycle_anchor_config" => {
                    Deserialize::begin(&mut self.billing_cycle_anchor_config)
                }
                "billing_mode" => Deserialize::begin(&mut self.billing_mode),
                "billing_thresholds" => Deserialize::begin(&mut self.billing_thresholds),
                "cancel_at" => Deserialize::begin(&mut self.cancel_at),
                "cancel_at_period_end" => Deserialize::begin(&mut self.cancel_at_period_end),
                "canceled_at" => Deserialize::begin(&mut self.canceled_at),
                "cancellation_details" => Deserialize::begin(&mut self.cancellation_details),
                "collection_method" => Deserialize::begin(&mut self.collection_method),
                "created" => Deserialize::begin(&mut self.created),
                "currency" => Deserialize::begin(&mut self.currency),
                "customer" => Deserialize::begin(&mut self.customer),
                "customer_account" => Deserialize::begin(&mut self.customer_account),
                "days_until_due" => Deserialize::begin(&mut self.days_until_due),
                "default_payment_method" => Deserialize::begin(&mut self.default_payment_method),
                "default_source" => Deserialize::begin(&mut self.default_source),
                "default_tax_rates" => Deserialize::begin(&mut self.default_tax_rates),
                "description" => Deserialize::begin(&mut self.description),
                "discounts" => Deserialize::begin(&mut self.discounts),
                "ended_at" => Deserialize::begin(&mut self.ended_at),
                "id" => Deserialize::begin(&mut self.id),
                "invoice_settings" => Deserialize::begin(&mut self.invoice_settings),
                "items" => Deserialize::begin(&mut self.items),
                "latest_invoice" => Deserialize::begin(&mut self.latest_invoice),
                "livemode" => Deserialize::begin(&mut self.livemode),
                "managed_payments" => Deserialize::begin(&mut self.managed_payments),
                "metadata" => Deserialize::begin(&mut self.metadata),
                "next_pending_invoice_item_invoice" => {
                    Deserialize::begin(&mut self.next_pending_invoice_item_invoice)
                }
                "on_behalf_of" => Deserialize::begin(&mut self.on_behalf_of),
                "pause_collection" => Deserialize::begin(&mut self.pause_collection),
                "payment_settings" => Deserialize::begin(&mut self.payment_settings),
                "pending_invoice_item_interval" => {
                    Deserialize::begin(&mut self.pending_invoice_item_interval)
                }
                "pending_setup_intent" => Deserialize::begin(&mut self.pending_setup_intent),
                "pending_update" => Deserialize::begin(&mut self.pending_update),
                "presentment_details" => Deserialize::begin(&mut self.presentment_details),
                "schedule" => Deserialize::begin(&mut self.schedule),
                "start_date" => Deserialize::begin(&mut self.start_date),
                "status" => Deserialize::begin(&mut self.status),
                "test_clock" => Deserialize::begin(&mut self.test_clock),
                "transfer_data" => Deserialize::begin(&mut self.transfer_data),
                "trial_end" => Deserialize::begin(&mut self.trial_end),
                "trial_settings" => Deserialize::begin(&mut self.trial_settings),
                "trial_start" => Deserialize::begin(&mut self.trial_start),
                _ => <dyn Visitor>::ignore(),
            })
        }

        fn deser_default() -> Self {
            Self {
                application: Some(None),
                application_fee_percent: Some(None),
                automatic_tax: None,
                billing_cycle_anchor: None,
                billing_cycle_anchor_config: Some(None),
                billing_mode: None,
                billing_thresholds: Some(None),
                cancel_at: Some(None),
                cancel_at_period_end: None,
                canceled_at: Some(None),
                cancellation_details: Some(None),
                collection_method: None,
                created: None,
                currency: None,
                customer: None,
                customer_account: Some(None),
                days_until_due: Some(None),
                default_payment_method: Some(None),
                default_source: Some(None),
                default_tax_rates: Some(None),
                description: Some(None),
                discounts: None,
                ended_at: Some(None),
                id: None,
                invoice_settings: None,
                items: None,
                latest_invoice: Some(None),
                livemode: None,
                managed_payments: Some(None),
                metadata: None,
                next_pending_invoice_item_invoice: Some(None),
                on_behalf_of: Some(None),
                pause_collection: Some(None),
                payment_settings: Some(None),
                pending_invoice_item_interval: Some(None),
                pending_setup_intent: Some(None),
                pending_update: Some(None),
                presentment_details: Some(None),
                schedule: Some(None),
                start_date: None,
                status: None,
                test_clock: Some(None),
                transfer_data: Some(None),
                trial_end: Some(None),
                trial_settings: Some(None),
                trial_start: Some(None),
            }
        }

        fn take_out(&mut self) -> Option<Self::Out> {
            let (
                Some(application),
                Some(application_fee_percent),
                Some(automatic_tax),
                Some(billing_cycle_anchor),
                Some(billing_cycle_anchor_config),
                Some(billing_mode),
                Some(billing_thresholds),
                Some(cancel_at),
                Some(cancel_at_period_end),
                Some(canceled_at),
                Some(cancellation_details),
                Some(collection_method),
                Some(created),
                Some(currency),
                Some(customer),
                Some(customer_account),
                Some(days_until_due),
                Some(default_payment_method),
                Some(default_source),
                Some(default_tax_rates),
                Some(description),
                Some(discounts),
                Some(ended_at),
                Some(id),
                Some(invoice_settings),
                Some(items),
                Some(latest_invoice),
                Some(livemode),
                Some(managed_payments),
                Some(metadata),
                Some(next_pending_invoice_item_invoice),
                Some(on_behalf_of),
                Some(pause_collection),
                Some(payment_settings),
                Some(pending_invoice_item_interval),
                Some(pending_setup_intent),
                Some(pending_update),
                Some(presentment_details),
                Some(schedule),
                Some(start_date),
                Some(status),
                Some(test_clock),
                Some(transfer_data),
                Some(trial_end),
                Some(trial_settings),
                Some(trial_start),
            ) = (
                self.application.take(),
                self.application_fee_percent,
                self.automatic_tax.take(),
                self.billing_cycle_anchor,
                self.billing_cycle_anchor_config,
                self.billing_mode.take(),
                self.billing_thresholds,
                self.cancel_at,
                self.cancel_at_period_end,
                self.canceled_at,
                self.cancellation_details.take(),
                self.collection_method.take(),
                self.created,
                self.currency.take(),
                self.customer.take(),
                self.customer_account.take(),
                self.days_until_due,
                self.default_payment_method.take(),
                self.default_source.take(),
                self.default_tax_rates.take(),
                self.description.take(),
                self.discounts.take(),
                self.ended_at,
                self.id.take(),
                self.invoice_settings.take(),
                self.items.take(),
                self.latest_invoice.take(),
                self.livemode,
                self.managed_payments,
                self.metadata.take(),
                self.next_pending_invoice_item_invoice,
                self.on_behalf_of.take(),
                self.pause_collection.take(),
                self.payment_settings.take(),
                self.pending_invoice_item_interval.take(),
                self.pending_setup_intent.take(),
                self.pending_update.take(),
                self.presentment_details.take(),
                self.schedule.take(),
                self.start_date,
                self.status.take(),
                self.test_clock.take(),
                self.transfer_data.take(),
                self.trial_end,
                self.trial_settings.take(),
                self.trial_start,
            )
            else {
                return None;
            };
            Some(Self::Out {
                application,
                application_fee_percent,
                automatic_tax,
                billing_cycle_anchor,
                billing_cycle_anchor_config,
                billing_mode,
                billing_thresholds,
                cancel_at,
                cancel_at_period_end,
                canceled_at,
                cancellation_details,
                collection_method,
                created,
                currency,
                customer,
                customer_account,
                days_until_due,
                default_payment_method,
                default_source,
                default_tax_rates,
                description,
                discounts,
                ended_at,
                id,
                invoice_settings,
                items,
                latest_invoice,
                livemode,
                managed_payments,
                metadata,
                next_pending_invoice_item_invoice,
                on_behalf_of,
                pause_collection,
                payment_settings,
                pending_invoice_item_interval,
                pending_setup_intent,
                pending_update,
                presentment_details,
                schedule,
                start_date,
                status,
                test_clock,
                transfer_data,
                trial_end,
                trial_settings,
                trial_start,
            })
        }
    }

    impl Map for Builder<'_> {
        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
            self.builder.key(k)
        }

        fn finish(&mut self) -> Result<()> {
            *self.out = self.builder.take_out();
            Ok(())
        }
    }

    impl ObjectDeser for Subscription {
        type Builder = SubscriptionBuilder;
    }

    impl FromValueOpt for Subscription {
        fn from_value(v: Value) -> Option<Self> {
            let Value::Object(obj) = v else {
                return None;
            };
            let mut b = SubscriptionBuilder::deser_default();
            for (k, v) in obj {
                match k.as_str() {
                    "application" => b.application = FromValueOpt::from_value(v),
                    "application_fee_percent" => {
                        b.application_fee_percent = FromValueOpt::from_value(v)
                    }
                    "automatic_tax" => b.automatic_tax = FromValueOpt::from_value(v),
                    "billing_cycle_anchor" => b.billing_cycle_anchor = FromValueOpt::from_value(v),
                    "billing_cycle_anchor_config" => {
                        b.billing_cycle_anchor_config = FromValueOpt::from_value(v)
                    }
                    "billing_mode" => b.billing_mode = FromValueOpt::from_value(v),
                    "billing_thresholds" => b.billing_thresholds = FromValueOpt::from_value(v),
                    "cancel_at" => b.cancel_at = FromValueOpt::from_value(v),
                    "cancel_at_period_end" => b.cancel_at_period_end = FromValueOpt::from_value(v),
                    "canceled_at" => b.canceled_at = FromValueOpt::from_value(v),
                    "cancellation_details" => b.cancellation_details = FromValueOpt::from_value(v),
                    "collection_method" => b.collection_method = FromValueOpt::from_value(v),
                    "created" => b.created = FromValueOpt::from_value(v),
                    "currency" => b.currency = FromValueOpt::from_value(v),
                    "customer" => b.customer = FromValueOpt::from_value(v),
                    "customer_account" => b.customer_account = FromValueOpt::from_value(v),
                    "days_until_due" => b.days_until_due = FromValueOpt::from_value(v),
                    "default_payment_method" => {
                        b.default_payment_method = FromValueOpt::from_value(v)
                    }
                    "default_source" => b.default_source = FromValueOpt::from_value(v),
                    "default_tax_rates" => b.default_tax_rates = FromValueOpt::from_value(v),
                    "description" => b.description = FromValueOpt::from_value(v),
                    "discounts" => b.discounts = FromValueOpt::from_value(v),
                    "ended_at" => b.ended_at = FromValueOpt::from_value(v),
                    "id" => b.id = FromValueOpt::from_value(v),
                    "invoice_settings" => b.invoice_settings = FromValueOpt::from_value(v),
                    "items" => b.items = FromValueOpt::from_value(v),
                    "latest_invoice" => b.latest_invoice = FromValueOpt::from_value(v),
                    "livemode" => b.livemode = FromValueOpt::from_value(v),
                    "managed_payments" => b.managed_payments = FromValueOpt::from_value(v),
                    "metadata" => b.metadata = FromValueOpt::from_value(v),
                    "next_pending_invoice_item_invoice" => {
                        b.next_pending_invoice_item_invoice = FromValueOpt::from_value(v)
                    }
                    "on_behalf_of" => b.on_behalf_of = FromValueOpt::from_value(v),
                    "pause_collection" => b.pause_collection = FromValueOpt::from_value(v),
                    "payment_settings" => b.payment_settings = FromValueOpt::from_value(v),
                    "pending_invoice_item_interval" => {
                        b.pending_invoice_item_interval = FromValueOpt::from_value(v)
                    }
                    "pending_setup_intent" => b.pending_setup_intent = FromValueOpt::from_value(v),
                    "pending_update" => b.pending_update = FromValueOpt::from_value(v),
                    "presentment_details" => b.presentment_details = FromValueOpt::from_value(v),
                    "schedule" => b.schedule = FromValueOpt::from_value(v),
                    "start_date" => b.start_date = FromValueOpt::from_value(v),
                    "status" => b.status = FromValueOpt::from_value(v),
                    "test_clock" => b.test_clock = FromValueOpt::from_value(v),
                    "transfer_data" => b.transfer_data = FromValueOpt::from_value(v),
                    "trial_end" => b.trial_end = FromValueOpt::from_value(v),
                    "trial_settings" => b.trial_settings = FromValueOpt::from_value(v),
                    "trial_start" => b.trial_start = FromValueOpt::from_value(v),
                    _ => {}
                }
            }
            b.take_out()
        }
    }
};
#[cfg(feature = "serialize")]
impl serde::Serialize for Subscription {
    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
        use serde::ser::SerializeStruct;
        let mut s = s.serialize_struct("Subscription", 47)?;
        s.serialize_field("application", &self.application)?;
        s.serialize_field("application_fee_percent", &self.application_fee_percent)?;
        s.serialize_field("automatic_tax", &self.automatic_tax)?;
        s.serialize_field("billing_cycle_anchor", &self.billing_cycle_anchor)?;
        s.serialize_field("billing_cycle_anchor_config", &self.billing_cycle_anchor_config)?;
        s.serialize_field("billing_mode", &self.billing_mode)?;
        s.serialize_field("billing_thresholds", &self.billing_thresholds)?;
        s.serialize_field("cancel_at", &self.cancel_at)?;
        s.serialize_field("cancel_at_period_end", &self.cancel_at_period_end)?;
        s.serialize_field("canceled_at", &self.canceled_at)?;
        s.serialize_field("cancellation_details", &self.cancellation_details)?;
        s.serialize_field("collection_method", &self.collection_method)?;
        s.serialize_field("created", &self.created)?;
        s.serialize_field("currency", &self.currency)?;
        s.serialize_field("customer", &self.customer)?;
        s.serialize_field("customer_account", &self.customer_account)?;
        s.serialize_field("days_until_due", &self.days_until_due)?;
        s.serialize_field("default_payment_method", &self.default_payment_method)?;
        s.serialize_field("default_source", &self.default_source)?;
        s.serialize_field("default_tax_rates", &self.default_tax_rates)?;
        s.serialize_field("description", &self.description)?;
        s.serialize_field("discounts", &self.discounts)?;
        s.serialize_field("ended_at", &self.ended_at)?;
        s.serialize_field("id", &self.id)?;
        s.serialize_field("invoice_settings", &self.invoice_settings)?;
        s.serialize_field("items", &self.items)?;
        s.serialize_field("latest_invoice", &self.latest_invoice)?;
        s.serialize_field("livemode", &self.livemode)?;
        s.serialize_field("managed_payments", &self.managed_payments)?;
        s.serialize_field("metadata", &self.metadata)?;
        s.serialize_field(
            "next_pending_invoice_item_invoice",
            &self.next_pending_invoice_item_invoice,
        )?;
        s.serialize_field("on_behalf_of", &self.on_behalf_of)?;
        s.serialize_field("pause_collection", &self.pause_collection)?;
        s.serialize_field("payment_settings", &self.payment_settings)?;
        s.serialize_field("pending_invoice_item_interval", &self.pending_invoice_item_interval)?;
        s.serialize_field("pending_setup_intent", &self.pending_setup_intent)?;
        s.serialize_field("pending_update", &self.pending_update)?;
        s.serialize_field("presentment_details", &self.presentment_details)?;
        s.serialize_field("schedule", &self.schedule)?;
        s.serialize_field("start_date", &self.start_date)?;
        s.serialize_field("status", &self.status)?;
        s.serialize_field("test_clock", &self.test_clock)?;
        s.serialize_field("transfer_data", &self.transfer_data)?;
        s.serialize_field("trial_end", &self.trial_end)?;
        s.serialize_field("trial_settings", &self.trial_settings)?;
        s.serialize_field("trial_start", &self.trial_start)?;

        s.serialize_field("object", "subscription")?;
        s.end()
    }
}
/// Possible values are `incomplete`, `incomplete_expired`, `trialing`, `active`, `past_due`, `canceled`, `unpaid`, or `paused`.
///
///
/// For `collection_method=charge_automatically` a subscription moves into `incomplete` if the initial payment attempt fails.
/// A subscription in this status can only have metadata and default_source updated.
/// Once the first invoice is paid, the subscription moves into an `active` status.
/// If the first invoice is not paid within 23 hours, the subscription transitions to `incomplete_expired`.
/// This is a terminal status, the open invoice will be voided and no further invoices will be generated.
///
///
/// A subscription that is currently in a trial period is `trialing` and moves to `active` when the trial period is over.
///
///
/// A subscription can only enter a `paused` status [when a trial ends without a payment method](https://docs.stripe.com/billing/subscriptions/trials#create-free-trials-without-payment).
/// A `paused` subscription doesn't generate invoices and can be resumed after your customer adds their payment method.
/// The `paused` status is different from [pausing collection](https://docs.stripe.com/billing/subscriptions/pause-payment), which still generates invoices and leaves the subscription's status unchanged.
///
///
/// If subscription `collection_method=charge_automatically`, it becomes `past_due` when payment is required but cannot be paid (due to failed payment or awaiting additional user actions).
/// Once Stripe has exhausted all payment retry attempts, the subscription will become `canceled` or `unpaid` (depending on your subscriptions settings).
///
///
/// If subscription `collection_method=send_invoice` it becomes `past_due` when its invoice is not paid by the due date, and `canceled` or `unpaid` if it is still not paid by an additional deadline after that.
/// Note that when a subscription has a status of `unpaid`, no subsequent invoices will be attempted (invoices will be created, but then immediately automatically closed).
/// After receiving updated payment information from a customer, you may choose to reopen and pay their closed invoices.
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub enum SubscriptionStatus {
    Active,
    Canceled,
    Incomplete,
    IncompleteExpired,
    PastDue,
    Paused,
    Trialing,
    Unpaid,
    /// An unrecognized value from Stripe. Should not be used as a request parameter.
    Unknown(String),
}
impl SubscriptionStatus {
    pub fn as_str(&self) -> &str {
        use SubscriptionStatus::*;
        match self {
            Active => "active",
            Canceled => "canceled",
            Incomplete => "incomplete",
            IncompleteExpired => "incomplete_expired",
            PastDue => "past_due",
            Paused => "paused",
            Trialing => "trialing",
            Unpaid => "unpaid",
            Unknown(v) => v,
        }
    }
}

impl std::str::FromStr for SubscriptionStatus {
    type Err = std::convert::Infallible;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        use SubscriptionStatus::*;
        match s {
            "active" => Ok(Active),
            "canceled" => Ok(Canceled),
            "incomplete" => Ok(Incomplete),
            "incomplete_expired" => Ok(IncompleteExpired),
            "past_due" => Ok(PastDue),
            "paused" => Ok(Paused),
            "trialing" => Ok(Trialing),
            "unpaid" => Ok(Unpaid),
            v => {
                tracing::warn!("Unknown value '{}' for enum '{}'", v, "SubscriptionStatus");
                Ok(Unknown(v.to_owned()))
            }
        }
    }
}
impl std::fmt::Display for SubscriptionStatus {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        f.write_str(self.as_str())
    }
}

#[cfg(not(feature = "redact-generated-debug"))]
impl std::fmt::Debug for SubscriptionStatus {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        f.write_str(self.as_str())
    }
}
#[cfg(feature = "redact-generated-debug")]
impl std::fmt::Debug for SubscriptionStatus {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        f.debug_struct(stringify!(SubscriptionStatus)).finish_non_exhaustive()
    }
}
#[cfg(feature = "serialize")]
impl serde::Serialize for SubscriptionStatus {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}
impl miniserde::Deserialize for SubscriptionStatus {
    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
        crate::Place::new(out)
    }
}

impl miniserde::de::Visitor for crate::Place<SubscriptionStatus> {
    fn string(&mut self, s: &str) -> miniserde::Result<()> {
        use std::str::FromStr;
        self.out = Some(SubscriptionStatus::from_str(s).expect("infallible"));
        Ok(())
    }
}

stripe_types::impl_from_val_with_from_str!(SubscriptionStatus);
#[cfg(feature = "deserialize")]
impl<'de> serde::Deserialize<'de> for SubscriptionStatus {
    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        use std::str::FromStr;
        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
        Ok(Self::from_str(&s).expect("infallible"))
    }
}
impl stripe_types::Object for Subscription {
    type Id = stripe_shared::SubscriptionId;
    fn id(&self) -> &Self::Id {
        &self.id
    }

    fn into_id(self) -> Self::Id {
        self.id
    }
}
stripe_types::def_id!(SubscriptionId);
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub enum SubscriptionCollectionMethod {
    ChargeAutomatically,
    SendInvoice,
    /// An unrecognized value from Stripe. Should not be used as a request parameter.
    Unknown(String),
}
impl SubscriptionCollectionMethod {
    pub fn as_str(&self) -> &str {
        use SubscriptionCollectionMethod::*;
        match self {
            ChargeAutomatically => "charge_automatically",
            SendInvoice => "send_invoice",
            Unknown(v) => v,
        }
    }
}

impl std::str::FromStr for SubscriptionCollectionMethod {
    type Err = std::convert::Infallible;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        use SubscriptionCollectionMethod::*;
        match s {
            "charge_automatically" => Ok(ChargeAutomatically),
            "send_invoice" => Ok(SendInvoice),
            v => {
                tracing::warn!(
                    "Unknown value '{}' for enum '{}'",
                    v,
                    "SubscriptionCollectionMethod"
                );
                Ok(Unknown(v.to_owned()))
            }
        }
    }
}
impl std::fmt::Display for SubscriptionCollectionMethod {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        f.write_str(self.as_str())
    }
}

#[cfg(not(feature = "redact-generated-debug"))]
impl std::fmt::Debug for SubscriptionCollectionMethod {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        f.write_str(self.as_str())
    }
}
#[cfg(feature = "redact-generated-debug")]
impl std::fmt::Debug for SubscriptionCollectionMethod {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        f.debug_struct(stringify!(SubscriptionCollectionMethod)).finish_non_exhaustive()
    }
}
impl serde::Serialize for SubscriptionCollectionMethod {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}
impl miniserde::Deserialize for SubscriptionCollectionMethod {
    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
        crate::Place::new(out)
    }
}

impl miniserde::de::Visitor for crate::Place<SubscriptionCollectionMethod> {
    fn string(&mut self, s: &str) -> miniserde::Result<()> {
        use std::str::FromStr;
        self.out = Some(SubscriptionCollectionMethod::from_str(s).expect("infallible"));
        Ok(())
    }
}

stripe_types::impl_from_val_with_from_str!(SubscriptionCollectionMethod);
#[cfg(feature = "deserialize")]
impl<'de> serde::Deserialize<'de> for SubscriptionCollectionMethod {
    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        use std::str::FromStr;
        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
        Ok(Self::from_str(&s).expect("infallible"))
    }
}