node.js - Stripe 不允许将一笔费用与一次性来源的客户关联起来

标签 node.js stripe-payments

正如标题所示,我正在尝试使用未保存在客户个人资料中的一次性来源(信用卡)进行付款。我仍然希望能够在 Stripe 上的客户个人资料中记录该费用。

根据the docs ,这可以通过在发送到 Stripe.customers.createCharge 的负载中的 customer 键中传递客户的 id 来完成。但是,在执行此操作时,我收到一条错误,指出该卡未与客户关联(显然不是,而且我不希望如此)。

Customer cus_*** does not have card with ID tok_visa

为了解决这个问题,我暂时应用了提到的修复in this answer这基本上涉及创建一张用于付款的临时卡,然后将其删除。

我想知道 API 在有明确记录的情况下怎么会不起作用,希望有使用 Stripe 经验的人也能提出同样的意见。

这是我尝试运行的代码:

await stripeService.charges.create({
    source: token, // temporary token received from Checkout
    customer: user.stripeCustomerId, // the Stripe customer ID from my database
    amount,
    currency: 'usd',
    description: 'Test charge'
});

最佳答案

您显式链接到的一次性源文档仅适用于 Sources ,但是 tok_visa 将创建 Card对象代替。我相信这就是您收到错误的原因。

如果您尝试使用通过前端 Elements/Checkout 获取的源代码(它具有类似“src_xxx”的 ID),例如 createSource ,它会成功,我刚刚测试过。您还可以使用以下代码进行测试:

const src = await stripe.sources.create({
    type : "card",
    token : "tok_visa"
});

const charge = await stripe.charges.create({
    source : src.id,
    customer : "cus_xxxx",
    amount : 1000,
    currency : "usd"
});

关于node.js - Stripe 不允许将一笔费用与一次性来源的客户关联起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51947325/

相关文章:

python - 如何通过 stripe python api 创建定期费用?

javascript - node.js 中的异步 https 请求

node.js mariasql 返回未定义

node.js - 在mongoosastic中搜索没有任何结果

php - 使用 Stripe 支付网关向银行账户发起付款

android - 运行 "flutter run"时出现 Flutter Stripe 错误

node.js - 使用node.js将数据从Excel加载到sql server表

javascript - sendgrid 的 typescript 定义

java - 如何使用stripe-java或rest api获取产品的计划

node.js - Stripe BillingPortal NodeJS