DEV Community

Cover image for Handle Stripe events in 2 minutes with Sailhouse
Ed Stephinson
Ed Stephinson

Posted on • Originally published at sailhouse.dev

Handle Stripe events in 2 minutes with Sailhouse

Building products is hard, before you even touch the business side and start taking payments.

There comes a point in every product's cycle when you need to start processing payments. Simple, right? Except what usually happens is you end up with a half-finished implementation that just about gets you by while you try to focus on shipping the product features people are paying for.

Here’s where Sailhouse makes things ridiculously easy. Let’s dive into using Sailhouse to seamlessly and effortlessly handle Stripe events in a way that scales as your product does.

The Stripe integration

Sailhouse is a platform built on pragmatic decisions, and with that useful features. As part of our beta offering, we're building out a fully-fledged Stripe integration to make it even easier for you to get your product and payments off the ground.

We see someone selecting the Stripe integration on the dashboard, choosing a topic for the events to be sent to, and then enabling it

Building a webhook to receive Stripe events itself is pretty straightforward, but the proper distribution — while maintaining verification — is a job for an events platform. Here’s where Sailhouse comes in.

Enabling the integration

Log in to your Sailhouse account and head over to your dashboard.

  • Create a topic to receive your events, for example, stripe-events
  • Enable the Stripe integration by navigating to Apps > your-app > Integrations, and select your new stripe-events topic
  • Copy the endpoint provided, navigate to Stripe, and create a new Webhook, selecting all available events
  • Take the secret from Stripe, and save it in the Sailhouse integration settings to activate the endpoint

There is a split browser screen, of the Sailhouse and Stripe dashboards. The user takes the dedicated webhook endpoint for the just-enabled Stripe integration, and configures the webhook on Stripe. The user selects all available events, then copies the webhook signature from Stripe into the integration configuration on Sailhouse, which finalises the setup.

Now, every single event on Stripe is sent to and handled on Sailhouse.

Wait a minute, that's noisy, surely?

Ah-ha! You fell into our pricing trap. (Just kidding, the beta is currently free to use under our fair use policy 😉.)

But if you’d like to reduce the amount of events received — or drill down into what’s most important, Sailhouse has got you covered with Subscription Filters.

Subscription filter for stripe events

Instead of building custom logic to handle Stripe events, verify webhooks, and distribute that information in your code, you can add a subscription filter on your Stripe events — as with any other event on Sailhouse.

For example, you can create an invoice-paid subscription, which filters on Stripe event type for invoice.paid. You can also set up Slack notifications for any invoice.payment_failed events thanks to the Sailhouse Slack integration!

Slack recieving a Stripe Event

Handling Stripe events

You can handle your Stripe events in Sailhouse just like any other event. Here are some examples.

You could configure a push subscription:

subscriptions:
  - slug: invoice-paid
    topic: stripe-events
    type: push
    endpoint: https://acme-inc.com/api/invoice-paid
    filter:
      path: type
      value: invoice.paid
Enter fullscreen mode Exit fullscreen mode

Or handle the event in your code.

const { events } = await client.getEvents("stripe-events", "customer-created");

for (const event of events) {
    // Do useful thing

    await event.ack();
}
Enter fullscreen mode Exit fullscreen mode

Let us know what you’re building!

This is just the start of a whole suite of awesome integrations, and we can't wait to see what you make with them.

Come show off what you're building in the official Sailhouse Discord, or tag us on Twitter.

Happy Sailing!

Top comments (0)