Skip to content

Sinatra app to send custom email receipts with Stripe webhooks and Mailgun

Notifications You must be signed in to change notification settings

adamjstevenson/stripe-ruby-webhook-receipts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Sinatra app to send custom email receipts with Stripe webhooks and Mailgun

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published