Demo, all content is generated
Question

How do I test what happens when a subscription renews without waiting a month

Solved · 642 views · asked by tuan_ng · edited

I have logic on renewal (reset monthly credits in my app). I have no idea if it works because renewal happens once a month. Claude suggested making a plan that renews every day in test mode, which feels hacky. Is there a proper way?

What I’ve tried

Created a daily price in test mode, but then my credit reset logic runs on invoice.paid and I'm not sure the event is the same as a real monthly one.

Comment

2 answers

Marked as helpful by the asker
nils_tw · edited

Test clocks. They're made for exactly this.

  1. Create a test clock (Dashboard > Billing > Test clocks, or stripe.testHelpers.testClocks.create({ frozen_time })).
  2. Create a customer attached to the clock (test_clock: clock.id) and a subscription for them with your real monthly price.
  3. Advance the clock by a month. Stripe generates the renewal invoice, attempts payment, and fires invoice.created, invoice.paid, customer.subscription.updated, same as in real life.

Use the 4000 0000 0000 0341 test card (attaches fine, fails on charge) to test the failed renewal path too.

One gotcha: when you advance, events arrive in a burst. If your handler assumes order, you'll find out here, which is a good thing.

Comment
Exactly the kind of bug test clocks are for. nils_tw · edited
Had no idea these existed. Found a bug in the first run: I reset credits on invoice.paid but the first invoice (signup) also resets them. Checking billing_reason === 'subscription_cycle' now. tuan_ng · edited
billing_reason is so useful, thanks for posting the follow-up bug. marco_py · edited
katja_s · edited

Once it works manually, script it: create clock, customer, subscription, advance, assert on your DB. We run it in CI against test mode nightly. Caught two regressions already.

Comment