11

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.

Dharman
  • 30,962
  • 25
  • 85
  • 135

2 Answers2

2

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

Posted on behalf of the question asker

Dharman
  • 30,962
  • 25
  • 85
  • 135
-4

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.

colinm
  • 4,258
  • 24
  • 19
  • Steps 1,2,3 are only for setup. I'm going to test processing the event itself. This will be in my expect block: email should be sent to customer telling them about failed payment. Problem with Stripe mocking libraries was that their implementation was not correct/incomplete. If there is any recommended practice I would appreciate that! – David Hrachovy Jun 02 '14 at 13:11