Instrumental Commerce from Instrumental Components is a complete Rails Stripe integration, designed for SaaS applications.
It includes all of the essential pieces to power a modern SaaS application's billing needs, including:
When you purchase your license for Instrumental Components, you went through the checkout flow powered by Instrumental Commerce!
Before you can use Instrumental Commerce, you'll need to make sure you have:
Installation of the Commerce component has a few steps. At a high level, these steps are:
Let's get into it!
rails g instrumental:commerce
rails db:migrate
Open the file config/initializers/stripe.rb
and uncomment its contents. (Note: After uncommenting this, your app won't work until you complete the following steps to configure your Stripe keys and webhook secret)
In your Stripe account > Developers > API keys, you'll need to obtain your secret key and publishable key.
Save those to your Rails credentials in this format.
stripe:
publishable_key:
secret_key:
webhook_secret:
Since you'll typically be developing your app locally before deploying to production, we'll start by setting up your local environment to listen for Stripe webhooks coming from your Stripe account's "test mode".
First, make sure you have the Stripe CLI installed.
Run the following command follow the prompt to log into your Stripe account:
stripe login
Then run the following to start a local server to listen for Stripe webhooks coming from your Stripe account's "test mode":
stripe listen --forward-to localhost:3000/stripe/webhook
That will give you a webhook signing secret, which you'll need to save to the webhook_secret
key in your Rails credentials for your local development environment.
Now you're up and running to build and test your Stripe integration locally! You can skip over to setting up your products & prices. Or, keep reading to set up your production (and/or staging) environments' Stripe integrations.
Your production environment should be the one that uses your Stripe account in "live mode". If you have a staging environment, then that should use your Stripe account in "test mode".
Let's assume you're setting up your production (live mode) environment:
Get your Stripe API keys from Stripe (in live mode) > Developers > API keys. Save those to the Rails credentials for your application's production environment.
In Stripe (live mode), create a webhook with the following settings:
yourdomain.com/stripe/webhook
Get the webhook secret from that webhook in Stripe and save that to the webhook_secret
key in your Rails credentials for your production environment.
If you have a staging environment, then do the same as above, except create the webhook in "test mode" in Stripe and save your Stripe test mode API keys and webhook secret to the Rails credentials for your staging environment.
Ready to dive into setting up your products, prices, plans, coupons, and more? It's all documented in these sections:
I created Instrumental Components to make designing and building professional apps with Ruby on Rails easy, fast, and fun. I use it on all of my projects and I hope it helps you build something great.