Git Product home page Git Product logo

stripehooks's Introduction

Build Status

stripehooks

A server to handle Stripe webhooks. Add your own custom event handlers.

Run

go get github.com/teamwork/stripehooks

go run main.go or go build && ./stripehooks

This accepts a port and a path part for configuring the endpoint e.g. ./stripehooks --help

Usage of ./stripehooks:
  -path="stripe": the endpoint to recieve webhooks on e.g. 'stripe' would be http://localhost:<port>/stripe
  -port=8080: port number to bind the server to e.g. '8080' would be http://localhost:8080/<path>

Example

In events/register.go add your event handlers to RegisterEventHandlers() function for any of the various events that Stripe send to your endpoint. You can see the list of events Stripe sends here. Here is an example of handling an invoice.payment_succeeded event.

// Example handle incoming hook for invoice.payment_succeeded event
registerEventHandler("invoice.payment_succeeded", func(event *stripe.Event) error {
    fmt.Printf("Event %s handled, type %s\n", event.ID, event.Type)
    return nil
})

eventHandlers is a map[string]eventHandler that holds all the events you register. There is also a validationHandler for checking the event Stripe sends down. This is typically either checking the event back with Stripe (extra step for security) or to use the event as-is and trust it. Examples of both are provided

func VerifyEventWithStripe(hook StripeWebhook) (*stripe.Event, error) {
    if !hook.LiveMode {
        return &stripe.Event{
            Data: &hook.Data,
            Live: hook.LiveMode,
            Type: hook.Type,
            ID:   hook.ID,
        }, nil
    }
    stripe.Key = "" // your private stripe api key goes here
    return event.Get(hook.ID)
}
validationHandler = func(hook StripeWebhook) (*stripe.Event, error) {
     return &stripe.Event{
         Data: &hook.Data,
         Live: hook.LiveMode,
         Type: hook.Type,
         ID:   hook.Id,
     }, nil
}

Dependencies

The only dependecies outside of the standard library are

  • "github.com/stripe/stripe-go"
  • "github.com/stripe/stripe-go/event"

I would recommend vendoring the stripe dependencies.

stripehooks's People

Contributors

peterkellydev avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.