For Data Engineers

Slack Notification Integration with Stripe Webhooks


In a previous article, we walked through the process to integrate Stripe Webhooks with Amberflo to track real-time event updates for payments and to flag issues in real time. Following the implementation of the integration, our team wanted to create a simple way to be notified about possible issues with customer payments.

Currently, our organization is manually managing payments and communicates most frequently on Slack: a professional and organizational instant messaging platform. 

Setting up a Slack channel that posted notifications of Stripe payment statuses seemed like the most seamless integration. As we scale, our team knows that we may require notifications to be sent to other places; when making this integration, we kept that in mind. To get our backend to send a notification to Slack, we used AWS and Amazon SDK (Software Development Kit); SDK is a library we implemented in our backend to help us use Amazon features. 

Our strategy is based on creating a simple notification topic on AWS and letting our backend post messages there once a webhook is received from Stripe and successfully processed. The topic can have multiple subscribers, such as Slack channels, emails, discord… etc. Once the topic receives a message from our backend, it will take care of notifying all of its subscribers. This architecture will allow us to scale over time and add/remove subscribers on a need basis.

The infrastructure implementation on AWS is done via Terraform. Terraform provides a way to write infrastructure as code and will help us to manage it in an efficient, automated, and reusable manner.

Now, let’s dive into the implementation. The very first step is to set up a Slack channel.

How we set up the Webhooks - Slack Integration (Slack Interface)

  1. Create a Slack channel dedicated to notifications
  2. In the channel, “add a workflow” under the Integrations tab. When creating a workflow, select “Webhook” and create a variable called SubscribeURL. This variable will take care of authenticating and validating simple notification service (SNS) topics to confirm the subscription
  3. Standardize your notification message by creating a message that will display the variable once received. The variable will be sent from your SNS topic once the Slack endpoint URL is registered.

Setting up the Backend

Our platform has a backend that receives Webhooks from Stripe, so in order to receive notifications, we needed to create an SNS topic with the Slack endpoint as a subscriber. This creates a centralized place to assign subscribers, allowing us to assign different subscribers such as Discord channels or email subscribers as the needs of the organization change or as we scale. 

We used this Terraform code to generate the infrastructure to support sending notifications from our backend to Slack. Terraform allows us to define and deploy infrastructure on Amazon. The variable var.stripe_webhook_slack_endpoint is the URL obtained from the previous workflow.

Once you apply the Terraform changes, an infrastructure will be generated on AWS. To confirm the subscription, you need to authenticate your SNS topic on your subscription platform (which is Slack for our organization). 

Standardize your notification message by creating a message that will display the variable once received. The variable will be sent from your SNS topic once the Slack endpoint URL is registered.

Creating a Notification Message on Slack 

Slack Interface: To create a message for the workflow, you need to define a “message” variable and write a text in the workflow. 

Backend: Write code that sends the messages we want to the AWS SNS topic. This will tell the SNS topic to notify each subscriber.

This will push a message to each subscriber; in our case, our only subscriber is Slack. Every time we capture one of our defined Stripe Webhook events, our Slack channel dedicated to payment notifications will post a message. 

Using this process, we are able to set up an easy and scalable solution to receive notifications for detecting payment anomalies. If this is a problem you've experienced or if you're curious about FeatureBase’s capabilities streamlining ingestion for such issues, start your free trial now!