'stripe.createToken() is not a function

I am using stripe in node.js.

I need to create a stripe token with bank details. For that I am using the below code which is given in the stripe documentation:

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) {
    console.log("result", result);
});

But I am getting this error, "stripe.createToken() is not a function".

I have also tried "stripe.tokens.create({ bank_account: {})" but it is not giving the token "account".

Need someone's valuable help.



Solution 1:[1]

The solution I found so far is to do the following import in your root document: https://github.com/stripe/stripe-js#import-as-a-side-effect.

import '@stripe/stripe-js';
// rest of your imports

Other methods also posted in the Stripe JS readme.

Solution 2:[2]

I ran into this issue myself, but the stripe documentation is the best to reference. https://stripe.com/docs/api/tokens/create_bank_account

const token = await stripe.tokens.create({
  bank_account: {
    country: 'US',
    currency: 'usd',
    account_holder_name: 'Jenny Rosen',
    account_holder_type: 'individual',
    routing_number: '110000000',
    account_number: '000123456789',
  },
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jayg_code
Solution 2 Jarren Campos