首页 > 解决方案 > Stripe Connect 直接收费错误:令牌 ID 无效

问题描述

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

以下作品:

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

解决方案


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

在服务器端,您正在使用 Connect 帐户创建 PaymentIntent

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

部分。

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

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

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

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


推荐阅读