Increasingly, I’m using Stripe as a payment processor for both professional work and hobby projects.
One key feature they offer is webhooks. When something happens outside of your typical API communication with them, they send an HTTP request to a url (or many) of your choice. This is useful for notifying administrators, sending receipts to customers and so on.
I’ve also taken to writing service-oriented web applications that rely more and more on APIs. I’ll end up just shoving the handling of Stripe webhooks into something that recieves HTTP on the public internet, typically the API that backs an Ember or Angular app.
Really, the billing webhooks shouldn’t be there, and should be self-contained. Given that, I have a lot to repeat on every project.
So, I made stripe-hooks. It’s a boiler plate system for sending webhooks, templating the emails and customizing it for your use case.
- Jane Customer purchases a copy of the B side Everybody’s Next One by Steppenwolf on your website
- Stripe charges her card and sends a
stripe-hookspicks up the hook and, based on the configuration, sends the administrator an email notifying them, and Jane a receipt
The basic email templates look like this, but they can be customized to fit your needs:
It’s written in Python but you really don’t need to touch the code – all you do is configure it using a JSON file and choose which Stripe events to act on, and what content to send. You can change the content by modifying the templates directly. The templates use Jinja and offer a lot of flexibility.
It’s designed to be deployed on Heroku, but with few dependencies, it can basically go anywhere Python can.
The GitHub repo has everything you need.