Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 610
Eyeball Avatar asked Jun 29 '18 10:06

Eyeball


1 Answers

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.

like image 65
karllekko Avatar answered Oct 20 '22 15:10

karllekko