Skip to content

A standalone middleware for responding to Stripe webhooks, sending email notifications by default. This Node.js scaffold serves as an example implementation that can be customized or deployed as-is for a webhook MVP. Ideal for local development with Postman.

Notifications You must be signed in to change notification settings

vortex-m/webhook-stripe-server

Repository files navigation

webhook-stripe-server

This is a standalone scaffold or middleware for responding to Stripe webhooks.

By default it sends emails upon receiving a webhook. You can reprogram it to do whatever. It's mean to be an example of how to implement Stripe webhooks in Node, but you can deploy it as-is for a webhook MVP.

There is no user interface. Postman REST Client is a great tool for local webhook development.

Prerequisites

  • You have a Stripe account.
  • You're running Node.js >= 8.x.x
  • You are storing the customer's email address in the Stripe email field. Otherwise the emails won't work!

Usage - Standalone service

$  git clone https://github.com/vortex-m/webhook-stripe-server
$  cd webhook-stripe-server
$  npm install

(or, fork it, then clone your own)

Edit config.example.js to suit your needs and rename it to config.js.

$  npm start

to run the server.

Usage - Connect or Express middleware

$  npm install webhook-stripe-server

Then bind the middleware to a route. You must pass some configuration options.

var app = require('express')();
var webhooks = require('stripe-webhook-server');
var config = {

	// application settings
	port: process.env.PORT || 3000,
	appProtocol: "http://",
	appdomain: "localhost",
	helpUrl: "http://change.this.com/support",
	webhookEndpointPath: '/',

	// stripe
	stripe: {
		public_key: '',
		secret_key: ''
	},

	// email templates
	emailTemplateDir: 'templates/', // relative to root of the application
	emailTemplateExt: '.html',
	
	// email template fields
	fromAddress: '',
	fromAddressName: '',
	supportAddress: '',
	sincerely: '',
	
	// settings for Nodemailer email module
	nodemailer: {
		service: "",
		generateTextFromHTML: true,
		auth: {
			user: "",
			pass: ""
		},
		//validateRecipients: true,
		//debug: true,
		maxConnections: 1
	}
};

// setup the route
app.post('/my-webhook-endpoint', webhooks.webhookServer(config));

Customization

Email templates use Handlebars and are at templates/.

lib/webhooks.js is a list of the webhooks you support.

If you don't want to respond to a webhook, leave the function empty, or just delete the entry completely.

If you have custom application logic, you would edit lib/webhooks.js. This project is really more of a scaffold than a module, in that respect.

Bugs

Please branch, fix, and submit pull request.

About

A standalone middleware for responding to Stripe webhooks, sending email notifications by default. This Node.js scaffold serves as an example implementation that can be customized or deployed as-is for a webhook MVP. Ideal for local development with Postman.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published