【问题标题】:How to add a payment source with insufficient funds using stripe?如何使用条带添加资金不足的支付来源?
【发布时间】:2018-12-08 12:47:45
【问题描述】:

我正在尝试测试用户卡资金不足的场景。

按照https://stripe.com/docs/testing 的文档 - 卡号4000 0000 0000 0002 应该会产生这样的错误。源在 Stripe SDK 中被认为是 valid,它会生成一个源 token,但是当调用他们的 create_source API 时,它会返回一个 Request req_nGnzPdJHjw4lrk: Your card was declined. 消息,即使我还没有创建任何费用.

https://stripe.com/docs/saving-cards 的文档指出:

Stripe validates card information when it is saved. This does not guarantee that any future charges succeed (e.g., the card no longer has sufficient funds, is reported lost or stolen, or if the account is closed). This process also includes the results of any checks, including traditional bank checks by Radar (e.g., CVC or postal code), that may have been performed.

所以我的问题是,当卡片被条带接受,但在捕获费用期间资金不足时,我该如何测试场景?

【问题讨论】:

    标签: stripe-payments pinax


    【解决方案1】:

    您可以使用来自https://stripe.com/docs/testing#cards-responses4000000000000341 测试卡。这张卡可以保存给客户,但当您尝试向其收费时,您会遭到拒绝。

    请注意,您将收到的错误是一般性拒绝,而不是insufficient_funds。如果您需要测试您的代码如何具体响应该错误代码,我建议您只模拟来自 Stripe API 的响应。通常,无论具体的拒绝原因如何,您的错误处理都会非常相似,因此 Stripe 不会为所有情况提供测试卡。

    编辑:因为我写了这篇文章,Stripe 为这个特定的案例添加了一张新的测试卡4000000000009995 / tok_chargeDeclinedInsufficientFunds

    【讨论】:

    • 太棒了!非常感谢!
    最近更新 更多