Revelry engineering blog header image lightbulb twil this week i learned. Chalkboard style

At Revelry, we believe in sharing and learning from one another (beliefs that are rooted in our Core Values). Among the many things we do to encourage internal knowledge exchange is to have a different team member present at each week’s Engineering Meeting. These presentations don’t have to be lengthy, formal, or complicated; in fact, many are brief, but also powerful in that they teach our Revelers something new, inspire conversation, and encourage collaboration.

In the spirit of sharing, we share our This Week I Learned presentations (aka RevTWILs”) here. We hope you find them helpful.

THIS WEEK: Director of Engineering Jason Pollentier digs into testing Stripe subscriptions.

To do much testing of Stripe subscriptions, you need to be able to advance time. Stripe has “test clocks” for this, and they’re really cool once you get the hang of it.

The steps below allow you to test how the app reacts when a Stripe subscription has invoices issued, changes state, etc. We assume your database holds a Stripe subscription id somewhere, and that Stripe is the source of truth for all subscription-related data. If you are caching some of that in your DB, you may have to adjust or re-fetch it at some point(s) in the process.

  1. Set up a subscription through the app, as normal, in an environment that’s using your Stripe account’s test credentials. Just go through the checkout flow.
  2. In the Stripe dashboard, visit the Test Clocks page.
  3. Create a new test clock, giving it a memorable name. Usually the current time is the best start time, but you can tweak that if you like.
  4. Now you’re on the clock’s detail page: Create a new customer. You don’t need to supply all the info, but make sure to provide realistic info for fields your app cares about.
  5. Create a new subscription linked to that customer. Choose a realistic product, quantity, and trial period. Fill in any other details that are important to what you want to test. Copy the subscription ID from the Stripe dashboard for the next step.
  6. Update your database manually, replacing the original subscription ID from the first step with the test clock’s subscription ID from the previous step. Now your app will be looking at the test clock subscription as its source of truth.
  7. Back in Stripe, you can use the Advance Time button on the subscription page or the test clock page to advance time. This allows you to see that the correct invoice is issued when the trial period expires, for instance, or that the app reacts correctly when a payment succeeds or fails.

The subscription can otherwise be modified as normal, so you can do things like change the payment method and then advance the clock again to the next invoice. It’s helpful to have Stripe’s test documentation handy for this, especially the card number 4000000000000341, which attaches successfully to a subscription but gets declined when a charge is processed.

We're building an AI-powered Product Operations Cloud, leveraging AI in almost every aspect of the software delivery lifecycle. Want to test drive it with us? Join the ProdOps party at ProdOps.ai.