Skip to main content

A low-configuration service for sending notifications andreceipts based on Stripe webhooks.

Project description

stripe-hooks

This is a Python web application to receive webhooks from Stripe and send emails accordingly.

This is a fork of Jack Pearkes original work: stripe-hooks.

There are two types of emails:

Use cases:

  • Sending notifications about important Stripe events, such as failed charges or new customers, to administrators
  • Sending receipts to user after they have been charged

It supports all Stripe events.

The email content included by default is versatile English. Any of it can be modified to fit your business or use case. It's easy to deploy and you shouldn't need to touch Python to configure it.

Installation

    $ python3 setup.py install

Configuration

All of the configuration is done in JSON.

Create a .json file following configuration_template.json and drop it in the command line:

    $ stripe-hooks configuration.json 

More details below:

Emails type

All receipts and notifications are off by default with a blank configuration.json.

To activate a notification or receipt, simply create a new key, named by the event type (the list can be found here) and formatted like this:

{
  ...
  "email": {
    "charge.failed": {
      "active": true,
      "subject": "Oh nos! A Charge Has Failed!"
    }
  }
  ...
}

subject is optional. By default, the email subject will be the type, periods replacing spaces and titlecased, prefixed with your business name (if it exists) like so: charge.failed -> [Acme Inc.] Charge Failed.

Everything falls back to safe, generic defaults, like not showing a business name if it doesn't exist.

Emails type configuration could look something like this:

{
  ...
  "email": {
    "business": {
      "name": "Acme, Inc.",
      "signoff": "The Acme Team",
      "email": "Acme Support Team <support@example.com>"
    },
    "notifications": {
      "balance.available": {
        "active": true,
        "subject": "Dat chedda is available..."
      },
      "charge.succeeded": {
        "active": true
      },
      "charge.failed": {
        "active": true
      },
      "charge.refunded": {
        "active": true
      }
    },
    "receipts": {
      "invoice.created": {
        "active": true,
        "subject": "New Invoice"
      }
    }
  }
  ...
}

Emails Content

You need to provide a path to your emails templates:

{
  ...
  "email": {
    "templates_path": "stripe-hooks-emails",
    ...
  }
  ...
}

You can fork that repository and you will have a good start.

stripe

You need to configure a stripe webhook in stripe GUI stripe webhooks.

The service default port is 5000 and route url is /webhook.

When you have your endpoint secret just drop it in the configuration file:

{
  ...
  "stripe": {
    "endpoint_secret": "whsec_..."
  },
  ...
}

The endpoint secret will be use to authenticate stripe POST requests following stripe documentation.

Email Provider

SMTP is use as the default interface with your email provider.

Add this in your configuration file:

{
  ...
  "smtp": {
    "url": "localhost:25"
  },
  ...
}

Mailgun is a good provider. Stripe team use it in there own documentation.

Jack Pearkes original work uses Amazon SES.

Revert commit refactor(mail): use a smtp server instead of aws ses if you want to use Amazon SES.

Test

WIP

Contributing

Just drop a PR following git karma style.

When unit tests will be up-to-date, they will need to pass.

Project isn't compliant with Flake8 lint for now, so it's not mandatory, but it could be cool.

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stripe-hooks-0.1.tar.gz (7.4 kB view hashes)

Uploaded Source

Built Distribution

stripe_hooks-0.1-py3-none-any.whl (8.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page