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


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.


4000 0000 0000 0002


valid


token


create_source


Request req_nGnzPdJHjw4lrk: Your card was declined.



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.


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?




1 Answer
1



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.


4000000000000341



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.


insufficient_funds





Awesome! Thanks a lot!
– Eyeball
Jun 29 at 11:21






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

how to run turtle graphics in Colaboratory

Export result set on Dbeaver to CSV