stripehooks

command module
v0.0.0-...-0a1f4b4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2016 License: MIT Imports: 10 Imported by: 0

README

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.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL