## Create a Token **Syntax:** `stripe.createToken(...)` #### cardElement Use `stripe.createToken` to convert information collected by card elements into a single-use [Token](/api.md#tokens) that you safely pass to your server to use in an API call. - `cardElement` (Element) **required** The `card` [Element](/js/element.md) you wish to tokenize data from. If applicable, the `Element` tokenizes by pulling data from other elements you’ve created on the same instance of [Elements](#elements_create)—you only need to supply one `Element` as the parameter. - `data` (object) An object containing additional payment information you might have collected. Although these fields are optional, we highly recommend collecting name and address. This information can be used to perform a number of verifications, such as CVC, ZIP, and address verification. [Radar](/radar.md) includes [built-in](/radar/rules.md#traditional-bank-checks) rules that can block payments where the ZIP or CVC verifications with the cardholder’s bank failed. - `name` (string) Cardholder name. - `address_line1` (string) - `address_line2` (string) - `address_city` (string) - `address_state` (string) - `address_zip` (string) - `address_country` (string) A two character country code (for example, `US`). - `currency` (string) Required in order to [add the card to a Connect account](/connect/bank-debit-card-payouts.md) (in all other cases, this parameter is not used). ### Create token from card ```js stripe.createToken(cardElement).then(function(result) { // Handle result.error or result.token }); ``` ```es_next const {token, error} = await stripe.createToken(cardElement); ``` #### cardNumberElement Use `stripe.createToken` to convert information collected by card elements into a single-use [Token](/api.md#tokens) that you safely pass to your server to use in an API call. - `cardNumberElement` (Element) **required** The `cardNumber` [Element](/js/element.md) you wish to tokenize data from. If applicable, the `Element` tokenizes by pulling data from other elements you’ve created on the same instance of [Elements](#elements_create)—you only need to supply one `Element` as the parameter. - `data` (object) An object containing additional payment information you might have collected. Although these fields are optional, we highly recommend collecting name and address. This information can be used to perform a number of verifications, such as CVC, ZIP, and address verification. [Radar](/radar.md) includes [built-in](/radar/rules.md#traditional-bank-checks) rules that can block payments where the ZIP or CVC verifications with the cardholder’s bank failed. - `name` (string) Cardholder name. - `address_line1` (string) - `address_line2` (string) - `address_city` (string) - `address_state` (string) - `address_zip` (string) - `address_country` (string) A two character country code (for example, `US`). - `currency` (string) Required in order to [add the card to a Connect account](/connect/bank-debit-card-payouts.md) (in all other cases, this parameter is not used). ### Create token from cardNumber ```js stripe.createToken(cardNumberElement).then(function(result) { // Handle result.error or result.token }); ``` ```es_next const {token, error} = await stripe.createToken(cardNumberElement); ``` #### cardCvcElement Use `stripe.createToken` to convert information collected by card elements into a single-use [Token](/api.md#tokens) that you safely pass to your server to use in an API call. - `cardCvcElement` (Element) **required** The `cardCvc` [Element](/js/element.md) you wish to tokenize data from. - `data` (object) An object containing additional payment information you might have collected. Although these fields are optional, we highly recommend collecting name and address. This information can be used to perform a number of verifications, such as CVC, ZIP, and address verification. [Radar](/radar.md) includes [built-in](/radar/rules.md#traditional-bank-checks) rules that can block payments where the ZIP or CVC verifications with the cardholder’s bank failed. - `name` (string) Cardholder name. - `address_line1` (string) - `address_line2` (string) - `address_city` (string) - `address_state` (string) - `address_zip` (string) - `address_country` (string) A two character country code (for example, `US`). - `currency` (string) Required in order to [add the card to a Connect account](/connect/bank-debit-card-payouts.md) (in all other cases, this parameter is not used). ### Create token from cardCvc ```js stripe.createToken(cardCvcElement).then(function(result) { // Handle result.error or result.token }); ``` ```es_next const {token, error} = await stripe.createToken(cardCvcElement); ``` #### ibanElement Use `stripe.createToken` to convert information collected by an `iban` element into a single-use token that you safely pass to your server to use in an API call. - `ibanElement` (Element) **required** An `iban` [Element](/js/element.md) you wish to tokenize data from. - `data` (object) **required** An object passed as the second argument. It must have the following properties: - `currency` (string) **required** Three character currency code (e.g., `eur`). - `account_holder_name` (string) **required** The name of the account holder. - `account_holder_type` (string) **required** The type of entity that holds the account. Can be either `individual` or `company`. ### Create token from iban ```js stripe .createToken(ibanElement, { // country and account_number are automatically populated from the IBAN Element currency: 'eur', account_holder_name: 'Jenny Rosen', account_holder_type: 'individual', }) .then(function(result) { // Handle result.error or result.token }); ``` ```es_next const {token, error} = await stripe.createToken(ibanElement, { // country and account_number are automatically populated from the IBAN Element currency: 'eur', account_holder_name: 'Jenny Rosen', account_holder_type: 'individual', }); ``` #### pii Use `stripe.createToken` to convert personally identifiable information (PII) into a single-use token for account identity verification. - `tokenType` ('pii') **required** The type of token to create. In this case, `pii`. - `data` (object) **required** An object passed as the second argument. It must have the following properties: - `personal_id_number` (string) **required** The personal ID number. ### Create a token for PII ```js stripe .createToken('pii', { personal_id_number: '123131185', }) .then(function(result) { // Handle result.error or result.token }); ``` ```es_next const {token, error} = await stripe.createToken('pii', { personal_id_number: '123131185', }); ``` #### bank_account Use `stripe.createToken` to convert bank account information into a single-use token that you safely pass to your server to use in an API call. - `tokenType` ('bank_account') **required** The type of token to create. In this case, `bank_account`. - `data` (object) **required** An object passed as the second argument. It must have the following properties: - `country` (string) **required** Two character country code (e.g., `US`). - `currency` (string) **required** Three character currency code (e.g., `usd`). - `routing_number` (string) The bank routing number (e.g., `111000025`). Optional if the currency is `eur`, as the account number is an IBAN. - `account_number` (string) **required** The bank account number (e.g., `000123456789`). - `account_holder_name` (string) The name of the account holder. - `account_holder_type` (string) The type of entity that holds the account. Can be either `individual` or `company`. - `account_type` (string) The bank account type. This can only be `checking` or `savings` in most countries. In Japan, this can only be `futsu` or `toza`. ### Create a bank account token ```js stripe .createToken('bank_account', { country: 'US', currency: 'usd', routing_number: '110000000', account_number: '000123456789', account_holder_name: 'Jenny Rosen', account_holder_type: 'individual', }) .then(function(result) { // Handle result.error or result.token }); ``` ```es_next const {token, error} = await stripe.createToken('bank_account', { country: 'US', currency: 'usd', routing_number: '110000000', account_number: '000123456789', account_holder_name: 'Jenny Rosen', account_holder_type: 'individual', }); ``` #### person Use `stripe.createToken` to create a single-use token that represents the details for a person. Use this when creating or updating persons associated with a Connect account. See [the documentation](/connect/account-tokens.md) to learn more. - `tokenType` ('person') **required** The type of token to create. In this case, `person`. - `data` (object) **required** [Person data](/api/tokens/create_person.md) this token will represent. ### Create a person token ```js stripe .createToken('person', { first_name: 'Jane', last_name: 'Doe', relationship: {owner: true}, }) .then(function(result) { // Handle result.error or result.token }); ``` ```es_next const {token, error} = await stripe.createToken('person', { first_name: 'Jane', last_name: 'Doe', relationship: {owner: true}, }); ``` #### account Use `stripe.createToken` to create a single-use token that wraps a user’s legal entity information. Use this when creating or updating a Connect account. See the [account tokens documentation](/connect/account-tokens.md) to learn more. - `tokenType` ('person') **required** The type of token to create. In this case, `account`. - `data` (object) **required** [Account data](/api/tokens/create_account.md) this token will represent. ### Create a account token ```js stripe .createToken('account', { individual: { first_name: 'Jane', last_name: 'Doe', }, tos_shown_and_accepted: true, }) .then(function(result) { // Handle result.error or result.token }); ``` ```es_next const {token, error} = await stripe.createToken('account', { individual: { first_name: 'Jane', last_name: 'Doe', }, tos_shown_and_accepted: true, }); ``` #### cvc_update Use `stripe.createToken` to tokenize the re-collected CVC on a saved card for use in [CVC re-collection](/payments/accept-a-payment-synchronously.md#web-recollect-cvc). First, render an element of type `cardCvc` to collect the data. Then, pass the `cardCvc` element to `stripe.createToken` to tokenize the collected data. - `tokenType` ('cvc_update') **required** The type of token to create. In this case, `cvc_update`. - `cardCvcElement` (Element) **required** The `cardCvc` [Element](/js/element.md) you wish to tokenize data from. ### Create token from updated CVC ```js stripe.createToken('cvc_update', cardCvcElement, ).then(function(result) { // Handle result.error or result.token }); ``` ```es_next const {token, error} = await stripe.createToken('cvc_update', cardCvcElement ); ``` `stripe.createToken` returns a `Promise` which resolves with a `result` object. This object has either: * `result.token`: a [Token](/api/tokens) was created successfully. * `result.error`: there was an error. This includes client-side validation errors. Refer to the [API reference](/api/errors) for all possible errors.