+
Skip to content

tolteck/stripe-hooks

 
 

Repository files navigation

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.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载