stripe_shared/
customer.rs

1/// This object represents a customer of your business.
2/// Use it to [create recurring charges](https://stripe.com/docs/invoicing/customer), [save payment](https://stripe.com/docs/payments/save-during-payment) and contact information,.
3/// and track payments that belong to the same customer.
4///
5/// For more details see <<https://stripe.com/docs/api/customers/object>>.
6#[derive(Clone, Debug)]
7#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
8pub struct Customer {
9    /// The customer's address.
10    pub address: Option<stripe_shared::Address>,
11    /// The current balance, if any, that's stored on the customer in their default currency.
12    /// If negative, the customer has credit to apply to their next invoice.
13    /// If positive, the customer has an amount owed that's added to their next invoice.
14    /// The balance only considers amounts that Stripe hasn't successfully applied to any invoice.
15    /// It doesn't reflect unpaid invoices.
16    /// This balance is only taken into account after invoices finalize.
17    /// For multi-currency balances, see [invoice_credit_balance](https://stripe.com/docs/api/customers/object#customer_object-invoice_credit_balance).
18    pub balance: Option<i64>,
19    /// The current funds being held by Stripe on behalf of the customer.
20    /// You can apply these funds towards payment intents when the source is "cash_balance".
21    /// The `settings[reconciliation_mode]` field describes if these funds apply to these payment intents manually or automatically.
22    pub cash_balance: Option<stripe_shared::CashBalance>,
23    /// Time at which the object was created. Measured in seconds since the Unix epoch.
24    pub created: stripe_types::Timestamp,
25    /// Three-letter [ISO code for the currency](https://stripe.com/docs/currencies) the customer can be charged in for recurring billing purposes.
26    pub currency: Option<stripe_types::Currency>,
27    /// ID of the default payment source for the customer.
28    ///
29    /// If you use payment methods created through the PaymentMethods API, see the [invoice_settings.default_payment_method](https://stripe.com/docs/api/customers/object#customer_object-invoice_settings-default_payment_method) field instead.
30    pub default_source: Option<stripe_types::Expandable<stripe_shared::PaymentSource>>,
31    /// Tracks the most recent state change on any invoice belonging to the customer.
32    /// Paying an invoice or marking it uncollectible via the API will set this field to false.
33    /// An automatic payment failure or passing the `invoice.due_date` will set this field to `true`.
34    ///
35    /// If an invoice becomes uncollectible by [dunning](https://stripe.com/docs/billing/automatic-collection), `delinquent` doesn't reset to `false`.
36    ///
37    /// If you care whether the customer has paid their most recent subscription invoice, use `subscription.status` instead.
38    /// Paying or marking uncollectible any customer invoice regardless of whether it is the latest invoice for a subscription will always set this field to `false`.
39    pub delinquent: Option<bool>,
40    /// An arbitrary string attached to the object. Often useful for displaying to users.
41    pub description: Option<String>,
42    /// Describes the current discount active on the customer, if there is one.
43    pub discount: Option<stripe_shared::Discount>,
44    /// The customer's email address.
45    pub email: Option<String>,
46    /// Unique identifier for the object.
47    pub id: stripe_shared::CustomerId,
48    /// The current multi-currency balances, if any, that's stored on the customer.
49    /// If positive in a currency, the customer has a credit to apply to their next invoice denominated in that currency.
50    /// If negative, the customer has an amount owed that's added to their next invoice denominated in that currency.
51    /// These balances don't apply to unpaid invoices.
52    /// They solely track amounts that Stripe hasn't successfully applied to any invoice.
53    /// Stripe only applies a balance in a specific currency to an invoice after that invoice (which is in the same currency) finalizes.
54    pub invoice_credit_balance: Option<std::collections::HashMap<String, i64>>,
55    /// The prefix for the customer used to generate unique invoice numbers.
56    pub invoice_prefix: Option<String>,
57    pub invoice_settings: Option<stripe_shared::InvoiceSettingCustomerSetting>,
58    /// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
59    pub livemode: bool,
60    /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
61    /// This can be useful for storing additional information about the object in a structured format.
62    pub metadata: Option<std::collections::HashMap<String, String>>,
63    /// The customer's full name or business name.
64    pub name: Option<String>,
65    /// The suffix of the customer's next invoice number (for example, 0001).
66    /// When the account uses account level sequencing, this parameter is ignored in API requests and the field omitted in API responses.
67    pub next_invoice_sequence: Option<i64>,
68    /// The customer's phone number.
69    pub phone: Option<String>,
70    /// The customer's preferred locales (languages), ordered by preference.
71    pub preferred_locales: Option<Vec<String>>,
72    /// Mailing and shipping address for the customer. Appears on invoices emailed to this customer.
73    pub shipping: Option<stripe_shared::Shipping>,
74    /// The customer's payment sources, if any.
75    pub sources: Option<stripe_types::List<stripe_shared::PaymentSource>>,
76    /// The customer's current subscriptions, if any.
77    pub subscriptions: Option<stripe_types::List<stripe_shared::Subscription>>,
78    pub tax: Option<stripe_shared::CustomerTax>,
79    /// Describes the customer's tax exemption status, which is `none`, `exempt`, or `reverse`.
80    /// When set to `reverse`, invoice and receipt PDFs include the following text: **"Reverse charge"**.
81    pub tax_exempt: Option<stripe_shared::CustomerTaxExempt>,
82    /// The customer's tax IDs.
83    pub tax_ids: Option<stripe_types::List<stripe_shared::TaxId>>,
84    /// ID of the test clock that this customer belongs to.
85    pub test_clock: Option<stripe_types::Expandable<stripe_shared::TestHelpersTestClock>>,
86}
87#[doc(hidden)]
88pub struct CustomerBuilder {
89    address: Option<Option<stripe_shared::Address>>,
90    balance: Option<Option<i64>>,
91    cash_balance: Option<Option<stripe_shared::CashBalance>>,
92    created: Option<stripe_types::Timestamp>,
93    currency: Option<Option<stripe_types::Currency>>,
94    default_source: Option<Option<stripe_types::Expandable<stripe_shared::PaymentSource>>>,
95    delinquent: Option<Option<bool>>,
96    description: Option<Option<String>>,
97    discount: Option<Option<stripe_shared::Discount>>,
98    email: Option<Option<String>>,
99    id: Option<stripe_shared::CustomerId>,
100    invoice_credit_balance: Option<Option<std::collections::HashMap<String, i64>>>,
101    invoice_prefix: Option<Option<String>>,
102    invoice_settings: Option<Option<stripe_shared::InvoiceSettingCustomerSetting>>,
103    livemode: Option<bool>,
104    metadata: Option<Option<std::collections::HashMap<String, String>>>,
105    name: Option<Option<String>>,
106    next_invoice_sequence: Option<Option<i64>>,
107    phone: Option<Option<String>>,
108    preferred_locales: Option<Option<Vec<String>>>,
109    shipping: Option<Option<stripe_shared::Shipping>>,
110    sources: Option<Option<stripe_types::List<stripe_shared::PaymentSource>>>,
111    subscriptions: Option<Option<stripe_types::List<stripe_shared::Subscription>>>,
112    tax: Option<Option<stripe_shared::CustomerTax>>,
113    tax_exempt: Option<Option<stripe_shared::CustomerTaxExempt>>,
114    tax_ids: Option<Option<stripe_types::List<stripe_shared::TaxId>>>,
115    test_clock: Option<Option<stripe_types::Expandable<stripe_shared::TestHelpersTestClock>>>,
116}
117
118#[allow(
119    unused_variables,
120    irrefutable_let_patterns,
121    clippy::let_unit_value,
122    clippy::match_single_binding,
123    clippy::single_match
124)]
125const _: () = {
126    use miniserde::de::{Map, Visitor};
127    use miniserde::json::Value;
128    use miniserde::{make_place, Deserialize, Result};
129    use stripe_types::miniserde_helpers::FromValueOpt;
130    use stripe_types::{MapBuilder, ObjectDeser};
131
132    make_place!(Place);
133
134    impl Deserialize for Customer {
135        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
136            Place::new(out)
137        }
138    }
139
140    struct Builder<'a> {
141        out: &'a mut Option<Customer>,
142        builder: CustomerBuilder,
143    }
144
145    impl Visitor for Place<Customer> {
146        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
147            Ok(Box::new(Builder { out: &mut self.out, builder: CustomerBuilder::deser_default() }))
148        }
149    }
150
151    impl MapBuilder for CustomerBuilder {
152        type Out = Customer;
153        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
154            Ok(match k {
155                "address" => Deserialize::begin(&mut self.address),
156                "balance" => Deserialize::begin(&mut self.balance),
157                "cash_balance" => Deserialize::begin(&mut self.cash_balance),
158                "created" => Deserialize::begin(&mut self.created),
159                "currency" => Deserialize::begin(&mut self.currency),
160                "default_source" => Deserialize::begin(&mut self.default_source),
161                "delinquent" => Deserialize::begin(&mut self.delinquent),
162                "description" => Deserialize::begin(&mut self.description),
163                "discount" => Deserialize::begin(&mut self.discount),
164                "email" => Deserialize::begin(&mut self.email),
165                "id" => Deserialize::begin(&mut self.id),
166                "invoice_credit_balance" => Deserialize::begin(&mut self.invoice_credit_balance),
167                "invoice_prefix" => Deserialize::begin(&mut self.invoice_prefix),
168                "invoice_settings" => Deserialize::begin(&mut self.invoice_settings),
169                "livemode" => Deserialize::begin(&mut self.livemode),
170                "metadata" => Deserialize::begin(&mut self.metadata),
171                "name" => Deserialize::begin(&mut self.name),
172                "next_invoice_sequence" => Deserialize::begin(&mut self.next_invoice_sequence),
173                "phone" => Deserialize::begin(&mut self.phone),
174                "preferred_locales" => Deserialize::begin(&mut self.preferred_locales),
175                "shipping" => Deserialize::begin(&mut self.shipping),
176                "sources" => Deserialize::begin(&mut self.sources),
177                "subscriptions" => Deserialize::begin(&mut self.subscriptions),
178                "tax" => Deserialize::begin(&mut self.tax),
179                "tax_exempt" => Deserialize::begin(&mut self.tax_exempt),
180                "tax_ids" => Deserialize::begin(&mut self.tax_ids),
181                "test_clock" => Deserialize::begin(&mut self.test_clock),
182
183                _ => <dyn Visitor>::ignore(),
184            })
185        }
186
187        fn deser_default() -> Self {
188            Self {
189                address: Deserialize::default(),
190                balance: Deserialize::default(),
191                cash_balance: Deserialize::default(),
192                created: Deserialize::default(),
193                currency: Deserialize::default(),
194                default_source: Deserialize::default(),
195                delinquent: Deserialize::default(),
196                description: Deserialize::default(),
197                discount: Deserialize::default(),
198                email: Deserialize::default(),
199                id: Deserialize::default(),
200                invoice_credit_balance: Deserialize::default(),
201                invoice_prefix: Deserialize::default(),
202                invoice_settings: Deserialize::default(),
203                livemode: Deserialize::default(),
204                metadata: Deserialize::default(),
205                name: Deserialize::default(),
206                next_invoice_sequence: Deserialize::default(),
207                phone: Deserialize::default(),
208                preferred_locales: Deserialize::default(),
209                shipping: Deserialize::default(),
210                sources: Deserialize::default(),
211                subscriptions: Deserialize::default(),
212                tax: Deserialize::default(),
213                tax_exempt: Deserialize::default(),
214                tax_ids: Deserialize::default(),
215                test_clock: Deserialize::default(),
216            }
217        }
218
219        fn take_out(&mut self) -> Option<Self::Out> {
220            let (
221                Some(address),
222                Some(balance),
223                Some(cash_balance),
224                Some(created),
225                Some(currency),
226                Some(default_source),
227                Some(delinquent),
228                Some(description),
229                Some(discount),
230                Some(email),
231                Some(id),
232                Some(invoice_credit_balance),
233                Some(invoice_prefix),
234                Some(invoice_settings),
235                Some(livemode),
236                Some(metadata),
237                Some(name),
238                Some(next_invoice_sequence),
239                Some(phone),
240                Some(preferred_locales),
241                Some(shipping),
242                Some(sources),
243                Some(subscriptions),
244                Some(tax),
245                Some(tax_exempt),
246                Some(tax_ids),
247                Some(test_clock),
248            ) = (
249                self.address.take(),
250                self.balance,
251                self.cash_balance.take(),
252                self.created,
253                self.currency.take(),
254                self.default_source.take(),
255                self.delinquent,
256                self.description.take(),
257                self.discount.take(),
258                self.email.take(),
259                self.id.take(),
260                self.invoice_credit_balance.take(),
261                self.invoice_prefix.take(),
262                self.invoice_settings.take(),
263                self.livemode,
264                self.metadata.take(),
265                self.name.take(),
266                self.next_invoice_sequence,
267                self.phone.take(),
268                self.preferred_locales.take(),
269                self.shipping.take(),
270                self.sources.take(),
271                self.subscriptions.take(),
272                self.tax.take(),
273                self.tax_exempt,
274                self.tax_ids.take(),
275                self.test_clock.take(),
276            )
277            else {
278                return None;
279            };
280            Some(Self::Out {
281                address,
282                balance,
283                cash_balance,
284                created,
285                currency,
286                default_source,
287                delinquent,
288                description,
289                discount,
290                email,
291                id,
292                invoice_credit_balance,
293                invoice_prefix,
294                invoice_settings,
295                livemode,
296                metadata,
297                name,
298                next_invoice_sequence,
299                phone,
300                preferred_locales,
301                shipping,
302                sources,
303                subscriptions,
304                tax,
305                tax_exempt,
306                tax_ids,
307                test_clock,
308            })
309        }
310    }
311
312    impl Map for Builder<'_> {
313        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
314            self.builder.key(k)
315        }
316
317        fn finish(&mut self) -> Result<()> {
318            *self.out = self.builder.take_out();
319            Ok(())
320        }
321    }
322
323    impl ObjectDeser for Customer {
324        type Builder = CustomerBuilder;
325    }
326
327    impl FromValueOpt for Customer {
328        fn from_value(v: Value) -> Option<Self> {
329            let Value::Object(obj) = v else {
330                return None;
331            };
332            let mut b = CustomerBuilder::deser_default();
333            for (k, v) in obj {
334                match k.as_str() {
335                    "address" => b.address = FromValueOpt::from_value(v),
336                    "balance" => b.balance = FromValueOpt::from_value(v),
337                    "cash_balance" => b.cash_balance = FromValueOpt::from_value(v),
338                    "created" => b.created = FromValueOpt::from_value(v),
339                    "currency" => b.currency = FromValueOpt::from_value(v),
340                    "default_source" => b.default_source = FromValueOpt::from_value(v),
341                    "delinquent" => b.delinquent = FromValueOpt::from_value(v),
342                    "description" => b.description = FromValueOpt::from_value(v),
343                    "discount" => b.discount = FromValueOpt::from_value(v),
344                    "email" => b.email = FromValueOpt::from_value(v),
345                    "id" => b.id = FromValueOpt::from_value(v),
346                    "invoice_credit_balance" => {
347                        b.invoice_credit_balance = FromValueOpt::from_value(v)
348                    }
349                    "invoice_prefix" => b.invoice_prefix = FromValueOpt::from_value(v),
350                    "invoice_settings" => b.invoice_settings = FromValueOpt::from_value(v),
351                    "livemode" => b.livemode = FromValueOpt::from_value(v),
352                    "metadata" => b.metadata = FromValueOpt::from_value(v),
353                    "name" => b.name = FromValueOpt::from_value(v),
354                    "next_invoice_sequence" => {
355                        b.next_invoice_sequence = FromValueOpt::from_value(v)
356                    }
357                    "phone" => b.phone = FromValueOpt::from_value(v),
358                    "preferred_locales" => b.preferred_locales = FromValueOpt::from_value(v),
359                    "shipping" => b.shipping = FromValueOpt::from_value(v),
360                    "sources" => b.sources = FromValueOpt::from_value(v),
361                    "subscriptions" => b.subscriptions = FromValueOpt::from_value(v),
362                    "tax" => b.tax = FromValueOpt::from_value(v),
363                    "tax_exempt" => b.tax_exempt = FromValueOpt::from_value(v),
364                    "tax_ids" => b.tax_ids = FromValueOpt::from_value(v),
365                    "test_clock" => b.test_clock = FromValueOpt::from_value(v),
366
367                    _ => {}
368                }
369            }
370            b.take_out()
371        }
372    }
373};
374#[cfg(feature = "serialize")]
375impl serde::Serialize for Customer {
376    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
377        use serde::ser::SerializeStruct;
378        let mut s = s.serialize_struct("Customer", 28)?;
379        s.serialize_field("address", &self.address)?;
380        s.serialize_field("balance", &self.balance)?;
381        s.serialize_field("cash_balance", &self.cash_balance)?;
382        s.serialize_field("created", &self.created)?;
383        s.serialize_field("currency", &self.currency)?;
384        s.serialize_field("default_source", &self.default_source)?;
385        s.serialize_field("delinquent", &self.delinquent)?;
386        s.serialize_field("description", &self.description)?;
387        s.serialize_field("discount", &self.discount)?;
388        s.serialize_field("email", &self.email)?;
389        s.serialize_field("id", &self.id)?;
390        s.serialize_field("invoice_credit_balance", &self.invoice_credit_balance)?;
391        s.serialize_field("invoice_prefix", &self.invoice_prefix)?;
392        s.serialize_field("invoice_settings", &self.invoice_settings)?;
393        s.serialize_field("livemode", &self.livemode)?;
394        s.serialize_field("metadata", &self.metadata)?;
395        s.serialize_field("name", &self.name)?;
396        s.serialize_field("next_invoice_sequence", &self.next_invoice_sequence)?;
397        s.serialize_field("phone", &self.phone)?;
398        s.serialize_field("preferred_locales", &self.preferred_locales)?;
399        s.serialize_field("shipping", &self.shipping)?;
400        s.serialize_field("sources", &self.sources)?;
401        s.serialize_field("subscriptions", &self.subscriptions)?;
402        s.serialize_field("tax", &self.tax)?;
403        s.serialize_field("tax_exempt", &self.tax_exempt)?;
404        s.serialize_field("tax_ids", &self.tax_ids)?;
405        s.serialize_field("test_clock", &self.test_clock)?;
406
407        s.serialize_field("object", "customer")?;
408        s.end()
409    }
410}
411impl stripe_types::Object for Customer {
412    type Id = stripe_shared::CustomerId;
413    fn id(&self) -> &Self::Id {
414        &self.id
415    }
416
417    fn into_id(self) -> Self::Id {
418        self.id
419    }
420}
421stripe_types::def_id!(CustomerId);
422#[derive(Copy, Clone, Eq, PartialEq)]
423pub enum CustomerTaxExempt {
424    Exempt,
425    None,
426    Reverse,
427}
428impl CustomerTaxExempt {
429    pub fn as_str(self) -> &'static str {
430        use CustomerTaxExempt::*;
431        match self {
432            Exempt => "exempt",
433            None => "none",
434            Reverse => "reverse",
435        }
436    }
437}
438
439impl std::str::FromStr for CustomerTaxExempt {
440    type Err = stripe_types::StripeParseError;
441    fn from_str(s: &str) -> Result<Self, Self::Err> {
442        use CustomerTaxExempt::*;
443        match s {
444            "exempt" => Ok(Exempt),
445            "none" => Ok(None),
446            "reverse" => Ok(Reverse),
447            _ => Err(stripe_types::StripeParseError),
448        }
449    }
450}
451impl std::fmt::Display for CustomerTaxExempt {
452    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
453        f.write_str(self.as_str())
454    }
455}
456
457impl std::fmt::Debug for CustomerTaxExempt {
458    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
459        f.write_str(self.as_str())
460    }
461}
462impl serde::Serialize for CustomerTaxExempt {
463    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
464    where
465        S: serde::Serializer,
466    {
467        serializer.serialize_str(self.as_str())
468    }
469}
470impl miniserde::Deserialize for CustomerTaxExempt {
471    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
472        crate::Place::new(out)
473    }
474}
475
476impl miniserde::de::Visitor for crate::Place<CustomerTaxExempt> {
477    fn string(&mut self, s: &str) -> miniserde::Result<()> {
478        use std::str::FromStr;
479        self.out = Some(CustomerTaxExempt::from_str(s).map_err(|_| miniserde::Error)?);
480        Ok(())
481    }
482}
483
484stripe_types::impl_from_val_with_from_str!(CustomerTaxExempt);
485#[cfg(feature = "deserialize")]
486impl<'de> serde::Deserialize<'de> for CustomerTaxExempt {
487    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
488        use std::str::FromStr;
489        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
490        Self::from_str(&s)
491            .map_err(|_| serde::de::Error::custom("Unknown value for CustomerTaxExempt"))
492    }
493}