【问题标题】:Provide a card that has the 'currency' field set when adding a card to a Stripe account在将卡片添加到 Stripe 帐户时,提供一张设置了“货币”字段的卡片
【发布时间】: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


    【解决方案1】:

    您可以提供一个可选数据对象作为stripe.createToken 的第二个参数,其中包含currency,如下所示:

    stripe.createToken(cardElement, { 'currency': 'usd' }).then(function (result) {
    

    文档:https://stripe.com/docs/js/tokens_sources/create_token?type=cardElement#stripe_create_token-data-currency

    【讨论】:

      猜你喜欢
      • 2018-03-04
      • 2021-01-31
      • 1970-01-01
      • 2020-08-14
      • 1970-01-01
      • 1970-01-01
      • 2013-11-24
      • 2019-11-04
      • 2018-12-02
      相关资源
      最近更新 更多