When creating new VaxCalc features, we like to use Heroku’s review-apps for testing them in a production-like environment. Manually updating the Stripe test webhook url with every new review-app deployment was starting to become a pain, so we created a rake test to do the following:
- obtain a list of Heroku apps, figure out which one is the new review-app
- obtain the web_url of the review-app
- using the web_url, create the new url for our test Stripe webhook
- update Stripe with the new webhook url
You are probably already using the stripe gem. You’ll need to add Heroku’s platform-api gem to your Gemfile. Be sure to follow directions in the README to obtain an OAuth token.
To start the simplest way to get this working, make sure you have an app.json file for your review-app in order to run the bin/review-app script post deployment.
The review_app script is below. You can add more tasks to it as needed. For example: code to populate your database for testing.
Here’s the rake task that finds the review-app url and updates the Stripe webhook. The critical not-so-obvious pattern in this code is that if your Heroku app is named “vaxcalc”, the review app’s name will start with “vaxcalc-“. The dash after your app name is the key to finding your review app.