How to add a payment source with insufficient funds using stripe?
Asked Answered
N

2

8

I am trying to test a scenario where the user's card has insufficient funds.

Following the docs at https://stripe.com/docs/testing - the cardnumber 4000 0000 0000 0002 should yield such an error. The source is considered valid in the Stripe SDK, and it generates a source token, but when calling their create_source API, It comes back with a Request req_nGnzPdJHjw4lrk: Your card was declined.-message, even though I have not created any charge yet.

The documentation at https://stripe.com/docs/saving-cards states:

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.

So my question is, how do I test a scenario when a card is accepted by stripe, but during the moment of capturing a charge has insufficient funds?

Nildanile answered 29/6, 2018 at 10:33 Comment(0)
I
12

You can use the 4000000000000341 test card from https://stripe.com/docs/testing#cards-responses. This card can be saved to a customer, but when you attempt to charge it you will get a decline.

Note that the error you will get is a generic decline, rather than insufficient_funds. If you need to test how your code responds to that error code specifically, I would recommend just mocking the response from the Stripe API. Generally your error handling would be pretty similar regardless of the specific decline reason, so Stripe doesn't provide test cards for all the cases.

EDIT : since I wrote this, Stripe has added a new test card 4000000000009995 / tok_chargeDeclinedInsufficientFunds for this specific case.

Investigation answered 29/6, 2018 at 10:48 Comment(0)
D
0

Update : To attach a card to a customer, you need to use :

4000 0000 0000 0341

Regarding to stripe doc it is the only declining card you can attach to a customer (https://docs.stripe.com/testing#declined-payments)

See stripe_doc_screenshot

Diner answered 1/4 at 20:14 Comment(1)
This actually doesn't provide anything new than the accepted answer.Angelicangelica

© 2022 - 2024 — McMap. All rights reserved.