【问题标题】:Stripe Connect Direct Charge Error: Invalid token IDStripe Connect 直接收费错误:令牌 ID 无效
【发布时间】:2021-10-31 07:24:06
【问题描述】:

我在通过 Stripe API (NodeJS) 创建 paymentIntent 时遇到错误:无效的令牌 ID

以下作品:

stripe.paymentIntents
    .create({
      amount: 100,
      confirm: true,
      currency: "gbp",
      description: "payment",
      payment_method_types: ["card"],
      payment_method_data: {
        type: "card",
        card: {
          token: customerCard.id, // token generated on the client side
        },
      },
    })

但现在我想根据本指南使用 Stripe Connect 从“简单”收费转变为“直接”收费流程:https://stripe.com/docs/connect/direct-charges

如果我按照指南修改我的代码:

stripe.paymentIntents
    .create({
      amount: 1000,
      application_fee_amount: 100, // added this
      confirm: true,
      currency: "gbp",
      description: "payment",
      payment_method_types: ["card"],
      payment_method_data: {
        type: "card",
        card: {
          token: customerCard.id,
        },
      },
    }, { stripeAccount: "{{ ACTUAL_CONNECT_ACCOUNT_ID_IS_HERE }}"}) // added this

调用失败(在我的 try catch 中)并显示“错误:无效的令牌 ID:tok_abc...”

我不明白为什么在第一种情况下创建 paymentIntent 时没有错误,但是当我尝试使用连接帐户上的直接费用创建另一个 paymentIntent 并收取申请费时(如根据文档),并使用完全相同的方法生成新卡/令牌(使用相同的条带测试卡),paymentIntent 失败并且之前很好的令牌现在无效。该错误似乎具有误导性或至少被掩盖了。

我在每次支付尝试时都会生成一个新的卡令牌客户端,完全按照指南,使用这个包:https://github.com/expo/stripe-expo。这是我生成令牌的方式:

import createStripe from "stripe-client"; // https://github.com/expo/stripe-expo

...

// init a new instance of stripe client passing the ID of the connected account to create the token on that account
  const stripeClient = createStripe(
    "pk_test_5...gKi",
    { stripeAccount: "{ACTUAL_ID_IS_HERE}" }
  );
  return stripeClient.createToken({ card });

每次都获得看似有效的令牌。

有人可以帮忙吗?

谢谢

【问题讨论】:

    标签: stripe-payments


    【解决方案1】:

    您正在使用 Stripe 的 ReactNative SDK(通过 Expo),看起来像。

    在服务器端,您在 Connect 帐户上创建了一个 PaymentIntent

        }, { stripeAccount: "{{ ACTUAL_CONNECT_ACCOUNT_ID_IS_HERE }}"}) // added this
    

    部分。

    同样,您也需要在 Connect 账户上创建 Token。

    您可以通过在 ReactNative 代码中构造 StripeProvider 时传递 stripeAccountId: acct_123 来做到这一点:https://stripe.dev/stripe-react-native/api-reference/interfaces/StripeProviderProps.html#stripeAccountId

    其中 acct_123 与您在创建 PaymentIntent 服务器端时传递的帐户 ID 相同。

    这意味着您的代币创建不会发生在平台上,而是发生在 Connect 帐户上。

    【讨论】:

    • 谢谢@hmunoz 我实际上在客户端使用上面提到的“stripe-client”。我编辑了我的问题以显示我的令牌生成代码,它确实包含一个“stripeAccount”标头,该标头设置为连接的帐户 ID。看起来我正在按照您的建议进行操作,但要么我出错了,要么没有按预期工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-21
    • 2015-06-21
    • 1970-01-01
    • 2013-06-21
    • 1970-01-01
    相关资源
    最近更新 更多