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