27

I'm trying to test different Stripe Subscription failures. Specifically, what happens when an active subscription gets renewed when initially the card got accepted and the subscription is active, but the renewal payment gets declined, or the customer deletes the card during the subscription.

How can I simulate this on Stripe?

yktoo
  • 1,797
  • 19
  • 29
Charlie Fish
  • 13,172
  • 14
  • 64
  • 137

1 Answers1

52

In order to test failed subscription payments, you can do something like this:

  1. Create the customer with a card token for a valid card (e.g. 4242 4242 4242 4242) in the source parameter.

  2. Create the subscription to the plan. The subscription will be successfully created since the first charge will succeed.

  3. Update the customer with a card token for a failing card (e.g. 4000 0000 0000 0341) in the source parameter.

  4. Update the subscription with the trial_end parameter set to a few seconds in the future and prorate set to false. This effectively changes the next billing date for the subscription.

Once the trial_end date is reached, a new billing period will start and an invoice will be created. After approximately one hour, the invoice will be closed and payment will be attempted. What happens then is decided by your subscription account settings.

To test your second scenario, you can simply change step 3 above to delete the card instead of updating the customer with a failing card.

Ywain
  • 14,951
  • 4
  • 39
  • 58
  • So payment will only be attempted approximately one hour after trial end date? Or what do you mean by the one hour part? – Charlie Fish Sep 09 '16 at 16:09
  • 4
    There is a (roughly) one hour delay between the time an invoice is created, and the time payment for the invoice is attempted. This is by design, so you can add items to the invoice at the last possible moment, which is useful in certain scenarios (e.g. metered billing). You can force the payment attempt earlier using the API: https://stripe.com/docs/api#pay_invoice. – Ywain Sep 09 '16 at 17:13
  • 1
    Great. So I think I now understand what I need to do to test this case. Thank you so much. – Charlie Fish Sep 09 '16 at 17:15
  • This doesn't work. When I try to update the customer's source it explodes saying that the CC has expired. I can't find a way to attach an invalid CC to a customer – Mollo Sep 29 '20 at 20:22
  • For me updating with `trial_end` did not work somehow, but this worked: `subscription = await stripe.subscriptions.update(subscriptionId, { billing_cycle_anchor: 'now', proration_behavior: 'none' });` – thomas Nov 21 '20 at 16:45
  • Renew subscription with a failing card 4000 0000 0000 0341 still doesn't work for me. It still successes – Toan Tran Van Mar 18 '21 at 10:59
  • It's easiest to update the customer's payment method using the token: `curl https://api.stripe.com/v1/customers/ -u : -d "source=tok_chargeCustomerFail"` – yktoo Apr 05 '21 at 15:57