stripe/resources/generated/
token.rs

1// ======================================
2// This file was automatically generated.
3// ======================================
4
5use crate::client::{Client, Response};
6use crate::ids::{CustomerId, TokenId};
7use crate::params::{Expand, Metadata, Object, Timestamp};
8use crate::resources::{Address, BankAccount, Card, CompanyParams, PersonParams, TokenType};
9use serde::{Deserialize, Serialize};
10
11/// The resource representing a Stripe "Token".
12///
13/// For more details see <https://stripe.com/docs/api/tokens/object>
14#[derive(Clone, Debug, Default, Deserialize, Serialize)]
15pub struct Token {
16    /// Unique identifier for the object.
17    pub id: TokenId,
18
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub bank_account: Option<BankAccount>,
21
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub card: Option<Card>,
24
25    /// IP address of the client that generates the token.
26    pub client_ip: Option<String>,
27
28    /// Time at which the object was created.
29    ///
30    /// Measured in seconds since the Unix epoch.
31    pub created: Timestamp,
32
33    /// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
34    pub livemode: bool,
35
36    /// Type of the token: `account`, `bank_account`, `card`, or `pii`.
37    #[serde(rename = "type")]
38    pub type_: TokenType,
39
40    /// Determines if you have already used this token (you can only use tokens once).
41    pub used: bool,
42}
43
44impl Token {
45    /// Creates a single-use token that represents a bank account’s details.
46    /// You can use this token with any API method in place of a bank account dictionary.
47    ///
48    /// You can only use this token once.
49    /// To do so, attach it to a [Custom account](https://stripe.com/docs/api#accounts).
50    pub fn create(client: &Client, params: CreateToken<'_>) -> Response<Token> {
51        #[allow(clippy::needless_borrows_for_generic_args)]
52        client.post_form("/tokens", &params)
53    }
54
55    /// Retrieves the token with the given ID.
56    pub fn retrieve(client: &Client, id: &TokenId, expand: &[&str]) -> Response<Token> {
57        client.get_query(&format!("/tokens/{}", id), Expand { expand })
58    }
59}
60
61impl Object for Token {
62    type Id = TokenId;
63    fn id(&self) -> Self::Id {
64        self.id.clone()
65    }
66    fn object(&self) -> &'static str {
67        "token"
68    }
69}
70
71/// The parameters for `Token::create`.
72#[derive(Clone, Debug, Serialize, Default)]
73pub struct CreateToken<'a> {
74    /// Information for the account this token represents.
75    #[serde(skip_serializing_if = "Option::is_none")]
76    pub account: Option<CreateTokenAccount>,
77
78    /// The card this token will represent.
79    ///
80    /// If you also pass in a customer, the card must be the ID of a card belonging to the customer.
81    /// Otherwise, if you do not pass in a customer, this is a dictionary containing a user's credit card details, with the options described below.
82    #[serde(skip_serializing_if = "Option::is_none")]
83    pub card: Option<CreateTokenCardUnion>,
84
85    /// Create a token for the customer, which is owned by the application's account.
86    ///
87    /// You can only use this with an [OAuth access token](https://stripe.com/docs/connect/standard-accounts) or [Stripe-Account header](https://stripe.com/docs/connect/authentication).
88    /// Learn more about [cloning saved payment methods](https://stripe.com/docs/connect/cloning-saved-payment-methods).
89    #[serde(skip_serializing_if = "Option::is_none")]
90    pub customer: Option<CustomerId>,
91
92    /// The updated CVC value this token represents.
93    #[serde(skip_serializing_if = "Option::is_none")]
94    pub cvc_update: Option<CreateTokenCvcUpdate>,
95
96    /// Specifies which fields in the response should be expanded.
97    #[serde(skip_serializing_if = "Expand::is_empty")]
98    pub expand: &'a [&'a str],
99
100    /// Information for the person this token represents.
101    #[serde(skip_serializing_if = "Option::is_none")]
102    pub person: Option<CreateTokenPerson>,
103
104    /// The PII this token represents.
105    #[serde(skip_serializing_if = "Option::is_none")]
106    pub pii: Option<CreateTokenPii>,
107}
108
109impl<'a> CreateToken<'a> {
110    pub fn new() -> Self {
111        CreateToken {
112            account: Default::default(),
113            card: Default::default(),
114            customer: Default::default(),
115            cvc_update: Default::default(),
116            expand: Default::default(),
117            person: Default::default(),
118            pii: Default::default(),
119        }
120    }
121}
122
123#[derive(Clone, Debug, Default, Deserialize, Serialize)]
124pub struct CreateTokenAccount {
125    /// The business type.
126    #[serde(skip_serializing_if = "Option::is_none")]
127    pub business_type: Option<CreateTokenAccountBusinessType>,
128
129    /// Information about the company or business.
130    #[serde(skip_serializing_if = "Option::is_none")]
131    pub company: Option<CompanyParams>,
132
133    /// Information about the person represented by the account.
134    #[serde(skip_serializing_if = "Option::is_none")]
135    pub individual: Option<PersonParams>,
136
137    /// Whether the user described by the data in the token has been shown [the Stripe Connected Account Agreement](https://stripe.com/docs/connect/account-tokens#stripe-connected-account-agreement).
138    ///
139    /// When creating an account token to create a new Connect account, this value must be `true`.
140    #[serde(skip_serializing_if = "Option::is_none")]
141    pub tos_shown_and_accepted: Option<bool>,
142}
143
144#[derive(Clone, Debug, Default, Deserialize, Serialize)]
145pub struct CreateTokenCvcUpdate {
146    /// The CVC value, in string form.
147    pub cvc: String,
148}
149
150#[derive(Clone, Debug, Default, Deserialize, Serialize)]
151pub struct CreateTokenPerson {
152    /// Details on the legal guardian's acceptance of the required Stripe agreements.
153    #[serde(skip_serializing_if = "Option::is_none")]
154    pub additional_tos_acceptances: Option<CreateTokenPersonAdditionalTosAcceptances>,
155
156    /// The person's address.
157    #[serde(skip_serializing_if = "Option::is_none")]
158    pub address: Option<Address>,
159
160    /// The Kana variation of the person's address (Japan only).
161    #[serde(skip_serializing_if = "Option::is_none")]
162    pub address_kana: Option<Address>,
163
164    /// The Kanji variation of the person's address (Japan only).
165    #[serde(skip_serializing_if = "Option::is_none")]
166    pub address_kanji: Option<Address>,
167
168    /// The person's date of birth.
169    #[serde(skip_serializing_if = "Option::is_none")]
170    pub dob: Option<CreateTokenPersonDob>,
171
172    /// Documents that may be submitted to satisfy various informational requests.
173    #[serde(skip_serializing_if = "Option::is_none")]
174    pub documents: Option<CreateTokenPersonDocuments>,
175
176    /// The person's email address.
177    #[serde(skip_serializing_if = "Option::is_none")]
178    pub email: Option<String>,
179
180    /// The person's first name.
181    #[serde(skip_serializing_if = "Option::is_none")]
182    pub first_name: Option<String>,
183
184    /// The Kana variation of the person's first name (Japan only).
185    #[serde(skip_serializing_if = "Option::is_none")]
186    pub first_name_kana: Option<String>,
187
188    /// The Kanji variation of the person's first name (Japan only).
189    #[serde(skip_serializing_if = "Option::is_none")]
190    pub first_name_kanji: Option<String>,
191
192    /// A list of alternate names or aliases that the person is known by.
193    #[serde(skip_serializing_if = "Option::is_none")]
194    pub full_name_aliases: Option<Vec<String>>,
195
196    /// The person's gender (International regulations require either "male" or "female").
197    #[serde(skip_serializing_if = "Option::is_none")]
198    pub gender: Option<String>,
199
200    /// The person's ID number, as appropriate for their country.
201    ///
202    /// For example, a social security number in the U.S., social insurance number in Canada, etc.
203    /// Instead of the number itself, you can also provide a [PII token provided by Stripe.js](https://stripe.com/docs/js/tokens/create_token?type=pii).
204    #[serde(skip_serializing_if = "Option::is_none")]
205    pub id_number: Option<String>,
206
207    /// The person's secondary ID number, as appropriate for their country, will be used for enhanced verification checks.
208    ///
209    /// In Thailand, this would be the laser code found on the back of an ID card.
210    /// Instead of the number itself, you can also provide a [PII token provided by Stripe.js](https://stripe.com/docs/js/tokens/create_token?type=pii).
211    #[serde(skip_serializing_if = "Option::is_none")]
212    pub id_number_secondary: Option<String>,
213
214    /// The person's last name.
215    #[serde(skip_serializing_if = "Option::is_none")]
216    pub last_name: Option<String>,
217
218    /// The Kana variation of the person's last name (Japan only).
219    #[serde(skip_serializing_if = "Option::is_none")]
220    pub last_name_kana: Option<String>,
221
222    /// The Kanji variation of the person's last name (Japan only).
223    #[serde(skip_serializing_if = "Option::is_none")]
224    pub last_name_kanji: Option<String>,
225
226    /// The person's maiden name.
227    #[serde(skip_serializing_if = "Option::is_none")]
228    pub maiden_name: Option<String>,
229
230    /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
231    ///
232    /// This can be useful for storing additional information about the object in a structured format.
233    /// Individual keys can be unset by posting an empty value to them.
234    /// All keys can be unset by posting an empty value to `metadata`.
235    #[serde(skip_serializing_if = "Option::is_none")]
236    pub metadata: Option<Metadata>,
237
238    /// The country where the person is a national.
239    ///
240    /// Two-letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)), or "XX" if unavailable.
241    #[serde(skip_serializing_if = "Option::is_none")]
242    pub nationality: Option<String>,
243
244    /// The person's phone number.
245    #[serde(skip_serializing_if = "Option::is_none")]
246    pub phone: Option<String>,
247
248    /// Indicates if the person or any of their representatives, family members, or other closely related persons, declares that they hold or have held an important public job or function, in any jurisdiction.
249    #[serde(skip_serializing_if = "Option::is_none")]
250    pub political_exposure: Option<String>,
251
252    /// The person's registered address.
253    #[serde(skip_serializing_if = "Option::is_none")]
254    pub registered_address: Option<CreateTokenPersonRegisteredAddress>,
255
256    /// The relationship that this person has with the account's legal entity.
257    #[serde(skip_serializing_if = "Option::is_none")]
258    pub relationship: Option<CreateTokenPersonRelationship>,
259
260    /// The last four digits of the person's Social Security number (U.S.
261    ///
262    /// only).
263    #[serde(skip_serializing_if = "Option::is_none")]
264    pub ssn_last_4: Option<String>,
265
266    /// The person's verification status.
267    #[serde(skip_serializing_if = "Option::is_none")]
268    pub verification: Option<PersonVerificationParams>,
269}
270
271#[derive(Clone, Debug, Default, Deserialize, Serialize)]
272pub struct CreateTokenPii {
273    /// The `id_number` for the PII, in string form.
274    #[serde(skip_serializing_if = "Option::is_none")]
275    pub id_number: Option<String>,
276}
277
278#[derive(Clone, Debug, Default, Deserialize, Serialize)]
279pub struct CreateTokenPersonAdditionalTosAcceptances {
280    /// Details on the legal guardian's acceptance of the main Stripe service agreement.
281    #[serde(skip_serializing_if = "Option::is_none")]
282    pub account: Option<CreateTokenPersonAdditionalTosAcceptancesAccount>,
283}
284
285#[derive(Clone, Debug, Default, Deserialize, Serialize)]
286pub struct CreateTokenPersonDob {
287    /// The day of birth, between 1 and 31.
288    pub day: i64,
289
290    /// The month of birth, between 1 and 12.
291    pub month: i64,
292
293    /// The four-digit year of birth.
294    pub year: i64,
295}
296
297#[derive(Clone, Debug, Default, Deserialize, Serialize)]
298pub struct CreateTokenPersonDocuments {
299    /// One or more documents that demonstrate proof that this person is authorized to represent the company.
300    #[serde(skip_serializing_if = "Option::is_none")]
301    pub company_authorization: Option<CreateTokenPersonDocumentsCompanyAuthorization>,
302
303    /// One or more documents showing the person's passport page with photo and personal data.
304    #[serde(skip_serializing_if = "Option::is_none")]
305    pub passport: Option<CreateTokenPersonDocumentsPassport>,
306
307    /// One or more documents showing the person's visa required for living in the country where they are residing.
308    #[serde(skip_serializing_if = "Option::is_none")]
309    pub visa: Option<CreateTokenPersonDocumentsVisa>,
310}
311
312#[derive(Clone, Debug, Default, Deserialize, Serialize)]
313pub struct CreateTokenPersonRegisteredAddress {
314    /// City, district, suburb, town, or village.
315    #[serde(skip_serializing_if = "Option::is_none")]
316    pub city: Option<String>,
317
318    /// Two-letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)).
319    #[serde(skip_serializing_if = "Option::is_none")]
320    pub country: Option<String>,
321
322    /// Address line 1 (e.g., street, PO Box, or company name).
323    #[serde(skip_serializing_if = "Option::is_none")]
324    pub line1: Option<String>,
325
326    /// Address line 2 (e.g., apartment, suite, unit, or building).
327    #[serde(skip_serializing_if = "Option::is_none")]
328    pub line2: Option<String>,
329
330    /// ZIP or postal code.
331    #[serde(skip_serializing_if = "Option::is_none")]
332    pub postal_code: Option<String>,
333
334    /// State, county, province, or region.
335    #[serde(skip_serializing_if = "Option::is_none")]
336    pub state: Option<String>,
337}
338
339#[derive(Clone, Debug, Default, Deserialize, Serialize)]
340pub struct CreateTokenPersonRelationship {
341    /// Whether the person is a director of the account's legal entity.
342    ///
343    /// Directors are typically members of the governing board of the company, or responsible for ensuring the company meets its regulatory obligations.
344    #[serde(skip_serializing_if = "Option::is_none")]
345    pub director: Option<bool>,
346
347    /// Whether the person has significant responsibility to control, manage, or direct the organization.
348    #[serde(skip_serializing_if = "Option::is_none")]
349    pub executive: Option<bool>,
350
351    /// Whether the person is the legal guardian of the account's representative.
352    #[serde(skip_serializing_if = "Option::is_none")]
353    pub legal_guardian: Option<bool>,
354
355    /// Whether the person is an owner of the account’s legal entity.
356    #[serde(skip_serializing_if = "Option::is_none")]
357    pub owner: Option<bool>,
358
359    /// The percent owned by the person of the account's legal entity.
360    #[serde(skip_serializing_if = "Option::is_none")]
361    pub percent_ownership: Option<f64>,
362
363    /// Whether the person is authorized as the primary representative of the account.
364    ///
365    /// This is the person nominated by the business to provide information about themselves, and general information about the account.
366    /// There can only be one representative at any given time.
367    /// At the time the account is created, this person should be set to the person responsible for opening the account.
368    #[serde(skip_serializing_if = "Option::is_none")]
369    pub representative: Option<bool>,
370
371    /// The person's title (e.g., CEO, Support Engineer).
372    #[serde(skip_serializing_if = "Option::is_none")]
373    pub title: Option<String>,
374}
375
376#[derive(Clone, Debug, Default, Deserialize, Serialize)]
377pub struct PersonVerificationParams {
378    /// A document showing address, either a passport, local ID card, or utility bill from a well-known utility company.
379    #[serde(skip_serializing_if = "Option::is_none")]
380    pub additional_document: Option<VerificationDocumentParams>,
381
382    /// An identifying document, either a passport or local ID card.
383    #[serde(skip_serializing_if = "Option::is_none")]
384    pub document: Option<VerificationDocumentParams>,
385}
386
387#[derive(Clone, Debug, Default, Deserialize, Serialize)]
388pub struct CreateTokenPersonAdditionalTosAcceptancesAccount {
389    /// The Unix timestamp marking when the account representative accepted the service agreement.
390    #[serde(skip_serializing_if = "Option::is_none")]
391    pub date: Option<Timestamp>,
392
393    /// The IP address from which the account representative accepted the service agreement.
394    #[serde(skip_serializing_if = "Option::is_none")]
395    pub ip: Option<String>,
396
397    /// The user agent of the browser from which the account representative accepted the service agreement.
398    #[serde(skip_serializing_if = "Option::is_none")]
399    pub user_agent: Option<String>,
400}
401
402#[derive(Clone, Debug, Default, Deserialize, Serialize)]
403pub struct CreateTokenPersonDocumentsCompanyAuthorization {
404    /// One or more document ids returned by a [file upload](https://stripe.com/docs/api#create_file) with a `purpose` value of `account_requirement`.
405    #[serde(skip_serializing_if = "Option::is_none")]
406    pub files: Option<Vec<String>>,
407}
408
409#[derive(Clone, Debug, Default, Deserialize, Serialize)]
410pub struct CreateTokenPersonDocumentsPassport {
411    /// One or more document ids returned by a [file upload](https://stripe.com/docs/api#create_file) with a `purpose` value of `account_requirement`.
412    #[serde(skip_serializing_if = "Option::is_none")]
413    pub files: Option<Vec<String>>,
414}
415
416#[derive(Clone, Debug, Default, Deserialize, Serialize)]
417pub struct CreateTokenPersonDocumentsVisa {
418    /// One or more document ids returned by a [file upload](https://stripe.com/docs/api#create_file) with a `purpose` value of `account_requirement`.
419    #[serde(skip_serializing_if = "Option::is_none")]
420    pub files: Option<Vec<String>>,
421}
422
423#[derive(Clone, Debug, Default, Deserialize, Serialize)]
424pub struct VerificationDocumentParams {
425    /// The back of an ID returned by a [file upload](https://stripe.com/docs/api#create_file) with a `purpose` value of `identity_document`.
426    ///
427    /// The uploaded file needs to be a color image (smaller than 8,000px by 8,000px), in JPG, PNG, or PDF format, and less than 10 MB in size.
428    #[serde(skip_serializing_if = "Option::is_none")]
429    pub back: Option<String>,
430
431    /// The front of an ID returned by a [file upload](https://stripe.com/docs/api#create_file) with a `purpose` value of `identity_document`.
432    ///
433    /// The uploaded file needs to be a color image (smaller than 8,000px by 8,000px), in JPG, PNG, or PDF format, and less than 10 MB in size.
434    #[serde(skip_serializing_if = "Option::is_none")]
435    pub front: Option<String>,
436}
437
438/// An enum representing the possible values of an `CreateTokenAccount`'s `business_type` field.
439#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
440#[serde(rename_all = "snake_case")]
441pub enum CreateTokenAccountBusinessType {
442    Company,
443    GovernmentEntity,
444    Individual,
445    NonProfit,
446}
447
448impl CreateTokenAccountBusinessType {
449    pub fn as_str(self) -> &'static str {
450        match self {
451            CreateTokenAccountBusinessType::Company => "company",
452            CreateTokenAccountBusinessType::GovernmentEntity => "government_entity",
453            CreateTokenAccountBusinessType::Individual => "individual",
454            CreateTokenAccountBusinessType::NonProfit => "non_profit",
455        }
456    }
457}
458
459impl AsRef<str> for CreateTokenAccountBusinessType {
460    fn as_ref(&self) -> &str {
461        self.as_str()
462    }
463}
464
465impl std::fmt::Display for CreateTokenAccountBusinessType {
466    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
467        self.as_str().fmt(f)
468    }
469}
470impl std::default::Default for CreateTokenAccountBusinessType {
471    fn default() -> Self {
472        Self::Company
473    }
474}
475
476/// The card this token will represent.
477///
478/// If you also pass in a customer, the card must be the ID of a card belonging to the customer.
479/// Otherwise, if you do not pass in a customer, this is a dictionary containing a user's credit card details, with the options described below.
480#[derive(Clone, Debug, Deserialize, Serialize)]
481#[serde(untagged, rename_all = "snake_case")]
482pub enum CreateTokenCardUnion {
483    CreditCardSpecs(CreditCardSpecs),
484    String(String),
485}
486
487#[derive(Clone, Debug, Default, Deserialize, Serialize)]
488pub struct CreditCardSpecs {
489    /// City / District / Suburb / Town / Village.
490    #[serde(skip_serializing_if = "Option::is_none")]
491    pub address_city: Option<String>,
492    /// Billing address country, if provided.
493    #[serde(skip_serializing_if = "Option::is_none")]
494    pub address_country: Option<String>,
495    /// Address line 1 (Street address / PO Box / Company name).
496    #[serde(skip_serializing_if = "Option::is_none")]
497    pub address_line1: Option<String>,
498    /// Address line 2 (Apartment / Suite / Unit / Building).
499    #[serde(skip_serializing_if = "Option::is_none")]
500    pub address_line2: Option<String>,
501    /// State / County / Province / Region.
502    #[serde(skip_serializing_if = "Option::is_none")]
503    pub address_state: Option<String>,
504    /// ZIP or postal code.
505    #[serde(skip_serializing_if = "Option::is_none")]
506    pub address_zip: Option<String>,
507    /// Required in order to add the card to an account; in all other cases, this parameter is not used.
508    ///
509    /// When added to an account, the card (which must be a debit card) can be used as a transfer destination for funds in this currency.
510    #[serde(skip_serializing_if = "Option::is_none")]
511    pub currency: Option<String>,
512    /// Card security code.
513    ///
514    /// Highly recommended to always include this value.
515    #[serde(skip_serializing_if = "Option::is_none")]
516    pub cvc: Option<String>,
517    /// Two-digit number representing the card's expiration month.
518    pub exp_month: String,
519    /// Two- or four-digit number representing the card's expiration year.
520    pub exp_year: String,
521    /// Cardholder's full name.
522    #[serde(skip_serializing_if = "Option::is_none")]
523    pub name: Option<String>,
524    /// The card number, as a string without any separators.
525    pub number: String,
526}