Skip to main content

stripe_payment/card/
requests.rs

1use stripe_client_core::{
2    RequestBuilder, StripeBlockingClient, StripeClient, StripeMethod, StripeRequest,
3};
4
5/// Delete a specified external account for a given account.
6#[derive(Clone)]
7#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
8#[derive(serde::Serialize)]
9pub struct DeleteAccountCard {
10    account: stripe_shared::AccountId,
11    id: String,
12}
13#[cfg(feature = "redact-generated-debug")]
14impl std::fmt::Debug for DeleteAccountCard {
15    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
16        f.debug_struct("DeleteAccountCard").finish_non_exhaustive()
17    }
18}
19impl DeleteAccountCard {
20    /// Construct a new `DeleteAccountCard`.
21    pub fn new(account: impl Into<stripe_shared::AccountId>, id: impl Into<String>) -> Self {
22        Self { account: account.into(), id: id.into() }
23    }
24}
25impl DeleteAccountCard {
26    /// Send the request and return the deserialized response.
27    pub async fn send<C: StripeClient>(
28        &self,
29        client: &C,
30    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
31        self.customize().send(client).await
32    }
33
34    /// Send the request and return the deserialized response, blocking until completion.
35    pub fn send_blocking<C: StripeBlockingClient>(
36        &self,
37        client: &C,
38    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
39        self.customize().send_blocking(client)
40    }
41}
42
43impl StripeRequest for DeleteAccountCard {
44    type Output = stripe_shared::DeletedExternalAccount;
45
46    fn build(&self) -> RequestBuilder {
47        let account = &self.account;
48        let id = &self.id;
49        RequestBuilder::new(
50            StripeMethod::Delete,
51            format!("/accounts/{account}/external_accounts/{id}"),
52        )
53    }
54}
55#[derive(Clone, Eq, PartialEq)]
56#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
57#[derive(serde::Serialize)]
58struct DeleteCustomerCardBuilder {
59    #[serde(skip_serializing_if = "Option::is_none")]
60    expand: Option<Vec<String>>,
61}
62#[cfg(feature = "redact-generated-debug")]
63impl std::fmt::Debug for DeleteCustomerCardBuilder {
64    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
65        f.debug_struct("DeleteCustomerCardBuilder").finish_non_exhaustive()
66    }
67}
68impl DeleteCustomerCardBuilder {
69    fn new() -> Self {
70        Self { expand: None }
71    }
72}
73/// Delete a specified source for a given customer.
74#[derive(Clone)]
75#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
76#[derive(serde::Serialize)]
77pub struct DeleteCustomerCard {
78    inner: DeleteCustomerCardBuilder,
79    customer: stripe_shared::CustomerId,
80    id: String,
81}
82#[cfg(feature = "redact-generated-debug")]
83impl std::fmt::Debug for DeleteCustomerCard {
84    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
85        f.debug_struct("DeleteCustomerCard").finish_non_exhaustive()
86    }
87}
88impl DeleteCustomerCard {
89    /// Construct a new `DeleteCustomerCard`.
90    pub fn new(customer: impl Into<stripe_shared::CustomerId>, id: impl Into<String>) -> Self {
91        Self { customer: customer.into(), id: id.into(), inner: DeleteCustomerCardBuilder::new() }
92    }
93    /// Specifies which fields in the response should be expanded.
94    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
95        self.inner.expand = Some(expand.into());
96        self
97    }
98}
99impl DeleteCustomerCard {
100    /// Send the request and return the deserialized response.
101    pub async fn send<C: StripeClient>(
102        &self,
103        client: &C,
104    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
105        self.customize().send(client).await
106    }
107
108    /// Send the request and return the deserialized response, blocking until completion.
109    pub fn send_blocking<C: StripeBlockingClient>(
110        &self,
111        client: &C,
112    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
113        self.customize().send_blocking(client)
114    }
115}
116
117impl StripeRequest for DeleteCustomerCard {
118    type Output = DeleteCustomerCardReturned;
119
120    fn build(&self) -> RequestBuilder {
121        let customer = &self.customer;
122        let id = &self.id;
123        RequestBuilder::new(StripeMethod::Delete, format!("/customers/{customer}/sources/{id}"))
124            .form(&self.inner)
125    }
126}
127#[derive(Clone)]
128#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
129#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
130#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
131#[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(untagged))]
132pub enum DeleteCustomerCardReturned {
133    PaymentSource(stripe_shared::PaymentSource),
134    DeletedPaymentSource(stripe_shared::DeletedPaymentSource),
135}
136
137#[derive(Default)]
138pub struct DeleteCustomerCardReturnedBuilder {
139    inner: stripe_types::miniserde_helpers::MaybeDeletedBuilderInner,
140}
141
142const _: () = {
143    use miniserde::de::{Map, Visitor};
144    use miniserde::json::Value;
145    use miniserde::{Deserialize, Result, make_place};
146    use stripe_types::MapBuilder;
147    use stripe_types::miniserde_helpers::FromValueOpt;
148
149    use super::*;
150
151    make_place!(Place);
152
153    struct Builder<'a> {
154        out: &'a mut Option<DeleteCustomerCardReturned>,
155        builder: DeleteCustomerCardReturnedBuilder,
156    }
157
158    impl Deserialize for DeleteCustomerCardReturned {
159        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
160            Place::new(out)
161        }
162    }
163
164    impl Visitor for Place<DeleteCustomerCardReturned> {
165        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
166            Ok(Box::new(Builder { out: &mut self.out, builder: Default::default() }))
167        }
168    }
169
170    impl Map for Builder<'_> {
171        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
172            self.builder.key(k)
173        }
174
175        fn finish(&mut self) -> Result<()> {
176            *self.out = self.builder.take_out();
177            Ok(())
178        }
179    }
180
181    impl MapBuilder for DeleteCustomerCardReturnedBuilder {
182        type Out = DeleteCustomerCardReturned;
183        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
184            self.inner.key_inner(k)
185        }
186
187        fn deser_default() -> Self {
188            Self::default()
189        }
190
191        fn take_out(&mut self) -> Option<Self::Out> {
192            let (deleted, o) = self.inner.finish_inner()?;
193            Some(if deleted {
194                DeleteCustomerCardReturned::DeletedPaymentSource(FromValueOpt::from_value(
195                    Value::Object(o),
196                )?)
197            } else {
198                DeleteCustomerCardReturned::PaymentSource(FromValueOpt::from_value(Value::Object(
199                    o,
200                ))?)
201            })
202        }
203    }
204
205    impl stripe_types::ObjectDeser for DeleteCustomerCardReturned {
206        type Builder = DeleteCustomerCardReturnedBuilder;
207    }
208};
209
210#[cfg(feature = "redact-generated-debug")]
211impl std::fmt::Debug for DeleteCustomerCardReturned {
212    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
213        f.debug_struct("DeleteCustomerCardReturned").finish_non_exhaustive()
214    }
215}
216#[derive(Clone)]
217#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
218#[derive(serde::Serialize)]
219struct UpdateAccountCardBuilder {
220    #[serde(skip_serializing_if = "Option::is_none")]
221    account_holder_name: Option<String>,
222    #[serde(skip_serializing_if = "Option::is_none")]
223    account_holder_type: Option<UpdateAccountCardAccountHolderType>,
224    #[serde(skip_serializing_if = "Option::is_none")]
225    account_type: Option<UpdateAccountCardAccountType>,
226    #[serde(skip_serializing_if = "Option::is_none")]
227    address_city: Option<String>,
228    #[serde(skip_serializing_if = "Option::is_none")]
229    address_country: Option<String>,
230    #[serde(skip_serializing_if = "Option::is_none")]
231    address_line1: Option<String>,
232    #[serde(skip_serializing_if = "Option::is_none")]
233    address_line2: Option<String>,
234    #[serde(skip_serializing_if = "Option::is_none")]
235    address_state: Option<String>,
236    #[serde(skip_serializing_if = "Option::is_none")]
237    address_zip: Option<String>,
238    #[serde(skip_serializing_if = "Option::is_none")]
239    default_for_currency: Option<bool>,
240    #[serde(skip_serializing_if = "Option::is_none")]
241    documents: Option<UpdateAccountCardDocuments>,
242    #[serde(skip_serializing_if = "Option::is_none")]
243    exp_month: Option<String>,
244    #[serde(skip_serializing_if = "Option::is_none")]
245    exp_year: Option<String>,
246    #[serde(skip_serializing_if = "Option::is_none")]
247    expand: Option<Vec<String>>,
248    #[serde(skip_serializing_if = "Option::is_none")]
249    metadata: Option<std::collections::HashMap<String, String>>,
250    #[serde(skip_serializing_if = "Option::is_none")]
251    name: Option<String>,
252}
253#[cfg(feature = "redact-generated-debug")]
254impl std::fmt::Debug for UpdateAccountCardBuilder {
255    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
256        f.debug_struct("UpdateAccountCardBuilder").finish_non_exhaustive()
257    }
258}
259impl UpdateAccountCardBuilder {
260    fn new() -> Self {
261        Self {
262            account_holder_name: None,
263            account_holder_type: None,
264            account_type: None,
265            address_city: None,
266            address_country: None,
267            address_line1: None,
268            address_line2: None,
269            address_state: None,
270            address_zip: None,
271            default_for_currency: None,
272            documents: None,
273            exp_month: None,
274            exp_year: None,
275            expand: None,
276            metadata: None,
277            name: None,
278        }
279    }
280}
281/// The type of entity that holds the account. This can be either `individual` or `company`.
282#[derive(Clone, Eq, PartialEq)]
283#[non_exhaustive]
284pub enum UpdateAccountCardAccountHolderType {
285    Company,
286    Individual,
287    /// An unrecognized value from Stripe. Should not be used as a request parameter.
288    Unknown(String),
289}
290impl UpdateAccountCardAccountHolderType {
291    pub fn as_str(&self) -> &str {
292        use UpdateAccountCardAccountHolderType::*;
293        match self {
294            Company => "company",
295            Individual => "individual",
296            Unknown(v) => v,
297        }
298    }
299}
300
301impl std::str::FromStr for UpdateAccountCardAccountHolderType {
302    type Err = std::convert::Infallible;
303    fn from_str(s: &str) -> Result<Self, Self::Err> {
304        use UpdateAccountCardAccountHolderType::*;
305        match s {
306            "company" => Ok(Company),
307            "individual" => Ok(Individual),
308            v => {
309                tracing::warn!(
310                    "Unknown value '{}' for enum '{}'",
311                    v,
312                    "UpdateAccountCardAccountHolderType"
313                );
314                Ok(Unknown(v.to_owned()))
315            }
316        }
317    }
318}
319impl std::fmt::Display for UpdateAccountCardAccountHolderType {
320    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
321        f.write_str(self.as_str())
322    }
323}
324
325#[cfg(not(feature = "redact-generated-debug"))]
326impl std::fmt::Debug for UpdateAccountCardAccountHolderType {
327    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
328        f.write_str(self.as_str())
329    }
330}
331#[cfg(feature = "redact-generated-debug")]
332impl std::fmt::Debug for UpdateAccountCardAccountHolderType {
333    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
334        f.debug_struct(stringify!(UpdateAccountCardAccountHolderType)).finish_non_exhaustive()
335    }
336}
337impl serde::Serialize for UpdateAccountCardAccountHolderType {
338    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
339    where
340        S: serde::Serializer,
341    {
342        serializer.serialize_str(self.as_str())
343    }
344}
345#[cfg(feature = "deserialize")]
346impl<'de> serde::Deserialize<'de> for UpdateAccountCardAccountHolderType {
347    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
348        use std::str::FromStr;
349        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
350        Ok(Self::from_str(&s).expect("infallible"))
351    }
352}
353/// The bank account type.
354/// This can only be `checking` or `savings` in most countries.
355/// In Japan, this can only be `futsu` or `toza`.
356#[derive(Clone, Eq, PartialEq)]
357#[non_exhaustive]
358pub enum UpdateAccountCardAccountType {
359    Checking,
360    Futsu,
361    Savings,
362    Toza,
363    /// An unrecognized value from Stripe. Should not be used as a request parameter.
364    Unknown(String),
365}
366impl UpdateAccountCardAccountType {
367    pub fn as_str(&self) -> &str {
368        use UpdateAccountCardAccountType::*;
369        match self {
370            Checking => "checking",
371            Futsu => "futsu",
372            Savings => "savings",
373            Toza => "toza",
374            Unknown(v) => v,
375        }
376    }
377}
378
379impl std::str::FromStr for UpdateAccountCardAccountType {
380    type Err = std::convert::Infallible;
381    fn from_str(s: &str) -> Result<Self, Self::Err> {
382        use UpdateAccountCardAccountType::*;
383        match s {
384            "checking" => Ok(Checking),
385            "futsu" => Ok(Futsu),
386            "savings" => Ok(Savings),
387            "toza" => Ok(Toza),
388            v => {
389                tracing::warn!(
390                    "Unknown value '{}' for enum '{}'",
391                    v,
392                    "UpdateAccountCardAccountType"
393                );
394                Ok(Unknown(v.to_owned()))
395            }
396        }
397    }
398}
399impl std::fmt::Display for UpdateAccountCardAccountType {
400    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
401        f.write_str(self.as_str())
402    }
403}
404
405#[cfg(not(feature = "redact-generated-debug"))]
406impl std::fmt::Debug for UpdateAccountCardAccountType {
407    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
408        f.write_str(self.as_str())
409    }
410}
411#[cfg(feature = "redact-generated-debug")]
412impl std::fmt::Debug for UpdateAccountCardAccountType {
413    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
414        f.debug_struct(stringify!(UpdateAccountCardAccountType)).finish_non_exhaustive()
415    }
416}
417impl serde::Serialize for UpdateAccountCardAccountType {
418    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
419    where
420        S: serde::Serializer,
421    {
422        serializer.serialize_str(self.as_str())
423    }
424}
425#[cfg(feature = "deserialize")]
426impl<'de> serde::Deserialize<'de> for UpdateAccountCardAccountType {
427    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
428        use std::str::FromStr;
429        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
430        Ok(Self::from_str(&s).expect("infallible"))
431    }
432}
433/// Documents that may be submitted to satisfy various informational requests.
434#[derive(Clone, Eq, PartialEq)]
435#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
436#[derive(serde::Serialize)]
437pub struct UpdateAccountCardDocuments {
438    /// One or more documents that support the [Bank account ownership verification](https://support.stripe.com/questions/bank-account-ownership-verification) requirement.
439    /// Must be a document associated with the bank account that displays the last 4 digits of the account number, either a statement or a check.
440    #[serde(skip_serializing_if = "Option::is_none")]
441    pub bank_account_ownership_verification:
442        Option<UpdateAccountCardDocumentsBankAccountOwnershipVerification>,
443}
444#[cfg(feature = "redact-generated-debug")]
445impl std::fmt::Debug for UpdateAccountCardDocuments {
446    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
447        f.debug_struct("UpdateAccountCardDocuments").finish_non_exhaustive()
448    }
449}
450impl UpdateAccountCardDocuments {
451    pub fn new() -> Self {
452        Self { bank_account_ownership_verification: None }
453    }
454}
455impl Default for UpdateAccountCardDocuments {
456    fn default() -> Self {
457        Self::new()
458    }
459}
460/// One or more documents that support the [Bank account ownership verification](https://support.stripe.com/questions/bank-account-ownership-verification) requirement.
461/// Must be a document associated with the bank account that displays the last 4 digits of the account number, either a statement or a check.
462#[derive(Clone, Eq, PartialEq)]
463#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
464#[derive(serde::Serialize)]
465pub struct UpdateAccountCardDocumentsBankAccountOwnershipVerification {
466    /// One or more document ids returned by a [file upload](https://api.stripe.com#create_file) with a `purpose` value of `account_requirement`.
467    #[serde(skip_serializing_if = "Option::is_none")]
468    pub files: Option<Vec<String>>,
469}
470#[cfg(feature = "redact-generated-debug")]
471impl std::fmt::Debug for UpdateAccountCardDocumentsBankAccountOwnershipVerification {
472    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
473        f.debug_struct("UpdateAccountCardDocumentsBankAccountOwnershipVerification")
474            .finish_non_exhaustive()
475    }
476}
477impl UpdateAccountCardDocumentsBankAccountOwnershipVerification {
478    pub fn new() -> Self {
479        Self { files: None }
480    }
481}
482impl Default for UpdateAccountCardDocumentsBankAccountOwnershipVerification {
483    fn default() -> Self {
484        Self::new()
485    }
486}
487/// Updates the metadata, account holder name, account holder type of a bank account belonging to
488/// a connected account and optionally sets it as the default for its currency. Other bank account
489/// details are not editable by design.
490///
491/// You can only update bank accounts when <a href="/api/accounts/object#account_object-controller-requirement_collection">account.controller.requirement_collection</a> is `application`, which includes <a href="/connect/custom-accounts">Custom accounts</a>.
492///
493/// You can re-enable a disabled bank account by performing an update call without providing any
494/// arguments or changes.
495#[derive(Clone)]
496#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
497#[derive(serde::Serialize)]
498pub struct UpdateAccountCard {
499    inner: UpdateAccountCardBuilder,
500    account: stripe_shared::AccountId,
501    id: String,
502}
503#[cfg(feature = "redact-generated-debug")]
504impl std::fmt::Debug for UpdateAccountCard {
505    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
506        f.debug_struct("UpdateAccountCard").finish_non_exhaustive()
507    }
508}
509impl UpdateAccountCard {
510    /// Construct a new `UpdateAccountCard`.
511    pub fn new(account: impl Into<stripe_shared::AccountId>, id: impl Into<String>) -> Self {
512        Self { account: account.into(), id: id.into(), inner: UpdateAccountCardBuilder::new() }
513    }
514    /// The name of the person or business that owns the bank account.
515    pub fn account_holder_name(mut self, account_holder_name: impl Into<String>) -> Self {
516        self.inner.account_holder_name = Some(account_holder_name.into());
517        self
518    }
519    /// The type of entity that holds the account. This can be either `individual` or `company`.
520    pub fn account_holder_type(
521        mut self,
522        account_holder_type: impl Into<UpdateAccountCardAccountHolderType>,
523    ) -> Self {
524        self.inner.account_holder_type = Some(account_holder_type.into());
525        self
526    }
527    /// The bank account type.
528    /// This can only be `checking` or `savings` in most countries.
529    /// In Japan, this can only be `futsu` or `toza`.
530    pub fn account_type(mut self, account_type: impl Into<UpdateAccountCardAccountType>) -> Self {
531        self.inner.account_type = Some(account_type.into());
532        self
533    }
534    /// City/District/Suburb/Town/Village.
535    pub fn address_city(mut self, address_city: impl Into<String>) -> Self {
536        self.inner.address_city = Some(address_city.into());
537        self
538    }
539    /// Billing address country, if provided when creating card.
540    pub fn address_country(mut self, address_country: impl Into<String>) -> Self {
541        self.inner.address_country = Some(address_country.into());
542        self
543    }
544    /// Address line 1 (Street address/PO Box/Company name).
545    pub fn address_line1(mut self, address_line1: impl Into<String>) -> Self {
546        self.inner.address_line1 = Some(address_line1.into());
547        self
548    }
549    /// Address line 2 (Apartment/Suite/Unit/Building).
550    pub fn address_line2(mut self, address_line2: impl Into<String>) -> Self {
551        self.inner.address_line2 = Some(address_line2.into());
552        self
553    }
554    /// State/County/Province/Region.
555    pub fn address_state(mut self, address_state: impl Into<String>) -> Self {
556        self.inner.address_state = Some(address_state.into());
557        self
558    }
559    /// ZIP or postal code.
560    pub fn address_zip(mut self, address_zip: impl Into<String>) -> Self {
561        self.inner.address_zip = Some(address_zip.into());
562        self
563    }
564    /// When set to true, this becomes the default external account for its currency.
565    pub fn default_for_currency(mut self, default_for_currency: impl Into<bool>) -> Self {
566        self.inner.default_for_currency = Some(default_for_currency.into());
567        self
568    }
569    /// Documents that may be submitted to satisfy various informational requests.
570    pub fn documents(mut self, documents: impl Into<UpdateAccountCardDocuments>) -> Self {
571        self.inner.documents = Some(documents.into());
572        self
573    }
574    /// Two digit number representing the card’s expiration month.
575    pub fn exp_month(mut self, exp_month: impl Into<String>) -> Self {
576        self.inner.exp_month = Some(exp_month.into());
577        self
578    }
579    /// Four digit number representing the card’s expiration year.
580    pub fn exp_year(mut self, exp_year: impl Into<String>) -> Self {
581        self.inner.exp_year = Some(exp_year.into());
582        self
583    }
584    /// Specifies which fields in the response should be expanded.
585    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
586        self.inner.expand = Some(expand.into());
587        self
588    }
589    /// Set of [key-value pairs](https://docs.stripe.com/api/metadata) that you can attach to an object.
590    /// This can be useful for storing additional information about the object in a structured format.
591    /// Individual keys can be unset by posting an empty value to them.
592    /// All keys can be unset by posting an empty value to `metadata`.
593    pub fn metadata(
594        mut self,
595        metadata: impl Into<std::collections::HashMap<String, String>>,
596    ) -> Self {
597        self.inner.metadata = Some(metadata.into());
598        self
599    }
600    /// Cardholder name.
601    pub fn name(mut self, name: impl Into<String>) -> Self {
602        self.inner.name = Some(name.into());
603        self
604    }
605}
606impl UpdateAccountCard {
607    /// Send the request and return the deserialized response.
608    pub async fn send<C: StripeClient>(
609        &self,
610        client: &C,
611    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
612        self.customize().send(client).await
613    }
614
615    /// Send the request and return the deserialized response, blocking until completion.
616    pub fn send_blocking<C: StripeBlockingClient>(
617        &self,
618        client: &C,
619    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
620        self.customize().send_blocking(client)
621    }
622}
623
624impl StripeRequest for UpdateAccountCard {
625    type Output = stripe_shared::ExternalAccount;
626
627    fn build(&self) -> RequestBuilder {
628        let account = &self.account;
629        let id = &self.id;
630        RequestBuilder::new(
631            StripeMethod::Post,
632            format!("/accounts/{account}/external_accounts/{id}"),
633        )
634        .form(&self.inner)
635    }
636}
637#[derive(Clone)]
638#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
639#[derive(serde::Serialize)]
640struct UpdateCustomerCardBuilder {
641    #[serde(skip_serializing_if = "Option::is_none")]
642    account_holder_name: Option<String>,
643    #[serde(skip_serializing_if = "Option::is_none")]
644    account_holder_type: Option<UpdateCustomerCardAccountHolderType>,
645    #[serde(skip_serializing_if = "Option::is_none")]
646    address_city: Option<String>,
647    #[serde(skip_serializing_if = "Option::is_none")]
648    address_country: Option<String>,
649    #[serde(skip_serializing_if = "Option::is_none")]
650    address_line1: Option<String>,
651    #[serde(skip_serializing_if = "Option::is_none")]
652    address_line2: Option<String>,
653    #[serde(skip_serializing_if = "Option::is_none")]
654    address_state: Option<String>,
655    #[serde(skip_serializing_if = "Option::is_none")]
656    address_zip: Option<String>,
657    #[serde(skip_serializing_if = "Option::is_none")]
658    exp_month: Option<String>,
659    #[serde(skip_serializing_if = "Option::is_none")]
660    exp_year: Option<String>,
661    #[serde(skip_serializing_if = "Option::is_none")]
662    expand: Option<Vec<String>>,
663    #[serde(skip_serializing_if = "Option::is_none")]
664    metadata: Option<std::collections::HashMap<String, String>>,
665    #[serde(skip_serializing_if = "Option::is_none")]
666    name: Option<String>,
667    #[serde(skip_serializing_if = "Option::is_none")]
668    owner: Option<UpdateCustomerCardOwner>,
669}
670#[cfg(feature = "redact-generated-debug")]
671impl std::fmt::Debug for UpdateCustomerCardBuilder {
672    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
673        f.debug_struct("UpdateCustomerCardBuilder").finish_non_exhaustive()
674    }
675}
676impl UpdateCustomerCardBuilder {
677    fn new() -> Self {
678        Self {
679            account_holder_name: None,
680            account_holder_type: None,
681            address_city: None,
682            address_country: None,
683            address_line1: None,
684            address_line2: None,
685            address_state: None,
686            address_zip: None,
687            exp_month: None,
688            exp_year: None,
689            expand: None,
690            metadata: None,
691            name: None,
692            owner: None,
693        }
694    }
695}
696/// The type of entity that holds the account. This can be either `individual` or `company`.
697#[derive(Clone, Eq, PartialEq)]
698#[non_exhaustive]
699pub enum UpdateCustomerCardAccountHolderType {
700    Company,
701    Individual,
702    /// An unrecognized value from Stripe. Should not be used as a request parameter.
703    Unknown(String),
704}
705impl UpdateCustomerCardAccountHolderType {
706    pub fn as_str(&self) -> &str {
707        use UpdateCustomerCardAccountHolderType::*;
708        match self {
709            Company => "company",
710            Individual => "individual",
711            Unknown(v) => v,
712        }
713    }
714}
715
716impl std::str::FromStr for UpdateCustomerCardAccountHolderType {
717    type Err = std::convert::Infallible;
718    fn from_str(s: &str) -> Result<Self, Self::Err> {
719        use UpdateCustomerCardAccountHolderType::*;
720        match s {
721            "company" => Ok(Company),
722            "individual" => Ok(Individual),
723            v => {
724                tracing::warn!(
725                    "Unknown value '{}' for enum '{}'",
726                    v,
727                    "UpdateCustomerCardAccountHolderType"
728                );
729                Ok(Unknown(v.to_owned()))
730            }
731        }
732    }
733}
734impl std::fmt::Display for UpdateCustomerCardAccountHolderType {
735    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
736        f.write_str(self.as_str())
737    }
738}
739
740#[cfg(not(feature = "redact-generated-debug"))]
741impl std::fmt::Debug for UpdateCustomerCardAccountHolderType {
742    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
743        f.write_str(self.as_str())
744    }
745}
746#[cfg(feature = "redact-generated-debug")]
747impl std::fmt::Debug for UpdateCustomerCardAccountHolderType {
748    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
749        f.debug_struct(stringify!(UpdateCustomerCardAccountHolderType)).finish_non_exhaustive()
750    }
751}
752impl serde::Serialize for UpdateCustomerCardAccountHolderType {
753    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
754    where
755        S: serde::Serializer,
756    {
757        serializer.serialize_str(self.as_str())
758    }
759}
760#[cfg(feature = "deserialize")]
761impl<'de> serde::Deserialize<'de> for UpdateCustomerCardAccountHolderType {
762    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
763        use std::str::FromStr;
764        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
765        Ok(Self::from_str(&s).expect("infallible"))
766    }
767}
768#[derive(Clone, Eq, PartialEq)]
769#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
770#[derive(serde::Serialize)]
771pub struct UpdateCustomerCardOwner {
772    /// Owner's address.
773    #[serde(skip_serializing_if = "Option::is_none")]
774    pub address: Option<UpdateCustomerCardOwnerAddress>,
775    /// Owner's email address.
776    #[serde(skip_serializing_if = "Option::is_none")]
777    pub email: Option<String>,
778    /// Owner's full name.
779    #[serde(skip_serializing_if = "Option::is_none")]
780    pub name: Option<String>,
781    /// Owner's phone number.
782    #[serde(skip_serializing_if = "Option::is_none")]
783    pub phone: Option<String>,
784}
785#[cfg(feature = "redact-generated-debug")]
786impl std::fmt::Debug for UpdateCustomerCardOwner {
787    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
788        f.debug_struct("UpdateCustomerCardOwner").finish_non_exhaustive()
789    }
790}
791impl UpdateCustomerCardOwner {
792    pub fn new() -> Self {
793        Self { address: None, email: None, name: None, phone: None }
794    }
795}
796impl Default for UpdateCustomerCardOwner {
797    fn default() -> Self {
798        Self::new()
799    }
800}
801/// Owner's address.
802#[derive(Clone, Eq, PartialEq)]
803#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
804#[derive(serde::Serialize)]
805pub struct UpdateCustomerCardOwnerAddress {
806    /// City, district, suburb, town, or village.
807    #[serde(skip_serializing_if = "Option::is_none")]
808    pub city: Option<String>,
809    /// Two-letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)).
810    #[serde(skip_serializing_if = "Option::is_none")]
811    pub country: Option<String>,
812    /// Address line 1, such as the street, PO Box, or company name.
813    #[serde(skip_serializing_if = "Option::is_none")]
814    pub line1: Option<String>,
815    /// Address line 2, such as the apartment, suite, unit, or building.
816    #[serde(skip_serializing_if = "Option::is_none")]
817    pub line2: Option<String>,
818    /// ZIP or postal code.
819    #[serde(skip_serializing_if = "Option::is_none")]
820    pub postal_code: Option<String>,
821    /// State, county, province, or region ([ISO 3166-2](https://en.wikipedia.org/wiki/ISO_3166-2)).
822    #[serde(skip_serializing_if = "Option::is_none")]
823    pub state: Option<String>,
824}
825#[cfg(feature = "redact-generated-debug")]
826impl std::fmt::Debug for UpdateCustomerCardOwnerAddress {
827    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
828        f.debug_struct("UpdateCustomerCardOwnerAddress").finish_non_exhaustive()
829    }
830}
831impl UpdateCustomerCardOwnerAddress {
832    pub fn new() -> Self {
833        Self { city: None, country: None, line1: None, line2: None, postal_code: None, state: None }
834    }
835}
836impl Default for UpdateCustomerCardOwnerAddress {
837    fn default() -> Self {
838        Self::new()
839    }
840}
841/// Update a specified source for a given customer.
842#[derive(Clone)]
843#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
844#[derive(serde::Serialize)]
845pub struct UpdateCustomerCard {
846    inner: UpdateCustomerCardBuilder,
847    customer: stripe_shared::CustomerId,
848    id: String,
849}
850#[cfg(feature = "redact-generated-debug")]
851impl std::fmt::Debug for UpdateCustomerCard {
852    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
853        f.debug_struct("UpdateCustomerCard").finish_non_exhaustive()
854    }
855}
856impl UpdateCustomerCard {
857    /// Construct a new `UpdateCustomerCard`.
858    pub fn new(customer: impl Into<stripe_shared::CustomerId>, id: impl Into<String>) -> Self {
859        Self { customer: customer.into(), id: id.into(), inner: UpdateCustomerCardBuilder::new() }
860    }
861    /// The name of the person or business that owns the bank account.
862    pub fn account_holder_name(mut self, account_holder_name: impl Into<String>) -> Self {
863        self.inner.account_holder_name = Some(account_holder_name.into());
864        self
865    }
866    /// The type of entity that holds the account. This can be either `individual` or `company`.
867    pub fn account_holder_type(
868        mut self,
869        account_holder_type: impl Into<UpdateCustomerCardAccountHolderType>,
870    ) -> Self {
871        self.inner.account_holder_type = Some(account_holder_type.into());
872        self
873    }
874    /// City/District/Suburb/Town/Village.
875    pub fn address_city(mut self, address_city: impl Into<String>) -> Self {
876        self.inner.address_city = Some(address_city.into());
877        self
878    }
879    /// Billing address country, if provided when creating card.
880    pub fn address_country(mut self, address_country: impl Into<String>) -> Self {
881        self.inner.address_country = Some(address_country.into());
882        self
883    }
884    /// Address line 1 (Street address/PO Box/Company name).
885    pub fn address_line1(mut self, address_line1: impl Into<String>) -> Self {
886        self.inner.address_line1 = Some(address_line1.into());
887        self
888    }
889    /// Address line 2 (Apartment/Suite/Unit/Building).
890    pub fn address_line2(mut self, address_line2: impl Into<String>) -> Self {
891        self.inner.address_line2 = Some(address_line2.into());
892        self
893    }
894    /// State/County/Province/Region.
895    pub fn address_state(mut self, address_state: impl Into<String>) -> Self {
896        self.inner.address_state = Some(address_state.into());
897        self
898    }
899    /// ZIP or postal code.
900    pub fn address_zip(mut self, address_zip: impl Into<String>) -> Self {
901        self.inner.address_zip = Some(address_zip.into());
902        self
903    }
904    /// Two digit number representing the card’s expiration month.
905    pub fn exp_month(mut self, exp_month: impl Into<String>) -> Self {
906        self.inner.exp_month = Some(exp_month.into());
907        self
908    }
909    /// Four digit number representing the card’s expiration year.
910    pub fn exp_year(mut self, exp_year: impl Into<String>) -> Self {
911        self.inner.exp_year = Some(exp_year.into());
912        self
913    }
914    /// Specifies which fields in the response should be expanded.
915    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
916        self.inner.expand = Some(expand.into());
917        self
918    }
919    /// Set of [key-value pairs](https://docs.stripe.com/api/metadata) that you can attach to an object.
920    /// This can be useful for storing additional information about the object in a structured format.
921    /// Individual keys can be unset by posting an empty value to them.
922    /// All keys can be unset by posting an empty value to `metadata`.
923    pub fn metadata(
924        mut self,
925        metadata: impl Into<std::collections::HashMap<String, String>>,
926    ) -> Self {
927        self.inner.metadata = Some(metadata.into());
928        self
929    }
930    /// Cardholder name.
931    pub fn name(mut self, name: impl Into<String>) -> Self {
932        self.inner.name = Some(name.into());
933        self
934    }
935    pub fn owner(mut self, owner: impl Into<UpdateCustomerCardOwner>) -> Self {
936        self.inner.owner = Some(owner.into());
937        self
938    }
939}
940impl UpdateCustomerCard {
941    /// Send the request and return the deserialized response.
942    pub async fn send<C: StripeClient>(
943        &self,
944        client: &C,
945    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
946        self.customize().send(client).await
947    }
948
949    /// Send the request and return the deserialized response, blocking until completion.
950    pub fn send_blocking<C: StripeBlockingClient>(
951        &self,
952        client: &C,
953    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
954        self.customize().send_blocking(client)
955    }
956}
957
958impl StripeRequest for UpdateCustomerCard {
959    type Output = UpdateCustomerCardReturned;
960
961    fn build(&self) -> RequestBuilder {
962        let customer = &self.customer;
963        let id = &self.id;
964        RequestBuilder::new(StripeMethod::Post, format!("/customers/{customer}/sources/{id}"))
965            .form(&self.inner)
966    }
967}
968#[derive(Clone)]
969#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
970#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
971#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
972#[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(tag = "object"))]
973pub enum UpdateCustomerCardReturned {
974    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "card"))]
975    Card(stripe_shared::Card),
976    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "bank_account"))]
977    BankAccount(stripe_shared::BankAccount),
978    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "source"))]
979    Source(stripe_shared::Source),
980}
981
982#[derive(Default)]
983pub struct UpdateCustomerCardReturnedBuilder {
984    inner: stripe_types::miniserde_helpers::ObjectBuilderInner,
985}
986
987const _: () = {
988    use miniserde::de::{Map, Visitor};
989    use miniserde::json::Value;
990    use miniserde::{Deserialize, Result, make_place};
991    use stripe_types::MapBuilder;
992    use stripe_types::miniserde_helpers::FromValueOpt;
993
994    use super::*;
995
996    make_place!(Place);
997
998    struct Builder<'a> {
999        out: &'a mut Option<UpdateCustomerCardReturned>,
1000        builder: UpdateCustomerCardReturnedBuilder,
1001    }
1002
1003    impl Deserialize for UpdateCustomerCardReturned {
1004        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
1005            Place::new(out)
1006        }
1007    }
1008
1009    impl Visitor for Place<UpdateCustomerCardReturned> {
1010        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
1011            Ok(Box::new(Builder { out: &mut self.out, builder: Default::default() }))
1012        }
1013    }
1014
1015    impl Map for Builder<'_> {
1016        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
1017            self.builder.key(k)
1018        }
1019
1020        fn finish(&mut self) -> Result<()> {
1021            *self.out = self.builder.take_out();
1022            Ok(())
1023        }
1024    }
1025
1026    impl MapBuilder for UpdateCustomerCardReturnedBuilder {
1027        type Out = UpdateCustomerCardReturned;
1028        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
1029            self.inner.key_inner(k)
1030        }
1031
1032        fn deser_default() -> Self {
1033            Self::default()
1034        }
1035
1036        fn take_out(&mut self) -> Option<Self::Out> {
1037            let (k, o) = self.inner.finish_inner()?;
1038            UpdateCustomerCardReturned::construct(&k, o)
1039        }
1040    }
1041
1042    impl stripe_types::ObjectDeser for UpdateCustomerCardReturned {
1043        type Builder = UpdateCustomerCardReturnedBuilder;
1044    }
1045    impl UpdateCustomerCardReturned {
1046        fn construct(key: &str, o: miniserde::json::Object) -> Option<Self> {
1047            Some(match key {
1048                "card" => Self::Card(FromValueOpt::from_value(Value::Object(o))?),
1049                "bank_account" => Self::BankAccount(FromValueOpt::from_value(Value::Object(o))?),
1050                "source" => Self::Source(FromValueOpt::from_value(Value::Object(o))?),
1051
1052                _ => {
1053                    tracing::warn!(
1054                        "Unknown object type '{}' for enum '{}'",
1055                        key,
1056                        "UpdateCustomerCardReturned"
1057                    );
1058                    return None;
1059                }
1060            })
1061        }
1062    }
1063
1064    impl FromValueOpt for UpdateCustomerCardReturned {
1065        fn from_value(v: Value) -> Option<Self> {
1066            let (typ, obj) = stripe_types::miniserde_helpers::extract_object_discr(v)?;
1067            Self::construct(&typ, obj)
1068        }
1069    }
1070};
1071
1072#[cfg(feature = "redact-generated-debug")]
1073impl std::fmt::Debug for UpdateCustomerCardReturned {
1074    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1075        f.debug_struct("UpdateCustomerCardReturned").finish_non_exhaustive()
1076    }
1077}