【发布时间】: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