Skip to content

๐Ÿš€ Deploy your own Stripe webhook handler. Create adapters to call webhooks however you like.

License

Notifications You must be signed in to change notification settings

boone-studios/stripe-webhooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

17 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Stripe Webhook Events

Test Stripe Webhooks

This server receives webhook events from Stripe and then sends them to the respective handlers.

Installation

$ git clone [email protected]:boone-software/stripe-webhooks.git
$ npm install

Usage

To run the server persistently (using PM2), run the following command:

$ npm run start

To deploy the server without PM2, run:

$ npm run serve

The server will listen on port 3000.

Alternatively, you can use Docker to deploy the server:

$ docker-compose build
$ docker-compose up

Adapters

The server can be configured to use different adapters to handle different webhook events. These are the adapters that are currently supported:

Events

There are several events that can be handled by the server:

  • customer.created
  • invoice.created
  • invoice.finalized
  • invoice.paid
  • invoice.payment_failed
  • payout.created
  • payout.paid
  • payout.failed

We plan on adding more events in the future, but you can also add more adapters and event handlers by contributing to this project.

Adding an Adapter

Create a new adapter file in the src/adapters directory:

import { GenericMessage, FormattedMessage } from './../types/messages'
import Dispatcher from '../dispatcher'

class YourAdapter extends Dispatcher {
    /**
     * Constructor.
     */
    constructor() {
        super()

        this.endpoint = process.env.ADAPTER_WEBHOOK
        this.name = 'Adapter Name'

        this.headers = {
            'Content-Type': 'application/json',
        }
    }

    /**
     * Format generic message to target platform.
     *
     * @param {GenericMessage} data Generic message to format.
     * @return {FormattedMessage}
     */
    public format(data: GenericMessage): FormattedMessage {
        return {
            content: data.message,
        }
    }
}

export default YourAdapter

Webhook payloads from Stripe are converted into a generic message format, and then passed into the adapter's format method. Use the type-hinted GenericMessage type to create your own custom message format.