So, you're integrating Stripe into your application! Huzzah, let's get that bread! All developers love Stripe, they make this so easy!
Except...well, they used to make it easy. But dealing with money on a global scale means regulation. Regulation means everything gets harder.
Why am I writing about this? Well, the short answer (and frankly, the only answer I'm qualified to give) is that our applications needs to accept webhooks from Stripe. That's how Stripe informs us about successful payments now-a-days.
So, the next hurdle is to make our application, which we're hacking on locally, accept webhooks from Stripe. We need our application to be available on the public internet!
How do we accept webhooks?
There's a few ways to make your local development environment available on the global internet. They have caveats.
- Remote development - a server is running and it has your development files
- Ngrok is available, but you get a random subdomain unless you pay them
- Expose is similar to Ngrok, including having the random subdomain issue
A random subdomain means you'll have to adjust the Stripe webhook configuration each time you spin up a new tunnel to your local application
These options are actually fine in reality, but the trade-offs are just yet-more-friction to getting work done.
Stripe, luckily, has given us a better alternative.
Stripe CLI
When it comes to Stripe, we can actually just not open a public tunnel to our localhost!
The way to accomplish this is to use the Stripe CLI.
For MacOS, you can install it via brew
:
brew install stripe/stripe-cli/stripe
See install instructions for other OSes.
Once that's installed, you can log into Stripe, and setup webhook forwarding to an endpoint of your choice.
stripe login
stripe listen --forward-to http://localhost:8000/stripe/webhook
When you authenticate and setup forwarding, the stripe
command creates some configuration files in ~/.config/stripe/config.yml
.
Multiple Apps
If you develop against multiple applications, you can setup "profiles". Each profile has a different configuration (notably, a different webhook secret key). These are saved to that same configuration file.
Here's what it looks like to configure per-application configuration!
# Setup a profile for "my-app"
stripe -p my-app login
stripe -p my-app listen --forward-to http://localhost:8000/stripe/webhook
That's it, it's that simple!