Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

159
Vistas
how to return Stripe's createToken tokenId and use it in another function in vuex

so I call Stripe.card.createToken in my api.js file and want to return the token this function generates so I can use it in my vuex, how can I do that?

// api.js

export const stripeToken = async ({ cardInfo }) => {
  const { data } = await Stripe.card.createToken({
    cardInfo,
  });
  return data;
};

So I want to use it in my actions in vuex like this. I did this and it doesn't work, it returns undefined:

//vuex

import { stripeToken } from '@src/store/api';
async stripeToken({ dispatch }, { cardInfo }) {
  const { data } = await stripeToken({ cardInfo });
  console.log('tokenId: ', data.tokenId);
},
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I'm not familiar with vuex, but the Stripe.card.createToken method takes two parameters: a JavaScript object containing credit card data entered by the user, and a callback function to handle the response. You can learn more about it in the Stripe documentation here.

Here's how you could display the ID of a token with Stripe.card.createToken:

Stripe.card.createToken(cardInfo, (status, response) => {
  if (response.error) {
    console.log(response.error);
  } else {
    console.log(response.id);
  }
});

Note that Stripe.card.createToken is an old method from Stripe.js v2 that is now deprecated, so I would recommend upgrading to Stripe.js v3 if possible.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda