【发布时间】:2021-03-16 23:34:50
【问题描述】:
我在 React 本机中使用 CardElement,在创建借记卡令牌时出现此错误。
错误:
您必须提供一张在添加时设置了“货币”字段的卡 一张卡到 Stripe 帐户
我创建令牌的代码:
const stripe = useStripe();
const elements = useElements();
const handleSubmit = async (event) => {
// Block native form submission.
// event.preventDefault();
if (!stripe || !elements) {
// Stripe.js has not loaded yet. Make sure to disable
// form submission until Stripe.js has loaded.
return;
}
// Get a reference to a mounted CardElement. Elements knows how
// to find your CardElement because there can only ever be one of
// each type of element.
const cardElement = elements.getElement(CardElement);
// Use your card Element with other Stripe.js APIs
stripe.createToken(cardElement).then(function (result) {
// Handle result.error or result.token
const cardId = result.token.card.id
console.log("TOKEN: ", result.token)
const token = result.token.id
// Send token and id to firebase
ref.doc('spE8oRHDBChYPTVgF8BayBTJKmP2').collection('external_accounts').doc(cardId).set({
token: token,
});
});
};
使用 Elements 时如何添加货币字段?
【问题讨论】:
标签: javascript reactjs react-native stripe-payments