[英]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
文件中调用Stripe.card.createToken
并希望返回这个 function 生成的令牌,以便我可以在我的 vuex 中使用它,我该怎么做?
// api.js // 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.所以我想像这样在 vuex 中的操作中使用它。 I did this and it doesn't work, it returns undefined:
我这样做了,但它不起作用,它返回未定义:
//vuex //vuex
import { stripeToken } from '@src/store/api';
async stripeToken({ dispatch }, { cardInfo }) {
const { data } = await stripeToken({ cardInfo });
console.log('tokenId: ', data.tokenId);
},
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.我不熟悉 vuex,但是
Stripe.card.createToken
方法需要两个参数:一个 JavaScript object 包含用户输入的信用卡数据,以及一个回调 ZC1C425268E68385D1AB5074C17A9 到You can learn more about it in the Stripe documentation here .您可以在此处的 Stripe 文档中了解更多信息。
Here's how you could display the ID of a token with Stripe.card.createToken
:以下是使用
Stripe.card.createToken
显示令牌 ID 的方法:
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.请注意,
Stripe.card.createToken
是 Stripe.js v2 中的旧方法,现已弃用,因此我建议尽可能升级到 Stripe.js v3 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.