Skip to content

Latest commit

 

History

History
44 lines (26 loc) · 2.52 KB

README.md

File metadata and controls

44 lines (26 loc) · 2.52 KB

Custom Stripe subscription email receipts with Mailgun

A basic example app built with Sinatra that uses Stripe's webhook functionality and the Mailgun Ruby gem to send custom email receipts to customers when the invoice.payment_succeeded event is received.

Modify the webhook.rb script and deploy this on Heroku or another service to send email receipts to your Stripe customers.

Example receipt

Features

  • Uses Mailgun's responsive email templates for invoices to send nicely formatted receipts.
  • HTML receipts include each invoice line item and totals. If you pass descriptions when creating invoice items, they'll each be listed here.
  • Sends both text and HTML emails for clients that don't support HTML.

Getting started

Create and configure a Mailgun account to send emails from your domain. You can also just test for free and use their sandbox domain until you're ready to configure your own.

Clone this repository:

git clone https://github.com/adamjstevenson/stripe-webhook-receipts.git

Run bundle install

Modify webhook.rb and views/html_email.erb to add your own domain and site name in place of SITE-NAME and YOUR-DOMAIN.COM

Obtain your API keys from your Stripe dashboard and Mailgun settings. Set these as environment variables when running this app.

Testing

You can test this locally and run on your machine by passing in the STRIPE_KEY and MAILGUN_KEY env variables:

STRIPE_KEY='sk_test_YOUR-STRIPE-KEY' MAILGUN_KEY='key-YOUR-MAILGUN-KEY' ruby webhook.rb

Once this is running locally, you can use a service like Ngrok to make the endpoint accessible at a URL like https://abcd1234.ngrok.io/webhook, then add the webhook endpoint in the Stripe dashboard.

You can find test cards on Stripe to create test customers and subscriptions.

Other notes

By default webhook.rb looks for an email address on the customer object. Be sure to either create customer objects with an email property or modify this to retrieve the email address from somewhere else.