David Hrachovy
David Hrachovy

Reputation: 121

Stripe - add an invalid card to customer in test mode?

I would like to test invoice.payment_failed event with VCR

Pseudocode:

  1. create a customer with invalid card
  2. create an invoice with invoice item (here the invoice gets automatically paid)
  3. fetch the invoice.payment_failed event with Stripe::Event

In step 1 Stripe returns error saying I want to add an invalid card. I used "4000000000000119" card number from https://stripe.com/docs/testing

Basically I want to create a scenario where the user had card that was once valid when they first purchased something/subscribed. But a year later it's no longer valid.

I don't want to mock the event data and store them in yml. I fetch event directly from Stripe and record it with VCR.

Upvotes: 12

Views: 3287

Answers (2)

anon
anon

Reputation:

Answer is: 4000 0000 0000 0341 card number. Described in https://stripe.com/docs/testing

Posted on behalf of the question asker

Upvotes: 2

colinm
colinm

Reputation: 4288

On several levels here, you're not testing your invoice.payment_failed code—you're testing your entire application, or even testing Stripe itself. This is not productive.

If you want to test that your webhook handler correctly handles a failed payment, that's the only thing you need or want to test. If Stripe (or a VCR facsimile of Stripe) is involved in the testing process, odds are very high that you have application design or testing design issues you need to address.

Upvotes: -4

Related Questions