【问题标题】:Stripe Cannot charge a customer that has no active cardStripe 无法向没有活动卡的客户收费
【发布时间】:2021-05-14 13:28:53
【问题描述】:

我无法向 Stripe 客户收费。虽然这个问题在过去被问过十几次,但他们的错误都与我的问题不符。

我在 node.js 中将此函数称为 firebase 函数

const charge = await stripe.charges.create({
      
        customer : customerId,
        amount : amount,
        currency : currency
    });

请求 POST 正文

{
  "customer": "cus_JL4hVfDnym2SIk",
  "amount": "500",
  "currency": "usd"
}

我已确认 Stripe Dashboard 上的所有值都是正确的。我也将测试卡存储在客户身上,它被明确设置为默认值,我也在仪表板上确认了这一点。我在一个非常不同的步骤存储卡信息,不像其他帖子一次处理这一切。

我只想向帐户中存有卡的客户收费。一切都在测试数据、测试卡等上。这是使用收费 api 的问题吗?还是因为某种原因测试卡在这里不起作用?

错误响应正文

{
  "error": {
    "code": "missing",
    "doc_url": "https://stripe.com/docs/error-codes/missing",
    "message": "Cannot charge a customer that has no active card",
    "param": "card",
    "type": "card_error"
  }
}

【问题讨论】:

    标签: stripe-payments


    【解决方案1】:

    仪表板中添加的卡片现在使用更新的Payment Methods API。您使用的模式取决于拥有 default_source (API ref) 且使用旧版 Sources API 的客户。

    您可以attach the test card as a source,但我建议您将集成更改为使用Payment Intents

    如果您已经在客户身上添加了基本测试卡,您需要提供其id作为payment_method

    const paymentIntent = await stripe.paymentIntents.create({
      amount: 2000,
      currency: 'usd',
      payment_method_types: ['card'],
      payment_method: 'pm_123', // put your ID here
      confirm: true,
    });
    

    虽然这适用于 4242 测试卡,但推荐的方法是 follow this guide 与支持 Strong Customer Authenticationclient-side confirmation 的 Stripe.js 和 Elements 集成。

    【讨论】:

    • 反响很好。理想情况下,我不想存储和传递我的 payment_method,因为这会在项目中产生一些边缘情况。但是,这可能是唯一的解决方案,因为我将 default_source 存储在“paymenthMethods.attach”和“customers.update”中。此外,这些教程很棒,除了我必须将卡片元素转换为 SwiftUI 视图,而且我存储的卡片和购买流程处于完全不同的关口。稍后可能会将其标记为正确,因为 PaymentMethod 和 Sources API 可能具有不同的 default_payments 对象,这可以解释我的问题。谢谢!
    • 请注意,使用付款方式时,一次性付款没有内置的“默认”PM。有一个客户invoice_settings.default_payment_method 用于发票(和订阅),但对于一次性付款意图,您必须始终明确提供一种付款方式。如果适合您的业务,您可以保存 PM id 以用作默认值,但您需要将此参数提供给付款意图。
    • 哦,这更有意义。我可能会调用“paymentMethods.retrieve”来获取订阅的默认存储卡,作为快捷方式。如果这不起作用,那么我将按照您最初的建议通过应用程序传递我的 payment_method。感谢您的帮助!
    • 快捷方式对我有用(以防其他人想知道)
    猜你喜欢
    • 1970-01-01
    • 2021-01-05
    • 2017-03-17
    • 1970-01-01
    • 2017-11-05
    • 2022-01-27
    • 2015-05-25
    • 2021-09-19
    • 2016-12-15
    相关资源
    最近更新 更多